title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Why am I getting an error using 'set' in Python? | 1,994,163 | <pre><code>s = set('ABC')
s.add('z')
s.update('BCD')
s.remove('DEF') # error here
s -= set('DEFG')
</code></pre>
| 1 | 2010-01-03T06:23:23Z | 1,994,184 | <p>As others pointed out, <code>'DEF'</code>, the set member you're trying to remove, is <strong>not</strong> a member of the set, and <code>remove</code>, per <a href="http://docs.python.org/library/stdtypes.html?highlight=set.remove#set.remove">the docs</a>, is specified as "Raises KeyError if elem is not contained i... | 9 | 2010-01-03T06:35:32Z | [
"python",
"set"
] |
Why am I getting an error using 'set' in Python? | 1,994,163 | <pre><code>s = set('ABC')
s.add('z')
s.update('BCD')
s.remove('DEF') # error here
s -= set('DEFG')
</code></pre>
| 1 | 2010-01-03T06:23:23Z | 1,995,089 | <p>Do you expect <code>'DEF'</code> to be treated as an <strong>element</strong> or a <strong>set</strong>?</p>
<p>In the latter case use <code>s.difference_update('DEF')</code>.</p>
| 0 | 2010-01-03T14:16:47Z | [
"python",
"set"
] |
is my google app engine deployed source code secure? | 1,994,182 | <p>I'm thinking about <a href="http://stackoverflow.com/questions/1994112/i-must-store-third-party-credentials-in-my-database-best-way">good ways to store third party credentials</a>, which basically means there needs to be a secret somewhere, either in code or data. I'm deploying on google app engine.</p>
<p>If the '... | 2 | 2010-01-03T06:34:59Z | 1,994,188 | <p>Yes: your source code <strong>is</strong> secure (as secure as Google can make it), and there's no way for unauthorized third parties to peek.</p>
| 3 | 2010-01-03T06:36:57Z | [
"python",
"security",
"google-app-engine",
"passwords",
"credentials"
] |
is my google app engine deployed source code secure? | 1,994,182 | <p>I'm thinking about <a href="http://stackoverflow.com/questions/1994112/i-must-store-third-party-credentials-in-my-database-best-way">good ways to store third party credentials</a>, which basically means there needs to be a secret somewhere, either in code or data. I'm deploying on google app engine.</p>
<p>If the '... | 2 | 2010-01-03T06:34:59Z | 1,996,412 | <p>Also remember to handle exceptions in your code with an error page, or else an exception thrown might uncover your source code to an unsigned user.</p>
| 2 | 2010-01-03T21:33:50Z | [
"python",
"security",
"google-app-engine",
"passwords",
"credentials"
] |
Why can't I find '__path__' in django.db.__init__.py? | 1,994,294 | <pre><code>backend_dir = os.path.join(__path__[0], 'backends')
</code></pre>
<p>Why can't I find it?</p>
| 0 | 2010-01-03T08:13:19Z | 1,994,391 | <p>Set <code>settings.DATABASE_ENGINE</code> in <code>settings.py</code>.</p>
<p>The execution reaches the line you mentioned only if the back-end is not standard.</p>
| 0 | 2010-01-03T09:07:31Z | [
"python",
"django"
] |
How can I open '_mysql.pyd' in 'D:\Python25\Lib\site-packages'? | 1,994,403 | <p>My IDE is 'ulipad', and when I open the file, it can't be shown. How can I get it?</p>
| 0 | 2010-01-03T09:12:43Z | 1,994,987 | <p>.pyd files are DLLs. You can't usefully open them in text editors.</p>
| 1 | 2010-01-03T13:40:41Z | [
"python",
"mysql"
] |
Copy file or directory in Python | 1,994,488 | <p>Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven't found any function that handles both. Sure, it's trivial to check whether you want to copy a file or a directory, but it seems like a strange omission.</p>
<p>Is there reall... | 71 | 2010-01-03T10:06:42Z | 1,994,510 | <p>Unix <code>cp</code> doesn't 'support both directories and files':</p>
<pre><code>betelgeuse:tmp james$ cp source/ dest/
cp: source/ is a directory (not copied).
</code></pre>
<p>To make cp copy a directory, you have to manually tell cp that it's a directory, by using the '-r' flag.</p>
<p>There is some disconnec... | 6 | 2010-01-03T10:17:22Z | [
"python"
] |
Copy file or directory in Python | 1,994,488 | <p>Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven't found any function that handles both. Sure, it's trivial to check whether you want to copy a file or a directory, but it seems like a strange omission.</p>
<p>Is there reall... | 71 | 2010-01-03T10:06:42Z | 1,994,840 | <p>I suggest you first call <code>shutil.copytree</code>, and if an exception is thrown, then retry with <code>shutil.copy</code>.</p>
<pre><code>import shutil, errno
def copyanything(src, dst):
try:
shutil.copytree(src, dst)
except OSError as exc: # python >2.5
if exc.errno == errno.ENOTDI... | 88 | 2010-01-03T12:35:25Z | [
"python"
] |
Copy file or directory in Python | 1,994,488 | <p>Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven't found any function that handles both. Sure, it's trivial to check whether you want to copy a file or a directory, but it seems like a strange omission.</p>
<p>Is there reall... | 71 | 2010-01-03T10:06:42Z | 38,698,841 | <p>The python shutil.copytree method its a mess. I've done one that works correctly:</p>
<pre><code>def copydirectorykut(src, dst):
os.chdir(dst)
list=os.listdir(src)
nom= src+'.txt'
fitx= open(nom, 'w')
for item in list:
fitx.write("%s\n" % item)
fitx.close()
f = open(nom,'r')
... | 0 | 2016-08-01T12:25:08Z | [
"python"
] |
how to start a thread when django runserver? | 1,994,507 | <p>I want to start a thread when django project runserver successfully.
where can I put the create-thread-and-start code? Is there any hook for the django runserver? </p>
| 0 | 2010-01-03T10:14:58Z | 1,994,563 | <p>Why would you want to do that? runserver is for development only, it should never be used in production. And if you're running via Apache, it should manage threads/processes for you anyway.</p>
| 6 | 2010-01-03T10:35:09Z | [
"python",
"django",
"multithreading"
] |
how to start a thread when django runserver? | 1,994,507 | <p>I want to start a thread when django project runserver successfully.
where can I put the create-thread-and-start code? Is there any hook for the django runserver? </p>
| 0 | 2010-01-03T10:14:58Z | 1,997,921 | <p>Agree with the above answer, you probably don't want to do this. Runserver should be used for development only. Once you deploy, you'll want to move to Apache/WSGI. On my dev machine (where I do use runserver), I usually throw it in a screen session, so it doesn't get in the way, but I can pull it back up if I need ... | 0 | 2010-01-04T06:59:09Z | [
"python",
"django",
"multithreading"
] |
Fast way to read filename from directory? | 1,994,549 | <p>Given a local directory structure of <code>/foo/bar</code>, and assuming that a given path contains exactly one file (filename and content does not matter), what is a reasonably fast way to get the filename of that single file (NOT the file content)?</p>
| 2 | 2010-01-03T10:29:55Z | 1,994,557 | <p>1st element of <a href="http://docs.python.org/library/os.html#os.listdir"><code>os.listdir()</code></a></p>
<pre><code>import os
os.listdir('/foo/bar')[0]
</code></pre>
| 10 | 2010-01-03T10:31:59Z | [
"python",
"path"
] |
Fast way to read filename from directory? | 1,994,549 | <p>Given a local directory structure of <code>/foo/bar</code>, and assuming that a given path contains exactly one file (filename and content does not matter), what is a reasonably fast way to get the filename of that single file (NOT the file content)?</p>
| 2 | 2010-01-03T10:29:55Z | 1,994,558 | <p>Well I know this code works...</p>
<pre><code>for file in os.listdir('.'):
#do something
</code></pre>
| 2 | 2010-01-03T10:32:08Z | [
"python",
"path"
] |
Fast way to read filename from directory? | 1,994,549 | <p>Given a local directory structure of <code>/foo/bar</code>, and assuming that a given path contains exactly one file (filename and content does not matter), what is a reasonably fast way to get the filename of that single file (NOT the file content)?</p>
| 2 | 2010-01-03T10:29:55Z | 1,995,148 | <p>you can also use glob</p>
<pre><code>import glob
print glob.glob("/path/*")[0]
</code></pre>
| 0 | 2010-01-03T14:38:24Z | [
"python",
"path"
] |
How to revert to content of a Dijit text box when browser back-button is clicked? | 1,994,581 | <p>I am using a Dojo Textarea Dijit to input and submit text (to be processed).</p>
<p>I found that after submiting, if a browser back-button is pressed (IE8, Firefox) unlike regular HTML Textarea, I return to the input screen, but the Textarea is EMPTY.</p>
<p>What I would like to happen is that after back-button is... | 4 | 2010-01-03T10:42:53Z | 2,056,839 | <p>You may consider using dojo.back module: <a href="http://dojocampus.org/content/2009/05/17/using-dojo-back-button-and-bookmarks" rel="nofollow">http://dojocampus.org/content/2009/05/17/using-dojo-back-button-and-bookmarks</a> to store the page's state and handle back / forward events. <br/>However not sure if it's w... | 2 | 2010-01-13T13:19:52Z | [
"python",
"dojo",
"textarea",
"back-button"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 1,994,714 | <p>I haven't played with it but I know that Scala works.</p>
<p><a href="http://www.scala-lang.org/node/160" rel="nofollow">http://www.scala-lang.org/node/160</a></p>
| 3 | 2010-01-03T11:40:53Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 1,994,892 | <p>Scala works very well.</p>
<p>I'm programming my Android application projects in Scala (<a href="http://bone.twbbs.org.tw/maidroid/MaidroidReminder">Website written in Chinese with some screenshot</a>, <a href="http://github.com/brianhsu/Maidroid/tree/master/MaidroidReminder/">source code @ GitHub</a>), and it is p... | 24 | 2010-01-03T12:57:48Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 1,994,959 | <p>The dynamically typed languages wont be possible until Dalvik supports JIT (Just In Time) compiling. I believe there is JIT support in one of the experimental Eclair branches, but it is not yet officially available/supported in Android.</p>
| 0 | 2010-01-03T13:32:47Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 3,323,834 | <ul>
<li><p>At launch, <code>Java</code> was the only officially supported programming language for building distributable third-party Android software.</p></li>
<li><p>Android Native Development Kit (Android NDK) which will allow developers to build Android software components with <code>C</code> and <code>C++</code>.... | 59 | 2010-07-24T04:37:22Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 8,382,552 | <p><a href="http://www.mercury.csse.unimelb.edu.au/index.html" rel="nofollow">Mercury</a> also works on Android, using its Java backend. I've written a <a href="https://github.com/ayrnieu/InquisitorM/" rel="nofollow">simple app</a> that should help someone get started (there are still few other examples), and <a href=... | 1 | 2011-12-05T08:16:24Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 13,440,392 | <p>There is a <a href="http://en.wikipedia.org/wiki/Free_Pascal" rel="nofollow">Free Pascal</a> compiler available now which creates executables for the Android platform.</p>
<ul>
<li>Short summary: <a href="http://mikejustin.wordpress.com/2012/11/10/developing-for-android-with-pascal-and-eclipse/" rel="nofollow">Deve... | 0 | 2012-11-18T13:09:14Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 17,218,992 | <p><a href="http://www.gnu.org/software/kawa/">Kawa</a> is a lovely but little known variant of Scheme that has existed quietly for many years and runs on both the JVM and Dalvik, <em>natively</em>. Therefore, its output includes no extra VM and only includes explicitly imported libraries. To the end-programmer, this... | 5 | 2013-06-20T16:33:47Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Which programming languages can I use on Android Dalvik? | 1,994,703 | <p>In theory, Dalvik executes any virtual machine byte code, created for example with the compilers of </p>
<ul>
<li>AspectJ</li>
<li>ColdFusion</li>
<li>Clojure</li>
<li>Groovy</li>
<li>JavaFX Script</li>
<li>JRuby</li>
<li>Jython</li>
<li>Rhino</li>
<li>Scala</li>
</ul>
<p>Are there already working versions of byte... | 54 | 2010-01-03T11:35:32Z | 30,734,985 | <p>Another JVM language that works on Android is <a href="http://kotlinlang.org/" rel="nofollow">Kotlin</a> with <a href="https://github.com/JetBrains/anko" rel="nofollow">Anko</a>, both from <a href="https://www.jetbrains.com/" rel="nofollow">Jetbrains</a>. </p>
| 2 | 2015-06-09T14:28:18Z | [
"java",
"python",
"android",
"scala",
"dalvik"
] |
Is Tkinter included with Python 2.5? | 1,994,760 | <p>I have downloaded python 2.5. I would like to know if Tkinter is included with python or is it a separate download?</p>
| 0 | 2010-01-03T11:58:07Z | 1,994,769 | <p>Yes, it is included.</p>
<p><a href="http://wiki.python.org/moin/TkInter" rel="nofollow">http://wiki.python.org/moin/TkInter</a></p>
| 4 | 2010-01-03T12:01:42Z | [
"python",
"tkinter"
] |
Is Tkinter included with Python 2.5? | 1,994,760 | <p>I have downloaded python 2.5. I would like to know if Tkinter is included with python or is it a separate download?</p>
| 0 | 2010-01-03T11:58:07Z | 27,392,691 | <p>If you are using linux just open your terminal and type python and in the <code>python</code> interpreter type <code>from Tkinter import*</code> if it doesn't show any error messages you are good to go. You can try this to check every package of python like <code>Pygame</code> just replace Tkinter by Pygame</p>
| 0 | 2014-12-10T03:06:40Z | [
"python",
"tkinter"
] |
Problem with for loop iterations over data from a queue | 1,994,904 | <p>I'm having a problem reading and processing data from my server. I've spent hours debugging this and it seems as though the problem has nothing to do with the server but is really just an issue with one of my for loops. Its difficult to explain this without actually seeing the data from the server, but I'll do my be... | 0 | 2010-01-03T13:03:29Z | 1,994,985 | <p>"As TCP is a stream, I usually don't receive each string separately "</p>
<p>You can't reliably and predictably receive them separately. TCP makes things into a single stream of data. That's what TCP/IP <em>must</em> do. It must buffer to create a "stream" of data, not matter what you try to do at each end to s... | 3 | 2010-01-03T13:38:45Z | [
"python",
"loops",
"for-loop"
] |
Problem with for loop iterations over data from a queue | 1,994,904 | <p>I'm having a problem reading and processing data from my server. I've spent hours debugging this and it seems as though the problem has nothing to do with the server but is really just an issue with one of my for loops. Its difficult to explain this without actually seeing the data from the server, but I'll do my be... | 0 | 2010-01-03T13:03:29Z | 1,994,986 | <p>I just tried your code with the following result:</p>
<pre><code>def xmlParser(newData):
for string in newData:
print string
if 'a' in string:
print 'string1 being processed'
elif 'b' in string:
print 'string2 being processed'
# ...
elif 'e... | 1 | 2010-01-03T13:40:32Z | [
"python",
"loops",
"for-loop"
] |
Problem with for loop iterations over data from a queue | 1,994,904 | <p>I'm having a problem reading and processing data from my server. I've spent hours debugging this and it seems as though the problem has nothing to do with the server but is really just an issue with one of my for loops. Its difficult to explain this without actually seeing the data from the server, but I'll do my be... | 0 | 2010-01-03T13:03:29Z | 1,995,049 | <p>Well, this <em>is</em> a stumper. Especially since you have not posted the real code, but your own concept of how the code should be working. Since there is nothing wrong with this concept, there is nothing wrong with your example.</p>
<p>Still, I copied out your code, and then tried to perturb it to get your res... | 1 | 2010-01-03T14:01:08Z | [
"python",
"loops",
"for-loop"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 1,995,015 | <pre><code>for i = 1 to 10000
get "http://en.wikipedia.org/wiki/Special:Random"
</code></pre>
| 23 | 2010-01-03T13:49:43Z | [
"python",
"algorithm",
"wikipedia"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 1,995,021 | <p>You may be able to do an end run around most of the requirement:</p>
<p><a href="http://cs.fit.edu/~mmahoney/compression/enwik8.zip" rel="nofollow">http://cs.fit.edu/~mmahoney/compression/enwik8.zip</a></p>
<p>is a ZIP file containing 100 MB of Wikipedia, already pulled out for you. The linked file is ~ 16 MB in s... | 0 | 2010-01-03T13:51:44Z | [
"python",
"algorithm",
"wikipedia"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 1,995,023 | <p>Look at the <a href="http://wiki.dbpedia.org/Downloads" rel="nofollow">DBpedia project</a>.</p>
<p>There are small downloadable chunks with at least some article URLs. Once you parsed 10000, you can batch-download them carefully ...</p>
| 0 | 2010-01-03T13:51:58Z | [
"python",
"algorithm",
"wikipedia"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 1,995,026 | <p>Wikipedia has an <a href="http://en.wikipedia.org/w/api.php">API</a>. With this API you can get any random article in a given namespace:</p>
<pre><code>http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=5
</code></pre>
<p>and for each article you call also get the wiki tex... | 20 | 2010-01-03T13:52:34Z | [
"python",
"algorithm",
"wikipedia"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 1,995,028 | <p>I'd go the opposite way-- start with the XML dump, and then throw away what you don't want.</p>
<p>In your case, if you are looking to do natural language processing, I would assume that you are interested in pages that have complete sentences, and not lists of links. If you spider the links in the manner you desc... | 1 | 2010-01-03T13:53:03Z | [
"python",
"algorithm",
"wikipedia"
] |
Getting a large number (but not all) Wikipedia pages | 1,995,008 | <p>For a <a href="http://en.wikipedia.org/wiki/Natural_language_processing" rel="nofollow">NLP</a> project of mine, I want to download a large number of pages (say, 10000) at random from Wikipedia. Without downloading the entire XML dump, this is what I can think of:</p>
<ol>
<li>Open a Wikipedia page</li>
<li>Parse t... | 4 | 2010-01-03T13:46:59Z | 31,642,898 | <p>I know it has been long, but for those who are still looking for an efficient way to crawl and download large number of wikipedia pages (or entire wikipedia) without violating the robot.txt file, 'Webb' library is useful. Here is the link:</p>
<p><a href="https://github.com/hardikvasa/webb" rel="nofollow">Webb Libr... | 0 | 2015-07-26T23:12:03Z | [
"python",
"algorithm",
"wikipedia"
] |
Creating an FTP client with Python | 1,995,046 | <p>I've always thought about creating my own ftp client ever since I've started using the Internet. And now that I'm studying Python, I'm thinking about creating one as an exercises/personal project.</p>
<p>I'm wondering, </p>
<ul>
<li>What libraries do you guys suggest? Will <code>ftplib</code> suffice? Or would you... | 3 | 2010-01-03T13:59:45Z | 1,995,050 | <p>Python's standard library is just a great place to start: <a href="http://docs.python.org/library/ftplib.html" rel="nofollow">http://docs.python.org/library/ftplib.html</a></p>
<p><em>Note: And if for some reason you want to write your own client, you can simple read the source, which is a good training exercise in... | 3 | 2010-01-03T14:02:37Z | [
"python",
"ftp"
] |
Creating an FTP client with Python | 1,995,046 | <p>I've always thought about creating my own ftp client ever since I've started using the Internet. And now that I'm studying Python, I'm thinking about creating one as an exercises/personal project.</p>
<p>I'm wondering, </p>
<ul>
<li>What libraries do you guys suggest? Will <code>ftplib</code> suffice? Or would you... | 3 | 2010-01-03T13:59:45Z | 1,995,065 | <p>It sounds like you want to make a program that has a GUI. May I recommend using <strong>PyQt</strong> for that part of your application? <strong>ftplib</strong> should be fine for your FTP support, and you can find documentation <a href="http://docs.python.org/3.1/library/ftplib.html">right here</a>.</p>
<p>Alterna... | 7 | 2010-01-03T14:05:59Z | [
"python",
"ftp"
] |
Python execution | 1,995,102 | <p>Is it possible for a python script to execute at a low run level? </p>
<p>Edit:
To clarify, is it possible for a python script to run in the background, kind of like a daemon.</p>
| 1 | 2010-01-03T14:21:27Z | 1,995,168 | <p>I put this file <code>nice.py</code> in my site-packages directory (on Windows):</p>
<pre><code>import win32api,win32process,win32con
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CL... | 5 | 2010-01-03T14:47:27Z | [
"python",
"runlevel"
] |
Python execution | 1,995,102 | <p>Is it possible for a python script to execute at a low run level? </p>
<p>Edit:
To clarify, is it possible for a python script to run in the background, kind of like a daemon.</p>
| 1 | 2010-01-03T14:21:27Z | 1,996,354 | <p>Yes. The scripts that control daemons are (normally) plain old bash scripts and can run whatever a bash script can run. The only difference is that in a low runlevel, lots of other system services will not be running, so if the program tries to do something that depends on another daemon, that may fail.</p>
| 0 | 2010-01-03T21:18:25Z | [
"python",
"runlevel"
] |
Deleting all files in a directory with Python | 1,995,373 | <p>I want to delete all files with the extension <code>.bak</code> in a directory. How can I do that in Python?</p>
| 102 | 2010-01-03T15:58:20Z | 1,995,389 | <p>First <a href="http://docs.python.org/library/glob.html" rel="nofollow">glob</a> them, then <a href="http://docs.python.org/library/os.html#os.unlink" rel="nofollow">unlink</a>.</p>
| 4 | 2010-01-03T16:01:34Z | [
"python",
"file-io"
] |
Deleting all files in a directory with Python | 1,995,373 | <p>I want to delete all files with the extension <code>.bak</code> in a directory. How can I do that in Python?</p>
| 102 | 2010-01-03T15:58:20Z | 1,995,397 | <p>Via <a href="https://docs.python.org/2/library/os.html#os.listdir"><code>os.listdir</code></a> and <a href="https://docs.python.org/2/library/os.html#os.remove"><code>os.remove</code></a>:</p>
<pre><code>import os
filelist = [ f for f in os.listdir(".") if f.endswith(".bak") ]
for f in filelist:
os.remove(f)
<... | 179 | 2010-01-03T16:02:54Z | [
"python",
"file-io"
] |
Deleting all files in a directory with Python | 1,995,373 | <p>I want to delete all files with the extension <code>.bak</code> in a directory. How can I do that in Python?</p>
| 102 | 2010-01-03T15:58:20Z | 1,995,410 | <p>Use <code>os.chdir</code> to change directory .
Use <code>glob.glob</code> to generate a list of file names which end it '.bak'. The elements of the list are just strings.</p>
<p>Then you could use <code>os.unlink</code> to remove the files. (PS. <code>os.unlink</code> and <code>os.remove</code> are synonyms for th... | 21 | 2010-01-03T16:06:33Z | [
"python",
"file-io"
] |
Deleting all files in a directory with Python | 1,995,373 | <p>I want to delete all files with the extension <code>.bak</code> in a directory. How can I do that in Python?</p>
| 102 | 2010-01-03T15:58:20Z | 1,997,087 | <p>you can create a function. Add maxdepth as you like for traversing subdirectories.</p>
<pre><code>def findNremove(path,pattern,maxdepth=1):
cpath=path.count(os.sep)
for r,d,f in os.walk(path):
if r.count(os.sep) - cpath <maxdepth:
for files in f:
if files.endswith(patt... | 5 | 2010-01-04T01:30:12Z | [
"python",
"file-io"
] |
Deleting all files in a directory with Python | 1,995,373 | <p>I want to delete all files with the extension <code>.bak</code> in a directory. How can I do that in Python?</p>
| 102 | 2010-01-03T15:58:20Z | 37,994,379 | <p>In Python 3.5, <a href="https://docs.python.org/3/library/os.html#os.scandir" rel="nofollow"><code>os.scandir</code></a> is better if you need to check for file attributes or type - see <a href="https://docs.python.org/3/library/os.html#os.DirEntry" rel="nofollow"><code>os.DirEntry</code></a> for properties of the o... | 1 | 2016-06-23T14:21:44Z | [
"python",
"file-io"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 1,995,425 | <p>Using <code>yield</code> is nice if the expression is more complicated than just nested loops. Among other things you can return a special first or special last value. Consider:</p>
<pre><code>def Generator(x):
for i in xrange(x):
yield(i)
yield(None)
</code></pre>
| 7 | 2010-01-03T16:13:13Z | [
"python",
"yield",
"generator"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 1,995,427 | <p>In this example, not really. But <code>yield</code> can be used for more complex constructs - <a href="http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/">for example</a> it can accept values from the caller as well and modify the flow as a result. Read <a href="http://www.pytho... | 32 | 2010-01-03T16:13:33Z | [
"python",
"yield",
"generator"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 1,995,445 | <p>When thinking about iterators, the <code>itertools</code> module:</p>
<blockquote>
<p>... standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an âiterator algebraâ making it possible to construct specialized tools succinctly and efficien... | 4 | 2010-01-03T16:21:44Z | [
"python",
"yield",
"generator"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 1,995,465 | <p>There is no difference for the kind of simple loops that you can fit into a generator expression. However yield can be used to create generators that do much more complex processing. Here is a simple example for generating the fibonacci sequence:</p>
<pre><code>>>> def fibgen():
... a = b = 1
... w... | 15 | 2010-01-03T16:30:39Z | [
"python",
"yield",
"generator"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 1,995,585 | <p>There are only slight differences in the two. You can use the <code>dis</code> module to examine this sort of thing for yourself. </p>
<p><strong>Edit:</strong> My first version decompiled the generator expression created at module-scope in the interactive prompt. That's slightly different from the OP's version ... | 60 | 2010-01-03T17:17:12Z | [
"python",
"yield",
"generator"
] |
Python: generator expression vs. yield | 1,995,418 | <p>In Python, is there any difference between creating a generator object through a <strong>generator expression</strong> versus using the <strong>yield</strong> statement?</p>
<p>Using <em>yield</em>:</p>
<pre><code>def Generator(x, y):
for i in xrange(x):
for j in xrange(y):
yield(i, j)
</co... | 68 | 2010-01-03T16:09:26Z | 2,047,130 | <p>In usage, note a distinction between a generator object vs a generator function.</p>
<p>A generator object is use-once-only, in contrast to a generator function, which can be reused each time you call it again, because it returns a fresh generator object.</p>
<p>Generator expressions are in practice usually used "... | 7 | 2010-01-12T06:26:29Z | [
"python",
"yield",
"generator"
] |
buildbot: connect to IRC server using SSL | 1,995,474 | <p>How can I use buildbot's IRC bot to connect to an IRC server that wants SSL connections?</p>
| 2 | 2010-01-03T16:36:59Z | 1,998,737 | <p>You could fix the tunnel on the buildbots localhost with stunnel, for e.g.:</p>
<pre><code> stunnel -c -D5 -r dest.irc.server:port -d 127.0.0.1:6667
</code></pre>
<p>And then let buildbot connect to 127.0.0.1:6667</p>
| 1 | 2010-01-04T10:39:12Z | [
"python",
"ssl",
"twisted",
"irc",
"buildbot"
] |
buildbot: connect to IRC server using SSL | 1,995,474 | <p>How can I use buildbot's IRC bot to connect to an IRC server that wants SSL connections?</p>
| 2 | 2010-01-03T16:36:59Z | 2,023,706 | <p>I just submitted a small patch to BuildBot which will allow the IRC bot to connect to SSL-enabled servers. Should be included in the next release (0.7.12?).</p>
<p>If you want to apply it to your setup, it's a <a href="http://github.com/djmitche/buildbot/commit/4412014653749be47026054cbbf4e702abb0ec08" rel="nofoll... | 3 | 2010-01-07T21:11:23Z | [
"python",
"ssl",
"twisted",
"irc",
"buildbot"
] |
Django/Python: How can I make the following number increment (not in database) | 1,995,561 | <p>I would like to create a number like:</p>
<pre><code>000000000001
</code></pre>
<p>to save to the database. I obviously cannot increment in this fashion (I don't think) in a database, so I'm looking for the most efficient method for pulling the previous number from the database and incrementing it by 1 to create t... | 0 | 2010-01-03T17:07:04Z | 1,995,570 | <p>All the leading zeroes are just formatting.</p>
<pre><code>>>> "%012d" % ( 1, )
'000000000001'
>>> "%012d" % ( 2, )
'000000000002'
</code></pre>
<p>Use an ordinary integer and format it to have lots of leading zeroes.</p>
| 5 | 2010-01-03T17:09:18Z | [
"python",
"django",
"auto-increment"
] |
Django/Python: How can I make the following number increment (not in database) | 1,995,561 | <p>I would like to create a number like:</p>
<pre><code>000000000001
</code></pre>
<p>to save to the database. I obviously cannot increment in this fashion (I don't think) in a database, so I'm looking for the most efficient method for pulling the previous number from the database and incrementing it by 1 to create t... | 0 | 2010-01-03T17:07:04Z | 1,995,660 | <p>There's actually a super tricky way to do this using the itertools library and a generator function.</p>
<pre><code>from itertools import product, imap
def stringdigit(num_digits=10, start = None):
"""A generator function which returns string versions of a large iterated number with
leading zeros. start al... | 1 | 2010-01-03T17:45:52Z | [
"python",
"django",
"auto-increment"
] |
How can I turn 000000000001 into 1? | 1,995,602 | <p>I need to turn a formatted integer into a regular integer:</p>
<ul>
<li>000000000001 needs to be turned into 1</li>
<li>000000000053 needs to be turned into 53</li>
<li>000000965948 needs to be turned into 965948</li>
</ul>
<p>And so on.</p>
<p>It seems that a simple <code>int(000000000015)</code> results in the ... | 4 | 2010-01-03T17:26:13Z | 1,995,609 | <p>Numbers starting with <code>0</code> are considered <a href="http://en.wikipedia.org/wiki/Octal" rel="nofollow">octal</a>.</p>
<pre><code>>>> 07
7
>>> 08
File "<stdin>", line 1
08
^
SyntaxError: invalid token
</code></pre>
<p>You can wrap your zero-padded number into a string, the... | 11 | 2010-01-03T17:29:26Z | [
"python",
"parsing",
"integer"
] |
How can I turn 000000000001 into 1? | 1,995,602 | <p>I need to turn a formatted integer into a regular integer:</p>
<ul>
<li>000000000001 needs to be turned into 1</li>
<li>000000000053 needs to be turned into 53</li>
<li>000000965948 needs to be turned into 965948</li>
</ul>
<p>And so on.</p>
<p>It seems that a simple <code>int(000000000015)</code> results in the ... | 4 | 2010-01-03T17:26:13Z | 1,995,610 | <pre><code>if x = "0000000000000001":
x = 1
</code></pre>
| -8 | 2010-01-03T17:29:34Z | [
"python",
"parsing",
"integer"
] |
How can I turn 000000000001 into 1? | 1,995,602 | <p>I need to turn a formatted integer into a regular integer:</p>
<ul>
<li>000000000001 needs to be turned into 1</li>
<li>000000000053 needs to be turned into 53</li>
<li>000000965948 needs to be turned into 965948</li>
</ul>
<p>And so on.</p>
<p>It seems that a simple <code>int(000000000015)</code> results in the ... | 4 | 2010-01-03T17:26:13Z | 1,995,616 | <p>The leading zeroes are considered octal. I am assuming that you are converting the string "000000013", not literal 000000013, so you should be able to convert these to base 10 integer by <code>int("000000013",10)</code></p>
<p>If the "harm has already been done", and they are literals, that have already been conver... | 8 | 2010-01-03T17:30:54Z | [
"python",
"parsing",
"integer"
] |
How can I turn 000000000001 into 1? | 1,995,602 | <p>I need to turn a formatted integer into a regular integer:</p>
<ul>
<li>000000000001 needs to be turned into 1</li>
<li>000000000053 needs to be turned into 53</li>
<li>000000965948 needs to be turned into 965948</li>
</ul>
<p>And so on.</p>
<p>It seems that a simple <code>int(000000000015)</code> results in the ... | 4 | 2010-01-03T17:26:13Z | 1,995,618 | <p>Try this:</p>
<pre><code>>>> int('00000000053', 10)
53
</code></pre>
| 3 | 2010-01-03T17:31:17Z | [
"python",
"parsing",
"integer"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 1,995,632 | <p>The <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting">String Formatting Operations</a> section of the Python documentation contains the answer you're looking for. In short:</p>
<pre><code>"%0.2f" % (num,)
</code></pre>
<p>Some examples:</p>
<pre><code>>>> "%0.2f" % 10
'10.00'
&... | 103 | 2010-01-03T17:35:29Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 1,995,634 | <p>You can use the <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting" rel="nofollow" title="string formatting operator">string formatting operator</a> as so:</p>
<pre><code>num = 49
x = "%.2f" % num # x is now the string "49.00"
</code></pre>
<p>I'm not sure what you mean by "efficient" -- t... | 21 | 2010-01-03T17:35:59Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 1,995,846 | <p>I suppose you're probably using the <a href="https://docs.python.org/2/library/decimal.html#decimal-objects"><code>Decimal()</code></a> objects from the <a href="https://docs.python.org/2/library/decimal.html"><code>decimal</code></a> module? (If you need exactly two digits of precision beyond the decimal point with... | 55 | 2010-01-03T18:43:52Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 8,940,627 | <p>You should use the <a href="https://docs.python.org/2/library/string.html#format-specification-mini-language">new format specifications</a> to define how your value should be represented:</p>
<pre><code>>>> from math import pi # pi ~ 3.141592653589793
>>> '{0:.2f}'.format(pi)
'3.14'
</code></pre>... | 198 | 2012-01-20T11:20:54Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 27,028,355 | <pre><code>>>> print "{:.2f}".format(1.123456)
1.12
</code></pre>
<p>You can change <code>2</code> in <code>2f</code> to any number of decimal points you want to show.</p>
| 6 | 2014-11-19T22:35:32Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 34,916,765 | <p>.format is a more readable way to handle variable formatting:</p>
<pre><code>'{:.{prec}f}'.format(26.034, prec=2)
</code></pre>
| 8 | 2016-01-21T06:26:41Z | [
"python",
"string-formatting"
] |
How can I format a decimal to always show 2 decimal places? | 1,995,615 | <p>I want to display:</p>
<p><code>49</code> as <code>49.00</code></p>
<p>and:</p>
<p><code>54.9</code> as <code>54.90</code></p>
<p>Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a <code>Decimal</code> with 2 decimal places, and I'd like to do it in an ... | 91 | 2010-01-03T17:30:44Z | 39,884,786 | <p>what about </p>
<pre><code>print round(20.2564567 , 2) >>>>>>> 20.25
print round(20.2564567 , 4) >>>>>>> 20.2564
</code></pre>
| 0 | 2016-10-05T22:40:48Z | [
"python",
"string-formatting"
] |
How do I implement 'Parameter Object' refactor in Python? | 1,995,622 | <p>Right now I use the parameter object's class to be inherited like so</p>
<pre><code>class A():
def __init__(self,p1,p2):
self.p1, self.p2 = p1, p2
class B(A):
def __init__(self,b):
self.p1, self.p2 = b.p1, b.p2
</code></pre>
<p>This trims up the absurdity of using the code but not the clas... | 3 | 2010-01-03T17:33:26Z | 1,995,644 | <pre><code>class B(A):
def __init__(self, *args, **kwargs):
super(B, self).__init__(*args, **kwargs)
</code></pre>
<p>Read more about <a href="http://docs.python.org/library/functions.html#super" rel="nofollow"><code>super()</code></a> for details.</p>
| 1 | 2010-01-03T17:39:39Z | [
"python",
"inheritance",
"refactoring",
"parameter-object"
] |
How do I implement 'Parameter Object' refactor in Python? | 1,995,622 | <p>Right now I use the parameter object's class to be inherited like so</p>
<pre><code>class A():
def __init__(self,p1,p2):
self.p1, self.p2 = p1, p2
class B(A):
def __init__(self,b):
self.p1, self.p2 = b.p1, b.p2
</code></pre>
<p>This trims up the absurdity of using the code but not the clas... | 3 | 2010-01-03T17:33:26Z | 1,995,664 | <p>Generally speaking, you likely don't need the parameter object refactor technique. Python has several collections in the standard library that already have the core benefits that a parameter object refactor would provide.</p>
<p>Additionally, the cost/benefit analysis for a refactor like the parameter object design... | 3 | 2010-01-03T17:46:52Z | [
"python",
"inheritance",
"refactoring",
"parameter-object"
] |
How do I implement 'Parameter Object' refactor in Python? | 1,995,622 | <p>Right now I use the parameter object's class to be inherited like so</p>
<pre><code>class A():
def __init__(self,p1,p2):
self.p1, self.p2 = p1, p2
class B(A):
def __init__(self,b):
self.p1, self.p2 = b.p1, b.p2
</code></pre>
<p>This trims up the absurdity of using the code but not the clas... | 3 | 2010-01-03T17:33:26Z | 1,996,149 | <p>The translation of the C++ code into python would be something like:</p>
<pre><code>class A():
def __init__(self,p1,p2):
self.p1, self.p2 = p1, p2
class B(A):
def __init__(self,b):
A.__init__(self, b.p1, b.p2)
</code></pre>
| 2 | 2010-01-03T20:18:47Z | [
"python",
"inheritance",
"refactoring",
"parameter-object"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,737 | <p><code>setjmp()</code> and <code>longjmp()</code> usually.</p>
<p>Exception catching does have a non-trivial cost, but for most purposes it's not a big deal.</p>
| 4 | 2010-01-03T18:08:45Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,748 | <p>In his book <em>C Interfaces and Implementations: Techniques for Creating Reusable Software</em>, D. R. Hanson provides a nice implementation of exceptions in pure C using a set of macros and <code>setjmp/longjmp</code>. He provides TRY/RAISE/EXCEPT/FINALLY macros that can emulate pretty much everything C++ excepti... | 17 | 2010-01-03T18:11:41Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,762 | <p>C/C++ compilers use the underlying OS facilities for exception handling. Frameworks like .Net or Java also rely, in the VM, on the OS facilities. In Windows for instance, the real heavy lifting is done by SEH, the Structured Exception Handling infrastructure. You should absolutely read the old reference article: <a ... | 7 | 2010-01-03T18:14:19Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,769 | <p>Regarding performance - sparse use of exceptions will probably have negligible effects, but do not abuse them.</p>
<p>I have personally seen Java code which performed two orders of magnitude worse than it could have (took about x100 the time) because exceptions were used in an important loop instead of more standar... | 1 | 2010-01-03T18:16:05Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,778 | <p>Here is a common way C++ exceptions are implemented:<br>
<a href="http://www.codesourcery.com/public/cxx-abi/abi-eh.html">http://www.codesourcery.com/public/cxx-abi/abi-eh.html</a></p>
<p>It is for the Itanium architecture, but the implementation described here is used in other architectures as well. Note that it i... | 20 | 2010-01-03T18:18:44Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,863 | <p>C++ code at Google (save for some Windows-specific cases) don't use exceptions: cfr <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Exceptions" rel="nofollow">the guidelines</a>, short form: "We do not use C++ exceptions". Quoting from the discussion (hit the arrow to expand on the URL):</p>... | 3 | 2010-01-03T18:49:51Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,895 | <p>Some runtimes like <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Exceptions/Articles/Exceptions64Bit.html" rel="nofollow">the Objective-C runtime</a> have zero-cost 64-bit exceptions. What that means is that it doesn't cost anything to enter a try block. However, this is quite costly... | 1 | 2010-01-03T18:59:46Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,995,979 | <p>Exceptions are just a specific example of a more general case of advanced non-local flow control constructs. Other examples are:</p>
<ul>
<li><em>notifications</em> (a generalization of exceptions, originally from some old Lisp object system, now implemented in e.g. CommonLisp and Ioke), </li>
<li><em>continuations... | 33 | 2010-01-03T19:24:44Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,996,011 | <p>The key thing an exception implementation needs to handle is how to return to the exception handler once an exception has been thrown. Since you may have made an arbitrary number of nested function calls since the try statement in C++, it must <em>unwind the call stack</em> searching for the handler. However impleme... | 4 | 2010-01-03T19:33:11Z | [
"c++",
"python",
"c",
"exception"
] |
How are exceptions implemented under the hood? | 1,995,734 | <p>Just about everyone uses them, but many, including me simply take it for granted that they just work.</p>
<p>I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.</p>
<p>Now, C++ is probably a good place to start since you can throw anything in ... | 56 | 2010-01-03T18:06:17Z | 1,997,160 | <p>The best paper ever written on the <em>implementation</em> of exceptions (under the hood) is <a href="http://www.computer.org/portal/web/csdl/doi/10.1109/TSE.1979.230191">Exception Handling in CLU</a> by Barbara Liskov and Alan Snyder. I have referred to it every time I've started a new compiler.</p>
<p>For a some... | 6 | 2010-01-04T01:58:16Z | [
"c++",
"python",
"c",
"exception"
] |
applying image decoration (border) in Python (programatically) | 1,995,772 | <p>I am looking for a way to create a border in python.Is there any library in Python which we can import to create a border.</p>
<p>Note that I do not want to use any image masks to create this effect (e.g. I don't want to use any image editing package like GIMP to create a border image mask) . </p>
<p>Here is what ... | 4 | 2010-01-03T18:16:41Z | 1,995,804 | <p>You can use the <a href="http://www.imagemagick.org/download/python/" rel="nofollow">PythonMagick module</a>. the documentation for this module is <a href="http://www.imagemagick.org/Magick++/Image.html#Image%20Manipulation%20Methods" rel="nofollow">here (Magic ++ documentation)</a></p>
<p>Example: To add a red 2 p... | 2 | 2010-01-03T18:27:11Z | [
"python",
"image",
"image-processing"
] |
applying image decoration (border) in Python (programatically) | 1,995,772 | <p>I am looking for a way to create a border in python.Is there any library in Python which we can import to create a border.</p>
<p>Note that I do not want to use any image masks to create this effect (e.g. I don't want to use any image editing package like GIMP to create a border image mask) . </p>
<p>Here is what ... | 4 | 2010-01-03T18:16:41Z | 1,995,990 | <pre><code>foo2 = foo.copy()
draw = ImageDraw.Draw(foo2)
for i in range(width):
draw.rectangle([i, i, foo2.size[0]-i-1, foo2.size[1]-i-1], outline = color)
</code></pre>
<p><code>foo2</code> will have a <code>width</code>-pixel border of <code>color</code>.</p>
<p>If you want different colored borders on each sid... | 1 | 2010-01-03T19:28:23Z | [
"python",
"image",
"image-processing"
] |
applying image decoration (border) in Python (programatically) | 1,995,772 | <p>I am looking for a way to create a border in python.Is there any library in Python which we can import to create a border.</p>
<p>Note that I do not want to use any image masks to create this effect (e.g. I don't want to use any image editing package like GIMP to create a border image mask) . </p>
<p>Here is what ... | 4 | 2010-01-03T18:16:41Z | 1,996,250 | <p>Look at the <a href="http://www.pythonware.com/library/pil/handbook/imageops.htm">ImageOps</a> module within the PIL.</p>
<pre><code>import Image
import ImageOps
x = Image.open('test.png')
y = ImageOps.expand(x,border=5,fill='red')
y.save('test2.png')
</code></pre>
| 7 | 2010-01-03T20:49:58Z | [
"python",
"image",
"image-processing"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,995,924 | <p>I don't think this is testing what you think it's testing. It looks like you're trying to say "for each number between 2 and my candidate, check to see if the candidate is evenly divisible by that number". However, when you find a prime (candidate%x == 0), you're only incrementing the candidate-- you still need to s... | 3 | 2010-01-03T19:09:00Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,995,947 | <p>There is lots (!) to be improved with your Python code, but to answer your specific question: </p>
<p>When you have found a divisor (<code>candidate % x == 0</code>), you increment the candidate, but you don't do anything about <code>x</code>. This can lead to two problems:</p>
<ol>
<li><code>candidate</code> migh... | 5 | 2010-01-03T19:16:25Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,995,971 | <p>As for optimizations, if you're definite that you want to follow this implementation, you could avoid looking at numbers that:</p>
<ol>
<li>end in 5, since they are divisible by 5.</li>
<li>are comprised by the same digits, e.g. 22, 33, 44, 55, 66, etc., since they are divisible by 11.</li>
</ol>
<p>Don't forget t... | 0 | 2010-01-03T19:22:43Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,995,986 | <p>Unless I'm very much mistaken, you are always adding the current candidate to the list of primes, regardless of whether a divisor has been found or not. Your code to append to the list of primes (putting aside the immutable tuple comment made earlier) is outside of the test for integer divisors, and therefore always... | 0 | 2010-01-03T19:26:02Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,996,001 | <p>It's good to know that every prime number bigger than 3 can be written as:
6k-1/+1. </p>
<p>When you are looking for the next candidate, you can always write something like this (code snippet is in C):</p>
<pre><code>a=1;
...
candidate=6*k+(a=(a==-1)?1:-1);
if(a==1){
k++;
}
</code></pre>
<p>And a funct... | 2 | 2010-01-03T19:31:24Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,996,032 | <p>in the statement:</p>
<pre><code>for x in range(2,candidate)
</code></pre>
<p>you can reduce the number of iterations by scanning up to sqrt(candidate) </p>
<blockquote>
<p>If candidate is divisible by x, then we
can write candidate=x*b for some b. If x
is less than or equal to b, then x
must be smaller ... | 2 | 2010-01-03T19:38:09Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,996,071 | <p>If you want anything remotely efficient, do the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow">Sieve of Eratosthenes</a> - it's as simple as it's old.</p>
<pre><code>MAX = 10000
candidates = [True] * MAX
candidates[0] = False
candidates[1] = False
primelist = []
for p,isprime in enumer... | 0 | 2010-01-03T19:47:13Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 1,996,092 | <p>There is a nice <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a> generator implementation in test_generators.py:</p>
<pre><code>def intsfrom(i):
while 1:
yield i
i += 1
def firstn(g, n):
return [g.next() for i in range(n)]
def exclude_multiples(n, ... | 8 | 2010-01-03T19:54:41Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 2,000,699 | <p>FYI... I solved it with the following code, though it can be optimised much much more, I just wanted to solve it in this manner first. Thanks everyone for your help.</p>
<pre><code>from math import *
primes=[2,3]
count=2
testnumber=5
while count<1000:
flag=0
for x in range(2,testnumber):
if x<... | 0 | 2010-01-04T16:50:18Z | [
"python",
"primes"
] |
Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python] | 1,995,890 | <p>The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :(</p>
<pre><code>count=1 #to keep count of prime number... | 6 | 2010-01-03T18:57:36Z | 2,904,629 | <p>c beginner </p>
<pre><code>#include<stdio.h>
int main ()
{
int a,s,c,v,f,p,z;
while(scanf("%d",&f) !=EOF){
p=0;
for(z=1;p<f;z++){
s=2;
a=z;
while(s<a){
if(a%s==0)s=a+1;
else s=s+1;
... | 0 | 2010-05-25T12:41:47Z | [
"python",
"primes"
] |
Creating an MS Office document-like file format to expose document properties | 1,996,162 | <p>Our application's "documents" are single binary files.</p>
<p>Our customers have asked if we can add MS Office-like document properties to our document files so that they are easier for users to manage. By easier to manage, I mean the ability for Windows Explorer to display common document properties in tooltips.</... | 3 | 2010-01-03T20:21:07Z | 1,996,467 | <p>I'm pretty sure your best answer is to use the OLE compound document.</p>
<p>Microsoft may have stopped using this, but that is because they have gone to an XML file format. Unless you are willing to convert from your current file format to XML, I do not think that the new standard for tags will be interesting for... | 3 | 2010-01-03T21:50:10Z | [
"python",
"file",
"winapi",
"file-properties"
] |
Creating an MS Office document-like file format to expose document properties | 1,996,162 | <p>Our application's "documents" are single binary files.</p>
<p>Our customers have asked if we can add MS Office-like document properties to our document files so that they are easier for users to manage. By easier to manage, I mean the ability for Windows Explorer to display common document properties in tooltips.</... | 3 | 2010-01-03T20:21:07Z | 2,003,160 | <p>On Windows 2000 or higher, instead of using OLE compound document, you can also <a href="http://blogs.msdn.com/benkaras/archive/2007/01/05/choosing-your-property-api.aspx" rel="nofollow">store the summery information in the NTFS file metadata</a> so applications such as Windows Explorer or Windows Desktop Search can... | 0 | 2010-01-04T23:44:21Z | [
"python",
"file",
"winapi",
"file-properties"
] |
All Possible combination for an HEX Value from a given set of chars | 1,996,184 | <p>I am new to python and programming,</p>
<p>I am looking for a code, or a sample code that can have a predefined set of hex values
and that can find the 3 used values within to generate a certain value.</p>
<p>lets say I have a value of : 0x50158A51</p>
<p>this is a 4 byte (32 bit) hex value</p>
<p>now i need to... | -3 | 2010-01-03T20:28:35Z | 1,996,200 | <p>What you're asking for isn't possible. There will be infinite sequences of numbers that when added together will continue to produce the same result, modulo 2^32.</p>
<p>As a trivial example, say that your target number is 0x10000000 and the only hex values you allow are zero and one. Then the following sequences o... | 1 | 2010-01-03T20:33:47Z | [
"python",
"dataset",
"hex",
"subtraction"
] |
All Possible combination for an HEX Value from a given set of chars | 1,996,184 | <p>I am new to python and programming,</p>
<p>I am looking for a code, or a sample code that can have a predefined set of hex values
and that can find the 3 used values within to generate a certain value.</p>
<p>lets say I have a value of : 0x50158A51</p>
<p>this is a 4 byte (32 bit) hex value</p>
<p>now i need to... | -3 | 2010-01-03T20:28:35Z | 1,996,547 | <p>The following program for 0x50158A51 generates: </p>
<pre><code>0x50157f51 + 0x00000b00 + 0x00000000 = 0x50158A51
</code></pre>
<p>for 0x1090F0FF it generates:</p>
<pre><code>0x107f7f7f + 0x000011717f + 0x00000001 = 0x1090f0ff
</code></pre>
<p>where all "characters" in summands are from allowed set and not from ... | 1 | 2010-01-03T22:16:07Z | [
"python",
"dataset",
"hex",
"subtraction"
] |
All Possible combination for an HEX Value from a given set of chars | 1,996,184 | <p>I am new to python and programming,</p>
<p>I am looking for a code, or a sample code that can have a predefined set of hex values
and that can find the 3 used values within to generate a certain value.</p>
<p>lets say I have a value of : 0x50158A51</p>
<p>this is a 4 byte (32 bit) hex value</p>
<p>now i need to... | -3 | 2010-01-03T20:28:35Z | 1,996,813 | <p>From what I understood, but I may be wrong, you are talking about variation of a <a href="http://en.wikipedia.org/wiki/Subset_sum_problem" rel="nofollow">Subset Sum Problem</a>, which is NP-Complete. So you may look for some more info about that.</p>
| 0 | 2010-01-03T23:45:57Z | [
"python",
"dataset",
"hex",
"subtraction"
] |
How to connect two state circles with an arrow in tkinter? | 1,996,377 | <p>I am currently writing a fsm editor with tkinter. But, I stuck on connecting two states. I have two questions:</p>
<p>1) How can make the transition arrow growable according to mouse movement?</p>
<p>2) How can I stick the starting point of the arrow on a state and the end point of the arrow on another state?</p>
... | 2 | 2010-01-03T21:25:00Z | 1,997,043 | <p>Tkinter is perfectly fine for this sort of application. In the past I've worked on tools that were boxes connected with arrows that stayed connected as you move the boxes around (which is what I think you are asking about). Don't let people who don't know much about Tkinter sway you -- it's a perfectly fine toolkit ... | 3 | 2010-01-04T01:13:28Z | [
"python",
"tkinter",
"fsm"
] |
How to connect two state circles with an arrow in tkinter? | 1,996,377 | <p>I am currently writing a fsm editor with tkinter. But, I stuck on connecting two states. I have two questions:</p>
<p>1) How can make the transition arrow growable according to mouse movement?</p>
<p>2) How can I stick the starting point of the arrow on a state and the end point of the arrow on another state?</p>
... | 2 | 2010-01-03T21:25:00Z | 1,997,117 | <p>Here's an example that shows the concept. In a nutshell, use tags to associate lines with boxes, and simply adjust the coordinates appropriately when the user moves the mouse.</p>
<p>Run the example, then click and drag from within the beige box.</p>
<p>Of course, for production code you need to make a more genera... | 4 | 2010-01-04T01:40:38Z | [
"python",
"tkinter",
"fsm"
] |
Wildcard matching a string in Python regex search | 1,996,482 | <p>I thought I would write some quick code to download the number of "fans" a Facebook page has.</p>
<p>For some reason, despite a fair number of iterations I've tried, I can't get the following code to pick out the number of fans in the HTML. None of the other solutions I found on the web correctly match the regex i... | 4 | 2010-01-03T21:55:48Z | 1,996,499 | <pre><code>import urllib
import re
fbhandle = urllib.urlopen('http://www.facebook.com/Microsoft')
pattern = "6 of(.*)fans" #this wild card doesnt appear to work?
compiled = re.compile(pattern)
ms = compiled.search(fbhandle.read())
print ms.group(1).strip()
fbhandle.close()
</code></pre>
<p>You needed to use <code>re... | 7 | 2010-01-03T22:02:11Z | [
"python",
"regex"
] |
Wildcard matching a string in Python regex search | 1,996,482 | <p>I thought I would write some quick code to download the number of "fans" a Facebook page has.</p>
<p>For some reason, despite a fair number of iterations I've tried, I can't get the following code to pick out the number of fans in the HTML. None of the other solutions I found on the web correctly match the regex i... | 4 | 2010-01-03T21:55:48Z | 1,997,013 | <p>don't need regex</p>
<pre><code>import urllib
fbhandle = urllib.urlopen('http://www.facebook.com/Microsoft')
for line in fbhandle.readlines():
line=line.rstrip().split("</span>")
for item in line:
if ">Fans<" in item:
rind=item.rindex("<span>")
print "-->... | 0 | 2010-01-04T01:02:51Z | [
"python",
"regex"
] |
Wildcard matching a string in Python regex search | 1,996,482 | <p>I thought I would write some quick code to download the number of "fans" a Facebook page has.</p>
<p>For some reason, despite a fair number of iterations I've tried, I can't get the following code to pick out the number of fans in the HTML. None of the other solutions I found on the web correctly match the regex i... | 4 | 2010-01-03T21:55:48Z | 1,997,016 | <p>Evan Fosmark already gave a good answer. This is just more info.</p>
<p>You have this line:</p>
<pre><code>pattern = "6 of(.*)fans"
</code></pre>
<p>In general, this isn't a good regular expression. If the input text was:</p>
<p>"6 of 99 fans in the whole galaxy of fans"</p>
<p>Then the match group (the stuff... | 8 | 2010-01-04T01:03:01Z | [
"python",
"regex"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.