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 |
|---|---|---|---|---|---|---|---|---|---|
What is memoization and how can I use it in Python? | 1,988,804 | <p>I just started Python and I've got no idea what <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> is and how to use it. Also, may I have a simplified example?</p>
| 215 | 2010-01-01T14:55:48Z | 17,268,784 | <p>Here is a solution that will work with list or dict type arguments without whining:</p>
<pre><code>def memoize(fn):
"""returns a memoized version of any function that can be called
with the same list of arguments.
Usage: foo = memoize(foo)"""
def handle_item(x):
if isinstance(x, dict):
... | 5 | 2013-06-24T05:53:40Z | [
"python",
"memoization"
] |
What is memoization and how can I use it in Python? | 1,988,804 | <p>I just started Python and I've got no idea what <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> is and how to use it. Also, may I have a simplified example?</p>
| 215 | 2010-01-01T14:55:48Z | 21,459,113 | <p>Solution that works with both positional and keyword arguments independently of order in which keyword args were passed (using <a href="http://docs.python.org/2/library/inspect.html#inspect.getargspec" rel="nofollow">inspect.getargspec</a>):</p>
<pre><code>import inspect
import functools
def memoize(fn):
cache... | 2 | 2014-01-30T14:26:02Z | [
"python",
"memoization"
] |
What is memoization and how can I use it in Python? | 1,988,804 | <p>I just started Python and I've got no idea what <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> is and how to use it. Also, may I have a simplified example?</p>
| 215 | 2010-01-01T14:55:48Z | 21,694,503 | <p>Well I should answer the first part first: what's memoization?</p>
<p>It's just a method to trade memory for time. Think of <a href="http://en.wikipedia.org/wiki/Multiplication_table" rel="nofollow">Multiplication Table</a>.</p>
<p>Using mutable object as default value in Python is usually considered bad. But if u... | 4 | 2014-02-11T06:16:18Z | [
"python",
"memoization"
] |
What is memoization and how can I use it in Python? | 1,988,804 | <p>I just started Python and I've got no idea what <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> is and how to use it. Also, may I have a simplified example?</p>
| 215 | 2010-01-01T14:55:48Z | 25,367,373 | <p>Just wanted to add to the answers already provided, the <a href="https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize" rel="nofollow">Python decorator library</a> has some simple yet useful implementations that can also memoize "unhashable types", unlike <code>functools.lru_cache</code>.</p>
| 2 | 2014-08-18T15:56:38Z | [
"python",
"memoization"
] |
What is memoization and how can I use it in Python? | 1,988,804 | <p>I just started Python and I've got no idea what <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> is and how to use it. Also, may I have a simplified example?</p>
| 215 | 2010-01-01T14:55:48Z | 26,769,816 | <p>Let's not forget the built-in <code>hasattr</code> function, for those who want to hand-craft. That way you can keep the mem cache inside the function definition (as opposed to a global).</p>
<pre><code>def fact(n):
if not hasattr(fact, 'mem'):
fact.mem = {1: 1}
if not n in fact.mem:
fact.me... | 7 | 2014-11-06T00:35:16Z | [
"python",
"memoization"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,278 | <p>There are probably dozens of ways to store your list data in a file instead of in memory. How you choose to do it will depend entirely on what sort of operations you need to perform on the data. Do you need random access to the Nth element? Do you need to iterate over all elements? Will you be searching for elem... | 8 | 2010-01-01T18:42:11Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,286 | <p>Modern operating systems will handle this for you without you having to worry about it. It's called <a href="http://en.wikipedia.org/wiki/Virtual_memory" rel="nofollow">virtual memory</a>. </p>
| 0 | 2010-01-01T18:44:50Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,292 | <p>The answer is very much "it depends".</p>
<p>What are you storing in the lists? Strings? integers? Objects?</p>
<p>How often is the list written to compared with being read? Are items only appended on the end, or can entries be modified or inserted in the middle?</p>
<p>If you are only appending to the end then... | 6 | 2010-01-01T18:47:04Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,320 | <p>You might want to consider a different kind of structure: not a list, but figuring out how to do (your task) with a generator or a custom iterator.</p>
| 1 | 2010-01-01T19:05:56Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,345 | <p>Did you check shelve python module which is based on pickle?</p>
<p><a href="http://docs.python.org/library/shelve.html" rel="nofollow">http://docs.python.org/library/shelve.html</a></p>
| 2 | 2010-01-01T19:19:28Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,434 | <p>If your "numbers" are simple-enough ones (signed or unsigned integers of up to 4 bytes each, or floats of 4 or 8 bytes each), I recommend the standard library <a href="http://docs.python.org/library/array.html?highlight=array#module-array">array</a> module as the best way to keep a few millions of them in memory (th... | 12 | 2010-01-01T19:53:36Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,459 | <p>What about a document oriented database?<br>
There are several alternatives; I think the most known one currently is <a href="http://couchdb.apache.org/" rel="nofollow">CouchDB</a>, but you can also go for <a href="http://stackoverflow.com/questions/601865/python-table-engine-binding-for-tokyo-cabinet">Tokyo Cabinet... | 0 | 2010-01-01T20:02:58Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 1,989,466 | <p>Well, if you are looking for speed and your data is numerical in nature, you could consider using numpy and <a href="http://www.pytables.org/" rel="nofollow">PyTables</a> or <a href="http://h5py.alfven.org/" rel="nofollow">h5py</a>. From what I remember, the interface is not as nice as simple lists, but the scalabi... | 4 | 2010-01-01T20:06:07Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
Alternatives to keeping large lists in memory (python) | 1,989,251 | <p>If I have a list(or array, dictionary....) in python that could exceed the available memory address space, (32 bit python) what are the options and there relative speeds? (other than not making a list that large)
Let me emphasize "could". The list could exceed the memory but I have know way of knowing before hand. I... | 10 | 2010-01-01T18:31:57Z | 15,526,187 | <p>You can try blist:
<a href="https://pypi.python.org/pypi/blist/" rel="nofollow">https://pypi.python.org/pypi/blist/</a></p>
<blockquote>
<p>The blist is a drop-in replacement for the Python list the provides better performance when modifying large lists.</p>
</blockquote>
| 0 | 2013-03-20T14:21:09Z | [
"python",
"file",
"list",
"memory-management",
"32bit-64bit"
] |
pkg_resources not found after installing setuptools | 1,989,355 | <p>I am trying to compile and install python2.6.4 on Debian 5.0.3 (64bit). I installed using 'make altinstall' as I want to keep python 2.5.2 that comes with Deb5.0 as my default python.</p>
<p>Following this, I installed setuptools 0.6c11 using the command 'sudo sh setuptools-0.6c11-py2.6.egg --prefix=/usr/local'. Ho... | 1 | 2010-01-01T19:21:54Z | 1,989,399 | <p>Packaging and package integration is tricky. Debian has Python 2.6, but for some internal reason it is only in the experimental branch:</p>
<pre><code>$ rmadison python2.6
python2.6 | 2.6.2-2 | experimental | source, ia64
python2.6 | 2.6.4-1 | experimental | source, alpha, amd64, armel, hppa, \
... | 0 | 2010-01-01T19:38:42Z | [
"python",
"debian",
"setuptools",
"pkg-resources"
] |
Repeating regex groups | 1,989,463 | <p>I'm trying to get some information from a web site. The information I want is in a table so I made a regex but I don't know the right way to simplify it.</p>
<p>The following are two parts of my regex that I would like to simplify:</p>
<pre><code><br>(.*)<br>(.*)<br>(.*)
<tr><td>(.+)... | 1 | 2010-01-01T20:04:04Z | 1,989,467 | <p><a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>
<p>"Have you tried using an XML parser instead?"</p>
<p>EDIT: This is... | 3 | 2010-01-01T20:06:25Z | [
"python",
"html",
"regex"
] |
Repeating regex groups | 1,989,463 | <p>I'm trying to get some information from a web site. The information I want is in a table so I made a regex but I don't know the right way to simplify it.</p>
<p>The following are two parts of my regex that I would like to simplify:</p>
<pre><code><br>(.*)<br>(.*)<br>(.*)
<tr><td>(.+)... | 1 | 2010-01-01T20:04:04Z | 1,989,484 | <p>You just need to put the block in parens and then use the {...} operators, e.g.:</p>
<pre><code>(foo...){1,10}
</code></pre>
<p>Matches 1 to 10 instances of the thing inside of there. Given your example above, you can nest those:</p>
<pre><code>((f..)(b..)){1,10}
</code></pre>
| 1 | 2010-01-01T20:12:07Z | [
"python",
"html",
"regex"
] |
Repeating regex groups | 1,989,463 | <p>I'm trying to get some information from a web site. The information I want is in a table so I made a regex but I don't know the right way to simplify it.</p>
<p>The following are two parts of my regex that I would like to simplify:</p>
<pre><code><br>(.*)<br>(.*)<br>(.*)
<tr><td>(.+)... | 1 | 2010-01-01T20:04:04Z | 1,989,506 | <p>This is the wrong way to go unless you're trying to scrape some data out of a tiny fragment. </p>
<p>It would be much better if you used a tolerant HTML. BeautifulSoup mentioned earlier is a good one but it's stagnating and I don't believe it's being maintained actively anymore. </p>
<p>A highly recommended parser... | 3 | 2010-01-01T20:20:31Z | [
"python",
"html",
"regex"
] |
Problems assigning dict values to variables | 1,989,511 | <p>I am struggling with something that must be one of those 'it is so obvious I am an idiot' problems. I have a csv file that I want to read in and use to create individual 'tables'. I have a variable (RID) that marks the beginning of a new 'table'. </p>
<p>I can't get my indicator variable (currentRow) to advance ... | -1 | 2010-01-01T20:21:11Z | 1,989,525 | <p>One solution is to add the following somewhere inside the loop:</p>
<pre><code>currentRow += 1
</code></pre>
<p>However, a better solution may be to use enumerable:</p>
<pre><code>for currentRow, line in csv.DictReader..:
stuff
</code></pre>
| 0 | 2010-01-01T20:25:18Z | [
"python",
"csv"
] |
Problems assigning dict values to variables | 1,989,511 | <p>I am struggling with something that must be one of those 'it is so obvious I am an idiot' problems. I have a csv file that I want to read in and use to create individual 'tables'. I have a variable (RID) that marks the beginning of a new 'table'. </p>
<p>I can't get my indicator variable (currentRow) to advance ... | -1 | 2010-01-01T20:21:11Z | 1,989,529 | <p>It looks to me like it's possible that <code>theTables[oldTableKey]=theList</code> could be executed with an uninitialized value of <code>oldTableKey</code>.</p>
| 0 | 2010-01-01T20:26:00Z | [
"python",
"csv"
] |
Problems assigning dict values to variables | 1,989,511 | <p>I am struggling with something that must be one of those 'it is so obvious I am an idiot' problems. I have a csv file that I want to read in and use to create individual 'tables'. I have a variable (RID) that marks the beginning of a new 'table'. </p>
<p>I can't get my indicator variable (currentRow) to advance ... | -1 | 2010-01-01T20:21:11Z | 1,989,531 | <p>In the line:</p>
<pre><code>currrentRow=int(line['RID'])
</code></pre>
<p>you have <strong>three</strong> <code>r</code>s in <code>currrentRow</code>. Reduce them to just two, and things should improve.</p>
| 7 | 2010-01-01T20:26:02Z | [
"python",
"csv"
] |
How to develop a Python module/package without having to restart the interpreter after every change? | 1,989,644 | <p>I am developing a Python package using a text editor and IPython. Each time I change any of the module code I have to restart the interpreter to test this. This is a pain since the classes I am developing rely on a context that needs to be re-established on each reload.</p>
<p>I am aware of the <code>reload()</code... | 6 | 2010-01-01T21:04:57Z | 1,989,671 | <p>Ipython does allow reloads see the magic function %run <a href="http://ipython.scipy.org/doc/stable/html/interactive/tutorial.html#the-run-magic-command" rel="nofollow">iPython doc</a></p>
<p>or if modules under the one have changed the recursive dreloadd() function</p>
<p>If you have a complex context is it poss... | 2 | 2010-01-01T21:18:30Z | [
"python",
"module",
"packages"
] |
How to develop a Python module/package without having to restart the interpreter after every change? | 1,989,644 | <p>I am developing a Python package using a text editor and IPython. Each time I change any of the module code I have to restart the interpreter to test this. This is a pain since the classes I am developing rely on a context that needs to be re-established on each reload.</p>
<p>I am aware of the <code>reload()</code... | 6 | 2010-01-01T21:04:57Z | 1,989,686 | <p>you could create a python script that sets up your context and run it with </p>
<pre><code>python -i context-setup.py
-i When a script is passed as first argument or the -c option is
used, enter interactive mode after executing the script or the
command. It does not read the $PYTH... | 0 | 2010-01-01T21:22:39Z | [
"python",
"module",
"packages"
] |
How to develop a Python module/package without having to restart the interpreter after every change? | 1,989,644 | <p>I am developing a Python package using a text editor and IPython. Each time I change any of the module code I have to restart the interpreter to test this. This is a pain since the classes I am developing rely on a context that needs to be re-established on each reload.</p>
<p>I am aware of the <code>reload()</code... | 6 | 2010-01-01T21:04:57Z | 1,990,165 | <p>A different approach may be to formalise your test driven development, and instead of using the interpreter to test your module, save your tests and run them directly.</p>
<p>You probably know of the various ways to do this with python, I imagine the simplest way to start in this direction is to copy and paste what... | 3 | 2010-01-02T00:33:20Z | [
"python",
"module",
"packages"
] |
How to develop a Python module/package without having to restart the interpreter after every change? | 1,989,644 | <p>I am developing a Python package using a text editor and IPython. Each time I change any of the module code I have to restart the interpreter to test this. This is a pain since the classes I am developing rely on a context that needs to be re-established on each reload.</p>
<p>I am aware of the <code>reload()</code... | 6 | 2010-01-01T21:04:57Z | 1,990,697 | <p>How about using <a href="http://code.google.com/p/python-nose/" rel="nofollow">nose</a> with <a href="http://jeffwinkler.net/2006/04/27/keeping-your-nose-green/" rel="nofollow">nosey</a> to run your tests automatically in a separate terminal every time you save your edits to disk? Set up all the state you need in yo... | 1 | 2010-01-02T05:36:39Z | [
"python",
"module",
"packages"
] |
commit & push to remote git repo via webhook? | 1,989,735 | <p>I want to commit to a git repo from app-engine via webhooks. I cannot install git on appengine. Possible?</p>
<p>I think it should be on GitHub, because they have a browser based text editor which can commit via the browser. E.g. <a href="http://github.com/dustingetz/autodoc/blob/master/todo.txt" rel="nofollow">go ... | 1 | 2010-01-01T21:37:24Z | 2,056,963 | <p>The tags say you're using python so this might not be particularly useful, but I do know there's a pure java implementation of git, <a href="http://www.eclipse.org/jgit/" rel="nofollow">JGit</a>, which might work on the app engine. It doesn't look like you can really call java code from python, but you could use a s... | 1 | 2010-01-13T13:38:59Z | [
"python",
"git",
"google-app-engine",
"github"
] |
commit & push to remote git repo via webhook? | 1,989,735 | <p>I want to commit to a git repo from app-engine via webhooks. I cannot install git on appengine. Possible?</p>
<p>I think it should be on GitHub, because they have a browser based text editor which can commit via the browser. E.g. <a href="http://github.com/dustingetz/autodoc/blob/master/todo.txt" rel="nofollow">go ... | 1 | 2010-01-01T21:37:24Z | 3,334,604 | <p>I'm trying to do the same. I found <a href="http://samba.org/~jelmer/dulwich/" rel="nofollow">http://samba.org/~jelmer/dulwich/</a> but this implementation uses the mmap module which is blocked in app engine.</p>
<p>@Dustin
Have you figgured a way to push into git repos from app engine</p>
| 0 | 2010-07-26T12:04:37Z | [
"python",
"git",
"google-app-engine",
"github"
] |
why my code error,I would like to print the parameters of two functions | 1,989,843 | <pre><code>def c(*x,**y):
print x,y
def a(*x,**y):
print x
def b(*x1,**y1):
c(*(x+x1),**dict(y,**y1))
b()
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error
</code></pre>
| 0 | 2010-01-01T22:17:11Z | 1,989,848 | <p>Replace b() with return b </p>
<p>Running this in Python 3.1:</p>
<pre><code>def c(*x,**y):
print(x,y)
def a(*x,**y):
print(x)
def b(*x1,**y1):
c(*(x+x1),**dict(y,**y1))
return b
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')
</code></pre>
<p>produces:</p>
<pre><code>>>> ==============... | 1 | 2010-01-01T22:19:31Z | [
"python"
] |
why my code error,I would like to print the parameters of two functions | 1,989,843 | <pre><code>def c(*x,**y):
print x,y
def a(*x,**y):
print x
def b(*x1,**y1):
c(*(x+x1),**dict(y,**y1))
b()
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error
</code></pre>
| 0 | 2010-01-01T22:17:11Z | 1,989,853 | <p>function a() is not returning a function; actually, it returns <code>None</code>. Therefore, the second set of parenthesis is a call on None object - and that's an error.<br>
Did you intend to return a function, like doing something like <code>return b</code>?</p>
| 2 | 2010-01-01T22:20:40Z | [
"python"
] |
why my code error,I would like to print the parameters of two functions | 1,989,843 | <pre><code>def c(*x,**y):
print x,y
def a(*x,**y):
print x
def b(*x1,**y1):
c(*(x+x1),**dict(y,**y1))
b()
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error
</code></pre>
| 0 | 2010-01-01T22:17:11Z | 1,989,861 | <pre><code>a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error
</code></pre>
<p>I assume you got "object is not callable" exception..</p>
<p>May be you need to return a function object 'b' (not result of the 'b') ?</p>
<p>So instead of</p>
<pre><code>b()
</code></pre>
<p>try</p>
<pre><code>return b # without braces and... | 1 | 2010-01-01T22:23:33Z | [
"python"
] |
why my code error,I would like to print the parameters of two functions | 1,989,843 | <pre><code>def c(*x,**y):
print x,y
def a(*x,**y):
print x
def b(*x1,**y1):
c(*(x+x1),**dict(y,**y1))
b()
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error
</code></pre>
| 0 | 2010-01-01T22:17:11Z | 1,989,862 | <p>The error I get is:</p>
<blockquote>
<p>Traceback (most recent call last):<br>
File "./tmp.py", line 11, in
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')
TypeError: 'NoneType' object is not
callable</p>
</blockquote>
<p>I can fix this by changing your code to:</p>
<pre><code>#!/usr/bin/python
def c(*x,*... | 1 | 2010-01-01T22:23:38Z | [
"python"
] |
Call Method on Every Ancestor in Python | 1,989,863 | <p>I have an object of class 'D' in python, and I want to sequentially execute the 'run' method as defined by 'D' and each of it's ancestors ('A', 'B' and 'C').</p>
<p>I'm able to accomplish this like this</p>
<pre><code>class A(object):
def run_all(self):
# I prefer to execute in revere MRO order
... | 2 | 2010-01-01T22:23:40Z | 1,989,874 | <p>You should not use <code>__getattribute__</code> method..</p>
<p>just do the following:</p>
<pre><code>getattr(cls, 'run')(self)
</code></pre>
| 1 | 2010-01-01T22:29:15Z | [
"python",
"datamodel"
] |
Call Method on Every Ancestor in Python | 1,989,863 | <p>I have an object of class 'D' in python, and I want to sequentially execute the 'run' method as defined by 'D' and each of it's ancestors ('A', 'B' and 'C').</p>
<p>I'm able to accomplish this like this</p>
<pre><code>class A(object):
def run_all(self):
# I prefer to execute in revere MRO order
... | 2 | 2010-01-01T22:23:40Z | 1,989,896 | <p>Why don't you simply use <code>super</code>? Although some <a href="http://fuhm.net/super-harmful/" rel="nofollow">consider it harmful</a>, it was designed with exactly this kind of scenario in mind, and I would use it without any hesitation.</p>
<p>From <a href="http://docs.python.org/library/functions.html#super"... | 1 | 2010-01-01T22:38:06Z | [
"python",
"datamodel"
] |
Call Method on Every Ancestor in Python | 1,989,863 | <p>I have an object of class 'D' in python, and I want to sequentially execute the 'run' method as defined by 'D' and each of it's ancestors ('A', 'B' and 'C').</p>
<p>I'm able to accomplish this like this</p>
<pre><code>class A(object):
def run_all(self):
# I prefer to execute in revere MRO order
... | 2 | 2010-01-01T22:23:40Z | 1,989,971 | <p>If you're OK with changing all the <code>run</code> implementations (and calling <code>run</code> instead of <code>run_all</code> in D), this works:</p>
<pre><code>class A(object):
def run(self):
print "Running A"
class B(A):
def run(self):
super(B, self).run()
print "Running B"
cl... | 4 | 2010-01-01T23:03:15Z | [
"python",
"datamodel"
] |
My own OCR-program in Python | 1,989,987 | <p>I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling.</p>
<pre><code>from PIL import Image
import numpy as np
im = Image.open("D:\\... | 24 | 2010-01-01T23:14:50Z | 1,990,918 | <p>OCR is very, very hard. Even with computer-generated characters, it's quite challenging if you don't know the font and font size in advance. Even if you're matching characters exactly, I would not call it a "beginning" programming project; it's quite subtle.</p>
<p>If you want to recognize scanned, or handwritten c... | 7 | 2010-01-02T07:52:32Z | [
"python",
"arrays",
"artificial-intelligence",
"ocr"
] |
My own OCR-program in Python | 1,989,987 | <p>I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling.</p>
<pre><code>from PIL import Image
import numpy as np
im = Image.open("D:\\... | 24 | 2010-01-01T23:14:50Z | 1,990,940 | <p>OCR is very, very difficult! What approach to use to attempt OCR will be based on what you are trying to accomplish (hand writing recongnition, computer generated text reading, etc.)</p>
<p>However, to get you started, read up on Neural Networks and OCR. Here are a few jump-right-in articles on the subject:</p>
<p... | 4 | 2010-01-02T08:03:12Z | [
"python",
"arrays",
"artificial-intelligence",
"ocr"
] |
My own OCR-program in Python | 1,989,987 | <p>I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling.</p>
<pre><code>from PIL import Image
import numpy as np
im = Image.open("D:\\... | 24 | 2010-01-01T23:14:50Z | 1,990,992 | <p>OCR is not an easy task indeed. That's why text CAPTCHAs still work :)</p>
<p>To talk only about the letter extraction and not the pattern recognition, the technique you are using to separate the letters is called <a href="http://en.wikipedia.org/wiki/Connected_component_labeling" rel="nofollow"><strong>Connected C... | 31 | 2010-01-02T08:34:23Z | [
"python",
"arrays",
"artificial-intelligence",
"ocr"
] |
My own OCR-program in Python | 1,989,987 | <p>I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling.</p>
<pre><code>from PIL import Image
import numpy as np
im = Image.open("D:\\... | 24 | 2010-01-01T23:14:50Z | 1,993,860 | <p>Most OCR algorithms these days are based on neural network algorithms. <a href="http://en.wikipedia.org/wiki/Hopfield_net" rel="nofollow">Hopfield networks</a> are a good place to start. Based on the Hopfield Model available <a href="http://www.ip-atlas.com/pub/nap/nn-src/" rel="nofollow">here in C</a>, I built a... | 4 | 2010-01-03T03:29:48Z | [
"python",
"arrays",
"artificial-intelligence",
"ocr"
] |
what is the 'self.__class__.__missing__' mean | 1,990,145 | <p>in pinax Userdict.py:</p>
<pre><code>def __getitem__(self, key):
if key in self.data:
return self.data[key]
if hasattr(self.__class__, "__missing__"):
return self.__class__.__missing__(self, key)
</code></pre>
<p>why does it do this on <code>self.__class__.__missing__</code>... | 0 | 2010-01-02T00:25:15Z | 1,990,177 | <p>The UserDict.py presented <a href="http://www.manifestdensity.net/2009/05/05/python_on_the_fonera/UserDict.py" rel="nofollow">here</a> emulates built-in <code>dict</code> closely, so for example:</p>
<pre><code>>>> class m(dict):
... def __missing__(self, key): return key + key
...
>>> a=m()
&g... | 4 | 2010-01-02T00:41:07Z | [
"python",
"pinax"
] |
is '__all__' only for 'from some import *' | 1,990,232 | <p>a.py</p>
<pre><code>__all__=['b','c']
a='aaa'
b='bbb'
def c():
print 'ccc'
def d():
print 'dddd'
</code></pre>
<p>b.py</p>
<pre><code>from a import a
print a
from a import *
print a
print d#error
</code></pre>
<p>Are there any other uses.</p>
<p>thanks</p>
| 0 | 2010-01-02T01:09:01Z | 1,990,263 | <p>No, the purpose of <code>__all__</code> is just to describe exactly what should be imported when you do <code>from foo import *</code>.</p>
| 0 | 2010-01-02T01:22:50Z | [
"python"
] |
is '__all__' only for 'from some import *' | 1,990,232 | <p>a.py</p>
<pre><code>__all__=['b','c']
a='aaa'
b='bbb'
def c():
print 'ccc'
def d():
print 'dddd'
</code></pre>
<p>b.py</p>
<pre><code>from a import a
print a
from a import *
print a
print d#error
</code></pre>
<p>Are there any other uses.</p>
<p>thanks</p>
| 0 | 2010-01-02T01:09:01Z | 1,990,271 | <p>No other uses, except limiting the damage caused by the horrible <code>from ... import *</code> usage.</p>
| 0 | 2010-01-02T01:25:11Z | [
"python"
] |
is '__all__' only for 'from some import *' | 1,990,232 | <p>a.py</p>
<pre><code>__all__=['b','c']
a='aaa'
b='bbb'
def c():
print 'ccc'
def d():
print 'dddd'
</code></pre>
<p>b.py</p>
<pre><code>from a import a
print a
from a import *
print a
print d#error
</code></pre>
<p>Are there any other uses.</p>
<p>thanks</p>
| 0 | 2010-01-02T01:09:01Z | 1,990,285 | <p>Yes, it also changes what help(a) documents. </p>
| 3 | 2010-01-02T01:29:50Z | [
"python"
] |
What does this code from types.py do? | 1,990,339 | <pre><code>try:
raise TypeError
except TypeError:
try:
tb = sys.exc_info()[2]
TracebackType = type(tb)
FrameType = type(tb.tb_frame)
except AttributeError:
# In the restricted environment, exc_info returns (None, None,
# None) Then, tb.tb_frame gives an attribute erro... | 1 | 2010-01-02T01:55:54Z | 1,990,355 | <p>It's a trick to get a traceback object and a frame object so that TracebackType and FrameType can be assigned their types. It simply raises an exception so it can catch the exception, then get the traceback and frame from <code>sys.exc_info</code>.</p>
| 4 | 2010-01-02T02:01:59Z | [
"python"
] |
What does this code from types.py do? | 1,990,339 | <pre><code>try:
raise TypeError
except TypeError:
try:
tb = sys.exc_info()[2]
TracebackType = type(tb)
FrameType = type(tb.tb_frame)
except AttributeError:
# In the restricted environment, exc_info returns (None, None,
# None) Then, tb.tb_frame gives an attribute erro... | 1 | 2010-01-02T01:55:54Z | 1,990,358 | <p>The code tries to find out the types used for the tracebacks returned by <a href="http://docs.python.org/library/sys.html#sys.exc_info" rel="nofollow"><code>sys.exc_info()</code></a> and assigned these types to the variables <code>TracebackType</code> and <code>FrameType</code>.</p>
<p>To do so it first needs to ra... | 0 | 2010-01-02T02:04:21Z | [
"python"
] |
What does this code from types.py do? | 1,990,339 | <pre><code>try:
raise TypeError
except TypeError:
try:
tb = sys.exc_info()[2]
TracebackType = type(tb)
FrameType = type(tb.tb_frame)
except AttributeError:
# In the restricted environment, exc_info returns (None, None,
# None) Then, tb.tb_frame gives an attribute erro... | 1 | 2010-01-02T01:55:54Z | 1,990,376 | <p>It appears as though this code is used to get the call stack. If you research the exc_info function from <a href="http://pyref.infogami.com/sys.exc_info" rel="nofollow">http://pyref.infogami.com/sys.exc_info</a> you'll find that the function returns a tuple of 3 values where the third is a Traceback object. This o... | 0 | 2010-01-02T02:21:06Z | [
"python"
] |
Port knocking and RSA encryption | 1,990,366 | <p>I am doing on my project and there is about port knocking. I have 3 files that separated in server side and client.
In the server contains : portknocking server as a daemon and configuration file [contains sequence of port that must be satisfied and many other configuration detail]
In the client contains : portknock... | 0 | 2010-01-02T02:09:32Z | 1,990,871 | <blockquote>
<p>Is there possible to encrypt sequence port number in file configuration using RSA.</p>
</blockquote>
<p>Yes.</p>
<blockquote>
<p>how to do that?? </p>
</blockquote>
<p>You might try a bit of searching for a <a href="http://www.google.com/search?q=python+rsa+library" rel="nofollow">python rsa libr... | 1 | 2010-01-02T07:21:00Z | [
"python",
"rsa",
"public-key"
] |
Nesting 'WITH' statements in Python | 1,990,373 | <p>It turns out that "with" is a funny word to search for on the internet.</p>
<p>Does anyone knows what the deal is with nesting with statements in python?<br>
I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this:</p>
<pre><code>with open(file1) as ... | 1 | 2010-01-02T02:18:13Z | 1,990,378 | <p>AFAIK you can't read a file open with append mode <code>'a'</code>.</p>
| 6 | 2010-01-02T02:23:06Z | [
"python",
"append",
"with-statement"
] |
Nesting 'WITH' statements in Python | 1,990,373 | <p>It turns out that "with" is a funny word to search for on the internet.</p>
<p>Does anyone knows what the deal is with nesting with statements in python?<br>
I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this:</p>
<pre><code>with open(file1) as ... | 1 | 2010-01-02T02:18:13Z | 1,990,392 | <p>There is no problem with nesting <code>with</code> statements -- rather, you're opening <code>file2</code> for append, so you can't read from it.</p>
<p>If you do dislike nesting <code>with</code> statements, for whatever reason, you can often avoid that with the <a href="http://docs.python.org/library/contextlib.h... | 1 | 2010-01-02T02:28:46Z | [
"python",
"append",
"with-statement"
] |
Nesting 'WITH' statements in Python | 1,990,373 | <p>It turns out that "with" is a funny word to search for on the internet.</p>
<p>Does anyone knows what the deal is with nesting with statements in python?<br>
I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this:</p>
<pre><code>with open(file1) as ... | 1 | 2010-01-02T02:18:13Z | 1,990,397 | <blockquote>
<p>Upon inspection in the debugger, this is because it thinks the file is empty.</p>
</blockquote>
<p>I think that happens because it can't actually read anything. Even if it could, when you append to a file, the seek pointer is moved to the end of the file in preparation for writing to occur.</p>
<p>T... | 3 | 2010-01-02T02:32:16Z | [
"python",
"append",
"with-statement"
] |
Nesting 'WITH' statements in Python | 1,990,373 | <p>It turns out that "with" is a funny word to search for on the internet.</p>
<p>Does anyone knows what the deal is with nesting with statements in python?<br>
I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this:</p>
<pre><code>with open(file1) as ... | 1 | 2010-01-02T02:18:13Z | 1,990,427 | <p>As for searching for "with", prefixing a word with '+' will prevent google from ignoring it.</p>
| -1 | 2010-01-02T02:42:46Z | [
"python",
"append",
"with-statement"
] |
Nesting 'WITH' statements in Python | 1,990,373 | <p>It turns out that "with" is a funny word to search for on the internet.</p>
<p>Does anyone knows what the deal is with nesting with statements in python?<br>
I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this:</p>
<pre><code>with open(file1) as ... | 1 | 2010-01-02T02:18:13Z | 27,551,161 | <p>I found the solution in python's doc. You may want to have a look at <a href="https://docs.python.org/3.4/reference/compound_stmts.html#with" rel="nofollow">this</a></p>
<p>If you are running python 3.1+ you can use it like this:</p>
<pre><code>with open(file1) as fsock1, open(file2, 'a') as fsock2:
fstring1 =... | 2 | 2014-12-18T16:20:45Z | [
"python",
"append",
"with-statement"
] |
Django: signal when user logs in? | 1,990,502 | <p>In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to</p>
<ol>
<li>get notified of a user login/logout</li>
<li>query user login status</li>
</ol>
<p>From my perspective, the ideal solution wo... | 50 | 2010-01-02T03:19:49Z | 1,990,511 | <p>One option might be to wrap Django's login/logout views with your own. For example:</p>
<pre><code>from django.contrib.auth.views import login, logout
def my_login(request, *args, **kwargs):
response = login(request, *args, **kwargs)
#fire a signal, or equivalent
return response
def my_logout(request... | 11 | 2010-01-02T03:25:48Z | [
"python",
"django",
"login",
"user",
"signals"
] |
Django: signal when user logs in? | 1,990,502 | <p>In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to</p>
<ol>
<li>get notified of a user login/logout</li>
<li>query user login status</li>
</ol>
<p>From my perspective, the ideal solution wo... | 50 | 2010-01-02T03:19:49Z | 1,991,497 | <p>Rough idea - you could use middleware for this. This middleware could process requests and fire signal when relevant URL is requested. It could also process responses and fire signal when given action actually succeded.</p>
| 0 | 2010-01-02T12:41:40Z | [
"python",
"django",
"login",
"user",
"signals"
] |
Django: signal when user logs in? | 1,990,502 | <p>In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to</p>
<ol>
<li>get notified of a user login/logout</li>
<li>query user login status</li>
</ol>
<p>From my perspective, the ideal solution wo... | 50 | 2010-01-02T03:19:49Z | 1,991,512 | <p>The only reliable way (that also detects when the user has closed the browser) is to update some <code>last_request</code> field every time the user loads a page.</p>
<p>You could also have a periodic AJAX request that pings the server every x minutes if the user has a page open.</p>
<p>Then have a single backgrou... | 1 | 2010-01-02T12:48:15Z | [
"python",
"django",
"login",
"user",
"signals"
] |
Django: signal when user logs in? | 1,990,502 | <p>In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to</p>
<ol>
<li>get notified of a user login/logout</li>
<li>query user login status</li>
</ol>
<p>From my perspective, the ideal solution wo... | 50 | 2010-01-02T03:19:49Z | 1,995,564 | <p>Inferring logout, as opposed to having them explicitly click a button (which nobody does), means picking an amount of idle time that equates to "logged out". phpMyAdmin uses a default of 15 minutes, some banking sites use as little as 5 minutes.</p>
<p>The simplest way of implementing this would be to change the co... | 1 | 2010-01-03T17:08:18Z | [
"python",
"django",
"login",
"user",
"signals"
] |
Django: signal when user logs in? | 1,990,502 | <p>In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to</p>
<ol>
<li>get notified of a user login/logout</li>
<li>query user login status</li>
</ol>
<p>From my perspective, the ideal solution wo... | 50 | 2010-01-02T03:19:49Z | 6,109,366 | <p>You can use a signal like this (I put mine in models.py)</p>
<pre><code> from django.contrib.auth.signals import user_logged_in
def do_stuff(sender, user, request, **kwargs):
whatever...
user_logged_in.connect(do_stuff)
</code></pre>
<p>See django docs: <a href="https://docs.djangoproject.com/en/dev/... | 98 | 2011-05-24T10:58:50Z | [
"python",
"django",
"login",
"user",
"signals"
] |
How can I schedule a Task to execute at a specific time using celery? | 1,990,531 | <p>I've looked into <code>PeriodicTask</code>, but the examples only cover making it recur. I'm looking for something more like <code>cron</code>'s ability to say "execute this task every Monday at 1 a.m."</p>
| 13 | 2010-01-02T03:37:16Z | 1,990,599 | <p>Use</p>
<pre><code>YourTask.apply_async(args=[some, args, here], eta=when)
</code></pre>
<p>And at the end of your task, reschedule it to the next time it should run.</p>
| 20 | 2010-01-02T04:24:01Z | [
"python",
"django",
"scheduled-tasks",
"celery"
] |
How can I schedule a Task to execute at a specific time using celery? | 1,990,531 | <p>I've looked into <code>PeriodicTask</code>, but the examples only cover making it recur. I'm looking for something more like <code>cron</code>'s ability to say "execute this task every Monday at 1 a.m."</p>
| 13 | 2010-01-02T03:37:16Z | 1,990,623 | <p>How you can read in this <a href="http://celeryproject.org/tutorials/clickcounter.html" rel="nofollow">tutorial</a>, you can make a PeriodicTask, i think if you have execute a task at 1 .am. Monday's morning is because you wan to run a long cpu/mem operation, rememeber celery use ampq for enqueue tasks.</p>
| 0 | 2010-01-02T04:41:43Z | [
"python",
"django",
"scheduled-tasks",
"celery"
] |
How can I schedule a Task to execute at a specific time using celery? | 1,990,531 | <p>I've looked into <code>PeriodicTask</code>, but the examples only cover making it recur. I'm looking for something more like <code>cron</code>'s ability to say "execute this task every Monday at 1 a.m."</p>
| 13 | 2010-01-02T03:37:16Z | 2,116,048 | <p>The recently released version 1.0.3 supports this now, thanks to Patrick Altman!</p>
<p>Example:</p>
<pre><code>from celery.task.schedules import crontab
from celery.decorators import periodic_task
@periodic_task(run_every=crontab(hour=7, minute=30, day_of_week="mon"))
def every_monday_morning():
print("This ... | 19 | 2010-01-22T08:54:04Z | [
"python",
"django",
"scheduled-tasks",
"celery"
] |
How can I schedule a Task to execute at a specific time using celery? | 1,990,531 | <p>I've looked into <code>PeriodicTask</code>, but the examples only cover making it recur. I'm looking for something more like <code>cron</code>'s ability to say "execute this task every Monday at 1 a.m."</p>
| 13 | 2010-01-02T03:37:16Z | 2,830,244 | <p>I have just submitted a patch to add a ScheduledTask to accomplish a small bit of time based scheduling versus period based:</p>
<p><a href="http://github.com/paltman/celery/compare/scheduled-periodic-task" rel="nofollow">http://github.com/paltman/celery/compare/scheduled-periodic-task</a></p>
| 4 | 2010-05-13T20:54:49Z | [
"python",
"django",
"scheduled-tasks",
"celery"
] |
Tkinter help viewer | 1,990,612 | <p>I have a simple Tkinter app in Python. I'd like to add help document to it; what is the simplest way to integrate an help viewer to the app? Preferably cross-platform (although I primarily use Windows)?</p>
<p>I can imagine writing the help in plain HTML.</p>
| 3 | 2010-01-02T04:32:27Z | 1,990,653 | <p>You could stick with writting in html, and then using something like this: <a href="http://www.hwaci.com/sw/tkhtml/" rel="nofollow">Tkhtml</a> which displays html pretty well and is fairly lightweight. :)</p>
<p>And here is <a href="http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py" rel="nofollow">the python ... | 2 | 2010-01-02T05:01:40Z | [
"python",
"tkinter",
"viewer"
] |
Tkinter help viewer | 1,990,612 | <p>I have a simple Tkinter app in Python. I'd like to add help document to it; what is the simplest way to integrate an help viewer to the app? Preferably cross-platform (although I primarily use Windows)?</p>
<p>I can imagine writing the help in plain HTML.</p>
| 3 | 2010-01-02T04:32:27Z | 1,991,128 | <p>Or just launch an external web browser, using the <a href="http://docs.python.org/library/webbrowser.html" rel="nofollow">webbrowser</a> module from the standard library.</p>
<pre><code>import webbrowser
webbrowser.open('/path/to/help/file.html')
</code></pre>
<p>For writing your documentation, have a look at <a h... | 2 | 2010-01-02T09:49:19Z | [
"python",
"tkinter",
"viewer"
] |
How to get Python error as C string? | 1,990,635 | <p>I have a C++ application that embeds the Python interpreter. It calls PyImport_Import to load scripts. I need a way of getting any syntax errors as C strings. For example, if the script uses a undefined function, I would like an error saying something like 'Function xxx is undefined.' How would I do this?</p>
| 0 | 2010-01-02T04:48:20Z | 1,990,667 | <p><a href="http://docs.python.org/c-api/exceptions.html#PyErr_Occurred" rel="nofollow">PyErr_Occurred</a> lets your C code check whether an exception has been raised, and, if so, what type; then, <a href="http://docs.python.org/c-api/exceptions.html#PyErr_Fetch" rel="nofollow">PyErr_Fetch</a> lets you fetch all detail... | 1 | 2010-01-02T05:10:50Z | [
"python",
"string"
] |
Why does this code return 'complex'? | 1,990,759 | <pre><code># Example: provide pickling support for complex numbers.
try:
complex
except NameError:
pass
else:
def pickle_complex(c):
return complex, (c.real, c.imag) # why return complex here?
pickle(complex, pickle_complex, complex)
</code></pre>
<p>Why?<br>
The following code is the pickle... | 1 | 2010-01-02T06:12:36Z | 1,990,785 | <p><code>complex</code> is the class to use to reconstitute the pickled object. It is returned so that it can be pickled along with the real and imag values. Then when the unpickler comes along, it sees the class and some values to use as arguments to its constructor. The unpickler uses the given class and arguments to... | 3 | 2010-01-02T06:30:41Z | [
"python",
"pickle",
"complex-numbers"
] |
Python Hierarchical QcomboBox: clean-up list | 1,990,782 | <p>I have a hierarchical two combo-box. The first combo-box displays a list of customerNames, i.e. different companies from a MySQL db. Each customer has branches in different cities.</p>
<p>Then, when a customer name is chosen from combo-box1 option list, e.g. {Aldi, Meyer, Carrefour, WalMart}, for that particular cu... | 0 | 2010-01-02T06:29:43Z | 1,992,370 | <p>I think you are missing a QComboBox.clear() call , before the 'for loop'. Try the following code (Notice the new line just before id=0)</p>
<pre><code>def loadComboCity(self,customerName):
"""query results cityList into self.mydb.matrix"""
queryName="citylist_thisCustomer"
self.mysqlAPI(queryName,custom... | 1 | 2010-01-02T18:31:51Z | [
"python",
"qt",
"combobox",
"hierarchical-data"
] |
In Python, what does dict.pop(a,b) mean? | 1,990,802 | <pre><code>class a(object):
data={'a':'aaa','b':'bbb','c':'ccc'}
def pop(self, key, *args):
return self.data.pop(key, *args)#what is this mean.
b=a()
print b.pop('a',{'b':'bbb'})
print b.data
</code></pre>
<p><code>self.data.pop(key, *args)</code> ←------ why is there a second argument?</p>
| 38 | 2010-01-02T06:40:52Z | 1,990,812 | <pre><code>def func(*args):
pass
</code></pre>
<p>When you define a function this way, <code>*args</code> will be array of arguments passed to the function. This allows your function to work without knowing ahead of time how many arguments are going to be passed to it. </p>
<p>You do this with keyword arguments ... | 3 | 2010-01-02T06:46:50Z | [
"python",
"dictionary"
] |
In Python, what does dict.pop(a,b) mean? | 1,990,802 | <pre><code>class a(object):
data={'a':'aaa','b':'bbb','c':'ccc'}
def pop(self, key, *args):
return self.data.pop(key, *args)#what is this mean.
b=a()
print b.pop('a',{'b':'bbb'})
print b.data
</code></pre>
<p><code>self.data.pop(key, *args)</code> ←------ why is there a second argument?</p>
| 38 | 2010-01-02T06:40:52Z | 1,990,818 | <p>The <code>pop</code> method of dicts (like <code>self.data</code>, i.e. <code>{'a':'aaa','b':'bbb','c':'ccc'}</code>, here) takes two arguments -- see <a href="http://docs.python.org/library/stdtypes.html?highlight=dict.pop#dict.pop">the docs</a></p>
<p>The second argument, <code>default</code>, is what <code>pop</... | 59 | 2010-01-02T06:49:51Z | [
"python",
"dictionary"
] |
In Python, what does dict.pop(a,b) mean? | 1,990,802 | <pre><code>class a(object):
data={'a':'aaa','b':'bbb','c':'ccc'}
def pop(self, key, *args):
return self.data.pop(key, *args)#what is this mean.
b=a()
print b.pop('a',{'b':'bbb'})
print b.data
</code></pre>
<p><code>self.data.pop(key, *args)</code> ←------ why is there a second argument?</p>
| 38 | 2010-01-02T06:40:52Z | 1,990,821 | <p>So many questions here. I see at least two, maybe three:</p>
<ul>
<li>What does pop(a,b) do?/Why are there a second argument?</li>
<li>What is <code>*args</code> being used for?</li>
</ul>
<hr>
<p>The first question is trivially answered in the <a href="http://docs.python.org/library/stdtypes.html#mapping-types-d... | 13 | 2010-01-02T06:50:50Z | [
"python",
"dictionary"
] |
In Python, what does dict.pop(a,b) mean? | 1,990,802 | <pre><code>class a(object):
data={'a':'aaa','b':'bbb','c':'ccc'}
def pop(self, key, *args):
return self.data.pop(key, *args)#what is this mean.
b=a()
print b.pop('a',{'b':'bbb'})
print b.data
</code></pre>
<p><code>self.data.pop(key, *args)</code> ←------ why is there a second argument?</p>
| 38 | 2010-01-02T06:40:52Z | 1,991,141 | <pre><code>>>> def func(a, *args, **kwargs):
... print 'a %s, args %s, kwargs %s' % (a, args, kwargs)
...
>>> func('one', 'two', 'three', four='four', five='five')
a one, args ('two', 'three'), kwargs {'four': 'four', 'five': 'five'}
</code></pre>
<hr>
<pre><code>>>> def anotherfunct(bet... | 3 | 2010-01-02T09:56:16Z | [
"python",
"dictionary"
] |
Why does my class not have a 'keys' function? | 1,990,850 | <pre><code>class a(object):
w='www'
def __init__(self):
for i in self.keys():
print i
def __iter__(self):
for k in self.keys():
yield k
a() # why is there an error here?
</code></pre>
<p>Thanks.</p>
<hr>
<p>Edit: The following class also doesn't extend an... | -1 | 2010-01-02T07:08:39Z | 1,990,856 | <p>Why would you expect it to have <code>keys</code>? You didn't define such a method in your class. Did you intend to inherit from a dictionary?</p>
<p>To do that declare class <code>a(dict)</code></p>
<p>Or maybe you meant <code>a.__dict__.keys()</code>?</p>
<p>As for the large snippet you've posted in the update,... | 2 | 2010-01-02T07:12:44Z | [
"python",
"inheritance"
] |
Abort HTMLParser processing in Python | 1,990,894 | <p>When using the <code>HTMLParser</code> class in Python, is it possible to abort processing within a <code>handle_*</code> function? Early in the processing, I get all the data I need, so it seems like a waste to continue processing. There's an example below of extracting the meta description for a document.</p>
<pr... | 3 | 2010-01-02T07:37:13Z | 1,990,904 | <p>You can raise an exception and wrap your <code>.feed()</code> call in a try block.</p>
<p>You can also call <code>self.reset()</code> when you decide, that you are done (I have not actually tried it, but according to <a href="http://docs.python.org/library/htmlparser.html#HTMLParser.HTMLParser.reset">documentation<... | 6 | 2010-01-02T07:46:49Z | [
"python",
"html",
"parsing"
] |
Abort HTMLParser processing in Python | 1,990,894 | <p>When using the <code>HTMLParser</code> class in Python, is it possible to abort processing within a <code>handle_*</code> function? Early in the processing, I get all the data I need, so it seems like a waste to continue processing. There's an example below of extracting the meta description for a document.</p>
<pr... | 3 | 2010-01-02T07:37:13Z | 1,993,274 | <p>If you use pyparsing's scanString method, you have more control over how far you actually go through the input string. In your example, we create an expression that matches a <code><meta></code> tag, and add a parse action that ensures that we only match the tag with <code>name="description"</code>. This cod... | 1 | 2010-01-02T23:29:42Z | [
"python",
"html",
"parsing"
] |
Abort HTMLParser processing in Python | 1,990,894 | <p>When using the <code>HTMLParser</code> class in Python, is it possible to abort processing within a <code>handle_*</code> function? Early in the processing, I get all the data I need, so it seems like a waste to continue processing. There's an example below of extracting the meta description for a document.</p>
<pr... | 3 | 2010-01-02T07:37:13Z | 36,976,627 | <p>Extending on @shylent's answer, here's my solution:</p>
<pre><code>class MyParser(HTMLParser):
boolean_flag = False
def handle_starttag(self, tag, attrs):
# for example:
self.boolean_flag = (tag == "sometag" and ("id", "someid") in attrs)
def handle_endtag(self, tag):
pass
... | 0 | 2016-05-02T06:57:48Z | [
"python",
"html",
"parsing"
] |
Convert a curl POST request to Python only using standard libary | 1,990,976 | <p>I would like to convert this curl command to something that I can use in Python for an existing script. </p>
<pre><code>curl -u 7898678:X -H 'Content-Type: application/json' \
-d '{"message":{"body":"TEXT"}}' http://sample.com/36576/speak.json
</code></pre>
<p>TEXT is what i would like to replace with a message ge... | 20 | 2010-01-02T08:27:23Z | 1,990,995 | <p>Take a look at pycurl <a href="http://pycurl.sourceforge.net/" rel="nofollow">http://pycurl.sourceforge.net/</a></p>
| 1 | 2010-01-02T08:35:36Z | [
"python",
"json",
"curl"
] |
Convert a curl POST request to Python only using standard libary | 1,990,976 | <p>I would like to convert this curl command to something that I can use in Python for an existing script. </p>
<pre><code>curl -u 7898678:X -H 'Content-Type: application/json' \
-d '{"message":{"body":"TEXT"}}' http://sample.com/36576/speak.json
</code></pre>
<p>TEXT is what i would like to replace with a message ge... | 20 | 2010-01-02T08:27:23Z | 1,991,001 | <blockquote>
<p>I would like this to work with the standard library if possible.</p>
</blockquote>
<p>The standard library provides <a href="http://docs.python.org/library/urllib.html"><strong><code>urllib</code></strong></a> and <strong><a href="http://docs.python.org/library/httplib.html"><code>httplib</code></a><... | 23 | 2010-01-02T08:37:16Z | [
"python",
"json",
"curl"
] |
Convert a curl POST request to Python only using standard libary | 1,990,976 | <p>I would like to convert this curl command to something that I can use in Python for an existing script. </p>
<pre><code>curl -u 7898678:X -H 'Content-Type: application/json' \
-d '{"message":{"body":"TEXT"}}' http://sample.com/36576/speak.json
</code></pre>
<p>TEXT is what i would like to replace with a message ge... | 20 | 2010-01-02T08:27:23Z | 1,992,894 | <p>While there are ways to handle <a href="http://www.voidspace.org.uk/python/articles/authentication.shtml">authentication in urllib2</a>, if you're doing Basic Authorization (which means effectively sending the username and password in clear text) then you can do all of what you want with a urllib2.Request and urllib... | 12 | 2010-01-02T21:19:03Z | [
"python",
"json",
"curl"
] |
Convert a curl POST request to Python only using standard libary | 1,990,976 | <p>I would like to convert this curl command to something that I can use in Python for an existing script. </p>
<pre><code>curl -u 7898678:X -H 'Content-Type: application/json' \
-d '{"message":{"body":"TEXT"}}' http://sample.com/36576/speak.json
</code></pre>
<p>TEXT is what i would like to replace with a message ge... | 20 | 2010-01-02T08:27:23Z | 2,003,832 | <p>Thanks every</p>
<p>this works</p>
<pre><code>import urllib2
def speak(status):
def basic_authorization(user, password):
s = user + ":" + password
return "Basic " + s.encode("base64").rstrip()
req = urllib2.Request("http://example.com/60/speak.json",
headers = {
... | 2 | 2010-01-05T02:38:14Z | [
"python",
"json",
"curl"
] |
Sorting problem with the Google App Engine | 1,991,022 | <p>I am using the following class to store some data:</p>
<pre><code>class NewsArticle(db.Model):
score = db.FloatProperty(default=0.0)
date_scored = db.DateTimeProperty()
...
</code></pre>
<p>What I need to do is to get those NewsArticle entities that have the top score in some time frame (e.g. get the t... | 1 | 2010-01-02T08:54:08Z | 1,991,035 | <p>Try this:</p>
<pre><code>import datetime
...
query = Data.gql('SELECT * FROM NewsArticle WHERE date_created >= :today ORDER BY score DESC', today=datetime.date.today())
</code></pre>
| 0 | 2010-01-02T08:59:43Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Sorting problem with the Google App Engine | 1,991,022 | <p>I am using the following class to store some data:</p>
<pre><code>class NewsArticle(db.Model):
score = db.FloatProperty(default=0.0)
date_scored = db.DateTimeProperty()
...
</code></pre>
<p>What I need to do is to get those NewsArticle entities that have the top score in some time frame (e.g. get the t... | 1 | 2010-01-02T08:54:08Z | 1,991,047 | <p>You could either:</p>
<ol>
<li><p>filter only by the timeframe and sort by score in memory or, </p></li>
<li><p>if you can limit the timeframes to whole days and weeks, include additional properties in your model to save the the week as a integer and the day as a <code>DateProperty</code> and do a simple equality c... | 5 | 2010-01-02T09:04:53Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Sorting problem with the Google App Engine | 1,991,022 | <p>I am using the following class to store some data:</p>
<pre><code>class NewsArticle(db.Model):
score = db.FloatProperty(default=0.0)
date_scored = db.DateTimeProperty()
...
</code></pre>
<p>What I need to do is to get those NewsArticle entities that have the top score in some time frame (e.g. get the t... | 1 | 2010-01-02T08:54:08Z | 1,991,080 | <p>I think ordering by multiple properties might work. Simply use the first inequality property as the first ordering property.</p>
<pre><code>query = db.GqlQuery('SELECT * FROM NewsArticle WHERE date_created > DATETIME(:year, :month, :day, 0, 0, 0) ORDER BY date_created, score DESC', year=date.selected_year, month... | -1 | 2010-01-02T09:22:12Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Sorting problem with the Google App Engine | 1,991,022 | <p>I am using the following class to store some data:</p>
<pre><code>class NewsArticle(db.Model):
score = db.FloatProperty(default=0.0)
date_scored = db.DateTimeProperty()
...
</code></pre>
<p>What I need to do is to get those NewsArticle entities that have the top score in some time frame (e.g. get the t... | 1 | 2010-01-02T08:54:08Z | 1,992,055 | <blockquote>
<p>I am expecting a really large number
of results so in-memory-sorting won't
be efficient.</p>
</blockquote>
<p>You can get at most 1000 results from a query, so sorting them every which way will be <strong>extremely</strong> efficient -- e.g., consider, on my Macbook Air (first-day, slowest model)... | 1 | 2010-01-02T16:34:18Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Role of C,C++,python,perl in Web development | 1,991,065 | <p>Please bear with me experts i'm a newbie in web dev.</p>
<p>With html,css can take care of webpages..
javascript,ajax for some dynamic content..
php for server side scripting,accessing databases,sending emails,doing all other stuf...</p>
<p>What role do these programming languages play?
Can they do any other impor... | 0 | 2010-01-02T09:14:08Z | 1,991,076 | <p>All languages can all do basically any task any other one of them can do, as they are all Turing complete.</p>
<p>PHP works as a server-side scripting language, but you can also use Perl, Python, Ruby, Haskell, Lisp, Java, C, C++, assembly, or pretty much any other language that can access standard input and standa... | 10 | 2010-01-02T09:21:47Z | [
"c++",
"python",
"c",
"perl"
] |
Role of C,C++,python,perl in Web development | 1,991,065 | <p>Please bear with me experts i'm a newbie in web dev.</p>
<p>With html,css can take care of webpages..
javascript,ajax for some dynamic content..
php for server side scripting,accessing databases,sending emails,doing all other stuf...</p>
<p>What role do these programming languages play?
Can they do any other impor... | 0 | 2010-01-02T09:14:08Z | 1,991,087 | <p>The <em>language</em> is where the actual logic of your application resides. </p>
<p>Perl, Python, Ruby etc. are all server side scripting languages (although their implementations and deployment methods are quite different). </p>
<p>As for "Can they do any other important task which cannot be done by PHP?", not r... | 5 | 2010-01-02T09:24:32Z | [
"c++",
"python",
"c",
"perl"
] |
Role of C,C++,python,perl in Web development | 1,991,065 | <p>Please bear with me experts i'm a newbie in web dev.</p>
<p>With html,css can take care of webpages..
javascript,ajax for some dynamic content..
php for server side scripting,accessing databases,sending emails,doing all other stuf...</p>
<p>What role do these programming languages play?
Can they do any other impor... | 0 | 2010-01-02T09:14:08Z | 1,991,102 | <p>Another difference between your language choice is speed. An app written in C is going to run faster and require less system resources in general then a higher level scripting language. In a small scale app, you'd never notice. If your site is the next facebook, you will.</p>
<p>Here's a good example of a choice of... | 4 | 2010-01-02T09:31:47Z | [
"c++",
"python",
"c",
"perl"
] |
Role of C,C++,python,perl in Web development | 1,991,065 | <p>Please bear with me experts i'm a newbie in web dev.</p>
<p>With html,css can take care of webpages..
javascript,ajax for some dynamic content..
php for server side scripting,accessing databases,sending emails,doing all other stuf...</p>
<p>What role do these programming languages play?
Can they do any other impor... | 0 | 2010-01-02T09:14:08Z | 1,991,108 | <p>If you'd like to understand how all of these different programming languages can be used for server-side scripting, <a href="http://www.jmarshall.com/easy/cgi/" rel="nofollow">read up on CGI</a>.</p>
| 3 | 2010-01-02T09:34:33Z | [
"c++",
"python",
"c",
"perl"
] |
A Python script I've written for correcting table names of the SQL dumps from Windows. Any comments? | 1,991,117 | <p>as a newbie in Python I've thought about writing a quick and dirty script for correcting the table anme caps of a MySQL dump file (by phpMyAdmin).</p>
<p>The idea is since the correct capitalization of the table names are in the comments, I'm going to use it.</p>
<p>e.g.:</p>
<pre><code>-- -----------------------... | 0 | 2010-01-02T09:41:19Z | 1,991,207 | <p>Looks fairly good, so the following are relatively minor:</p>
<ul>
<li>get_text_blocks basically splits the entire text by the separator, correct? If so, I think this can be done with a single regex with a re.MULTILINE flag. Something like r'(.*?)\n-- -+' (warning: untested).</li>
<li>If you don't want to use a sin... | 1 | 2010-01-02T10:34:20Z | [
"python"
] |
Accessing samba shares with gio in python | 1,991,206 | <p>I am trying to make a simple command line client for accessing shares via the Python bindings of gio (yes, the main requirement is to use gio).</p>
<p>I can see that comparing with it's predecessor gnome-vfs, it provides some means to do authentication stuff (subclassing <code>MountOperation</code>), and even some ... | 2 | 2010-01-02T10:34:12Z | 2,051,628 | <p>The following appears to be the minimum code needed to mount a volume:</p>
<pre><code>def mount(f):
op = gio.MountOperation()
op.connect('ask-password', ask_password_cb)
f.mount_enclosing_volume(op, mount_done_cb)
def ask_password_cb(op, message, default_user, default_domain, flags):
op.set_usernam... | 4 | 2010-01-12T19:12:26Z | [
"python",
"authentication",
"gnome",
"samba",
"gio"
] |
Reading from an SSL Socket in Twisted | 1,991,399 | <p>I'm trying to implement an SSL client in Twisted that simply must connect to a socket and read binary data (specifically, tuples of data). I've gotten the code to a point where it seems to connect and disconnect successfully but no data is <em>ever</em> read from the socket. </p>
<pre><code>class FeedbackHandler(Li... | 3 | 2010-01-02T11:53:24Z | 1,997,062 | <p>Take a look at ssldump or wireshark. Since you're not seeing any data delivered at this level, you should drop down a level to one of these tools. One of them might reveal an SSL negotiation error, or that the server never sends any bytes, or something else that's hard to guess based just on what you've discovered... | 2 | 2010-01-04T01:21:33Z | [
"python",
"sockets",
"openssl",
"twisted"
] |
python appengine form-posted utf8 file issue | 1,991,658 | <p>i am trying to form-post a sql file that consists on many INSERTS, eg.</p>
<pre><code>INSERT INTO `TABLE` VALUES ('abcdé', 2759);
</code></pre>
<p>then i use re.search to parse it and extract the fields to put into my own datastore. The problem is that, although the file contains accented characters (see the e is... | 0 | 2010-01-02T14:01:11Z | 1,992,081 | <p>You mention <code>utf8</code> in the Q's title but then never again: what are you doing (in terms of setting headers and checking them) to verify what encoding is in use? There should be headers of the form</p>
<pre><code>Content-Type: text/plain; charset=utf-8
</code></pre>
<p>and the <code>charset=</code> part ... | 1 | 2010-01-02T16:44:24Z | [
"python",
"google-app-engine",
"forms",
"utf-8"
] |
How does Django + mod_wsgi affect the python path? | 1,991,743 | <p>I have a simple setup with my python libraries in /domains/somedomain.com/libs/ and all my tests run fine. I start WSGI with DJANGO_SETTINGS_MODULE to "somedomain.settings" where somedomain is a package in libs/</p>
<p>Suddenly, when adding pywapi.py into libs/ I can't import it when hitting the site. But, if I add... | 1 | 2010-01-02T14:29:42Z | 1,991,778 | <p>I think the problem is related with the permissions of that file. Check that the user running wsgi (apache user, usually) is capable of reading and writing the everything in the libs folder and specially capable of reading the file pywapi.py.</p>
| 2 | 2010-01-02T14:41:40Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
python import module to work globally | 1,991,784 | <p>I've got a problem trying to get python to accept an import 'globally'</p>
<p>In a module it needs to import another module depending on another variable but it doesn't seem to import it into all of the module functions if i have it in the start function; for example:</p>
<pre><code>def start():
selected = "we... | 0 | 2010-01-02T14:42:33Z | 1,991,794 | <p>You can provide scope of <a href="http://docs.python.org/reference/simple_stmts.html#grammar-token-exec_stmt" rel="nofollow"><code>exec</code></a> with <code>in</code>. Try this:</p>
<pre><code>exec("from gui import " + selected + " as ui") in globals()
</code></pre>
| 0 | 2010-01-02T14:46:29Z | [
"python",
"import",
"module"
] |
python import module to work globally | 1,991,784 | <p>I've got a problem trying to get python to accept an import 'globally'</p>
<p>In a module it needs to import another module depending on another variable but it doesn't seem to import it into all of the module functions if i have it in the start function; for example:</p>
<pre><code>def start():
selected = "we... | 0 | 2010-01-02T14:42:33Z | 1,991,809 | <p>You are importing the ui module to the start() function scope only. You should import the module to global scope. To do this you could import the module before the two functions (start and close) or provide global scope to exec() function.</p>
<p>Example: To provide global scope to the exec method.</p>
<pre><code>... | 0 | 2010-01-02T14:50:46Z | [
"python",
"import",
"module"
] |
python import module to work globally | 1,991,784 | <p>I've got a problem trying to get python to accept an import 'globally'</p>
<p>In a module it needs to import another module depending on another variable but it doesn't seem to import it into all of the module functions if i have it in the start function; for example:</p>
<pre><code>def start():
selected = "we... | 0 | 2010-01-02T14:42:33Z | 1,991,879 | <p>Why do you want to do it this way? Why not use the <code>__import__</code> builtin? Also, your binding to <code>gui</code> is local to the function <code>start</code>.</p>
| 2 | 2010-01-02T15:20:37Z | [
"python",
"import",
"module"
] |
python import module to work globally | 1,991,784 | <p>I've got a problem trying to get python to accept an import 'globally'</p>
<p>In a module it needs to import another module depending on another variable but it doesn't seem to import it into all of the module functions if i have it in the start function; for example:</p>
<pre><code>def start():
selected = "we... | 0 | 2010-01-02T14:42:33Z | 1,992,020 | <pre><code>import gui
ui = None
def start():
selected = "web"
log("going to start gui " + selected)
global ui
__import__("gui.%s" % selected) # if you're importing a submodule that
# may not have been imported yet
ui = getattr(gui, selected)
ui.start()
</code></pre>
| 8 | 2010-01-02T16:19:03Z | [
"python",
"import",
"module"
] |
Why file writing does not happen when it is suppose to happen in the program flow? | 1,991,815 | <p>This is not a new problem for me. From C to PERL to Python on Windows Mobile, Windows XP and other Windows versions this problem persists and f**ks my nerves.</p>
<p>Now in my latest script it again happens.
To be more concrete: I have coded in Python a trivial script. Now the script writes correctly to the file w... | 2 | 2010-01-02T14:53:42Z | 1,991,819 | <p>Remember what your mom taught you:</p>
<p>always flush()</p>
<p>(in python, <code>file_object.flush()</code> followed by <code>os.fsync(file_object.fileno())</code>)</p>
| 8 | 2010-01-02T14:55:33Z | [
"python"
] |
Why file writing does not happen when it is suppose to happen in the program flow? | 1,991,815 | <p>This is not a new problem for me. From C to PERL to Python on Windows Mobile, Windows XP and other Windows versions this problem persists and f**ks my nerves.</p>
<p>Now in my latest script it again happens.
To be more concrete: I have coded in Python a trivial script. Now the script writes correctly to the file w... | 2 | 2010-01-02T14:53:42Z | 1,991,823 | <p>If you have opened the file with a file handle in Python, remember to close it when finished.
eg</p>
<pre><code>f=open("file")
....
f.write(....)
f.close()
</code></pre>
| 0 | 2010-01-02T14:57:21Z | [
"python"
] |
Why file writing does not happen when it is suppose to happen in the program flow? | 1,991,815 | <p>This is not a new problem for me. From C to PERL to Python on Windows Mobile, Windows XP and other Windows versions this problem persists and f**ks my nerves.</p>
<p>Now in my latest script it again happens.
To be more concrete: I have coded in Python a trivial script. Now the script writes correctly to the file w... | 2 | 2010-01-02T14:53:42Z | 1,991,832 | <p>Obviously, you forget to close the file upon finishing working with it. If you want to check the contents of the file before closing it, call the <code>flush()</code> method. Example:</p>
<pre><code>file = open("hello.txt", "a")
file.write(...)
file.flush() // force write on the disk
file.close() // finis... | 0 | 2010-01-02T15:01:43Z | [
"python"
] |
Why file writing does not happen when it is suppose to happen in the program flow? | 1,991,815 | <p>This is not a new problem for me. From C to PERL to Python on Windows Mobile, Windows XP and other Windows versions this problem persists and f**ks my nerves.</p>
<p>Now in my latest script it again happens.
To be more concrete: I have coded in Python a trivial script. Now the script writes correctly to the file w... | 2 | 2010-01-02T14:53:42Z | 1,991,915 | <p>Regarding the code:
It looks like the actual problem is one relating to threads, not to files:</p>
<p>Whilst you are executing this code:</p>
<pre><code> for t in list:
fileo.write(t + "\n")
list = []
fileo.close()
fileo = open(OutFile, 'a')
k = 0
</code></pre>
<p><code>list</code> is b... | 2 | 2010-01-02T15:34:38Z | [
"python"
] |
Why file writing does not happen when it is suppose to happen in the program flow? | 1,991,815 | <p>This is not a new problem for me. From C to PERL to Python on Windows Mobile, Windows XP and other Windows versions this problem persists and f**ks my nerves.</p>
<p>Now in my latest script it again happens.
To be more concrete: I have coded in Python a trivial script. Now the script writes correctly to the file w... | 2 | 2010-01-02T14:53:42Z | 1,991,964 | <pre><code>
import httplib2
import thread
import os
import sys
ht = httplib2.Http();
def check(proxy, port, OutFile):
global list
try:
head = ht.request(proxy, 'HEAD')
except:
return
fileo = open(OutFile, 'a')
fileo.write(proxy+"\n")
fileo.write(port+"\n")
sys.stdout.flush(... | 1 | 2010-01-02T15:57:06Z | [
"python"
] |
Parse xml file while a tag is missing | 1,991,840 | <p>I try to parse an xml file. The text which is in tags is parsed successfully (or it seems so) but I want to output as the text which is not contained in some tags and the following program just ignores it.</p>
<pre><code>from xml.etree.ElementTree import XMLTreeBuilder
class HtmlLatex: # The ta... | 0 | 2010-01-02T15:05:19Z | 1,991,866 | <p>Have a look at <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>, a python library for parsing, navigating and manipulating html and xml. It has a handy interface and might solve your problem ...</p>
| 3 | 2010-01-02T15:16:09Z | [
"python",
"html",
"xml",
"parsing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.