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
listlengths
1
5
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
15,769,548
<p>I think the proper way to use **kwargs in Python when it comes to default values is to use the dictionary method setdefault, as given below:</p> <pre><code>class ExampleClass: def __init__(self, **kwargs): kwargs.setdefault('val', value1) kwargs.setdefault('val2', value2) </code></pre> <p>In this way, if a...
5
2013-04-02T16:39:14Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
36,336,431
<p>Following up on <a href="http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python/13629607#13629607">@srhegde</a> suggestion of using <a href="https://docs.python.org/2/reference/datamodel.html#object.__setattr__"><strong>setattr</strong></a>:</p> <pre><code>class ExampleClass(object): __ac...
5
2016-03-31T14:34:37Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
37,369,859
<p>@AbhinavGupta and @Steef suggested using <code>update()</code>, which I found very helpful for processing large argument lists:</p> <pre><code>args.update(kwargs) </code></pre> <p>What if we want to check that the user hasn't passed any spurious/unsupported arguments? @VinaySajip pointed out that <code>pop()</code...
1
2016-05-22T02:08:18Z
[ "python", "kwargs" ]
Extract only numbers from data in Jython
1,098,613
<p>Here is my problem. I'm working on a Jython program and I have to extract numbers from a PyJavaInstance:</p> <p>[{string1="foo", xxx1, xxx2, ..., xxxN, string2="bar"}]</p> <p>(where xxx are the floating point numbers).</p> <p>My question is how can I extract the numbers and put them in a more simple structure lik...
0
2009-07-08T14:56:48Z
1,098,642
<p>can you iterate and check whether an item is float? The method you're looking for is <a href="http://docs.python.org/library/functions.html?highlight=isinstance#isinstance" rel="nofollow"><code>isinstance</code></a>. I hope it's implemented in Jython.</p>
1
2009-07-08T15:03:43Z
[ "python", "list", "jython", "extract" ]
Extract only numbers from data in Jython
1,098,613
<p>Here is my problem. I'm working on a Jython program and I have to extract numbers from a PyJavaInstance:</p> <p>[{string1="foo", xxx1, xxx2, ..., xxxN, string2="bar"}]</p> <p>(where xxx are the floating point numbers).</p> <p>My question is how can I extract the numbers and put them in a more simple structure lik...
0
2009-07-08T14:56:48Z
1,098,657
<p>A <code>PyJavaInstance</code> is a Jython wrapper around a Java instance; how you extract numbers from it depends on what it is. If you need to get a bunch of stuff - some of which are strings and some of which are floats, then:</p> <pre><code>float_list = [] for item in instance_properties: try: float_...
2
2009-07-08T15:06:37Z
[ "python", "list", "jython", "extract" ]
Extract only numbers from data in Jython
1,098,613
<p>Here is my problem. I'm working on a Jython program and I have to extract numbers from a PyJavaInstance:</p> <p>[{string1="foo", xxx1, xxx2, ..., xxxN, string2="bar"}]</p> <p>(where xxx are the floating point numbers).</p> <p>My question is how can I extract the numbers and put them in a more simple structure lik...
0
2009-07-08T14:56:48Z
1,098,769
<p>Thank you Vinay. It's also the kind of solution I've just found:</p> <pre><code> new_inst=[] for element in instance: try: float(element) new_inst.append(float(element)) except ValueError: del(element) </code></pre> <p>@SilentGhost: Good suggestion. The issue was to find what method could de...
0
2009-07-08T15:20:49Z
[ "python", "list", "jython", "extract" ]
IndexError: list index out of range and python
1,098,643
<p>I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?</p>
8
2009-07-08T15:03:55Z
1,098,658
<p>yes. sequence doesn't have the 54th item.</p>
3
2009-07-08T15:07:00Z
[ "python", "indexoutofboundsexception" ]
IndexError: list index out of range and python
1,098,643
<p>I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?</p>
8
2009-07-08T15:03:55Z
1,098,660
<p>If you have a list with 53 items, the last one is <code>thelist[52]</code> because indexing start at 0.</p>
16
2009-07-08T15:07:15Z
[ "python", "indexoutofboundsexception" ]
IndexError: list index out of range and python
1,098,643
<p>I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?</p>
8
2009-07-08T15:03:55Z
1,098,670
<p>That's right. 'list index out of range' most likely means you are referring to <code>n-th</code> element of the list, while the length of the list is smaller than <code>n</code>.</p>
1
2009-07-08T15:08:10Z
[ "python", "indexoutofboundsexception" ]
IndexError: list index out of range and python
1,098,643
<p>I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?</p>
8
2009-07-08T15:03:55Z
1,098,675
<p>Yes,</p> <p>You are trying to access an element of the list that does not exist.</p> <pre><code>MyList = ["item1", "item2"] print MyList[0] # Will work print MyList[1] # Will Work print MyList[2] # Will crash. </code></pre> <p>Have you got an off-by-one error?</p>
10
2009-07-08T15:08:32Z
[ "python", "indexoutofboundsexception" ]
IndexError: list index out of range and python
1,098,643
<p>I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?</p>
8
2009-07-08T15:03:55Z
37,785,115
<p>Always keep in mind when you want to overcome this error, the default value of indexing and range starts from 0, so if total items is 100 then l[99] and range(99) will give you access up to the last element.</p> <p>whenever you get this type of error please cross check with items that comes between/middle in range,...
0
2016-06-13T08:34:53Z
[ "python", "indexoutofboundsexception" ]
Help me lambda-nize this
1,098,841
<p>To help me better understand lambda I wrote this short snippet that rotates and transforms a quad (I hope I got the math right). Now, I want to replace the three steps below with one liner lambdas, possibly in conjunction with map().</p> <p>Im using a <a href="http://www.pygame.org/wiki/2DVectorClass?parent=CookBoo...
3
2009-07-08T15:31:04Z
1,098,882
<p>You could use <code>map</code>, <code>reduce</code>, et al, but nowadays list comprehensions are the preferred way to do things in Python:</p> <pre><code>rot_points = (i.rotated(self.orientation.get_angle()) for i in points) real_points = [self.pos+i*self.scale for i in rot_points] </code></pre> <p>Notice how I u...
8
2009-07-08T15:37:39Z
[ "python", "lambda" ]
Help me lambda-nize this
1,098,841
<p>To help me better understand lambda I wrote this short snippet that rotates and transforms a quad (I hope I got the math right). Now, I want to replace the three steps below with one liner lambdas, possibly in conjunction with map().</p> <p>Im using a <a href="http://www.pygame.org/wiki/2DVectorClass?parent=CookBoo...
3
2009-07-08T15:31:04Z
1,098,984
<p>Note that you're unnecessarily calling <code>get_angle()</code> for each point, when really it's constant over the life of the loop. </p> <p>I'd try this:</p> <pre><code>angle = self.orientation.get_angle() real_points = [self.pos+point.rotated(angle)*self.scale for point in points] </code></pre> <p>I don't thin...
0
2009-07-08T15:56:08Z
[ "python", "lambda" ]
for statement and i.find in list
1,098,970
<pre><code>for a in ('90','52.6', '26.5'): if a == '90': z = (' 0',) elif a == '52.6': z = ('0', '5') else: z = ('25') for b in z: cmd = exepath + ' -a ' + str(a) + ' -b ' + str(b) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstri...
-2
2009-07-08T15:53:59Z
1,098,985
<p>you are missing quotes around you first for statement try</p> <pre><code>for a in ('90','52.6', '26.5'): </code></pre>
6
2009-07-08T15:56:14Z
[ "python" ]
for statement and i.find in list
1,098,970
<pre><code>for a in ('90','52.6', '26.5'): if a == '90': z = (' 0',) elif a == '52.6': z = ('0', '5') else: z = ('25') for b in z: cmd = exepath + ' -a ' + str(a) + ' -b ' + str(b) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstri...
-2
2009-07-08T15:53:59Z
1,099,481
<p>Once you've fixed the missing quote, you'll get weird behavior from this part:</p> <pre><code>else: z = ('25') for b in z: </code></pre> <p>the parentheses here do nothing at all, and b in the loop will be '2' then '5'. You probably mean to use, instead:</p> <pre><code> z = ('25',) </code></pre> <p>which...
1
2009-07-08T17:32:57Z
[ "python" ]
for statement and i.find in list
1,098,970
<pre><code>for a in ('90','52.6', '26.5'): if a == '90': z = (' 0',) elif a == '52.6': z = ('0', '5') else: z = ('25') for b in z: cmd = exepath + ' -a ' + str(a) + ' -b ' + str(b) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstri...
-2
2009-07-08T15:53:59Z
1,100,578
<p>Looking at your code it will only actually output something if the <code>i.find('The student says')</code> successfully matches so you could either run this in a debugger or add some print statements to see what is in <code>outputstring</code> for each time round the loop.</p>
1
2009-07-08T21:17:10Z
[ "python" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
1,099,197
<p>I'd recommend removing the nesting from the regex itself, looping through the results and performing regexes on that.</p>
1
2009-07-08T16:34:13Z
[ "python", "regex", "recursive-regex" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
1,099,215
<p>Python doesn't support recursion in regular expressions. So equivalents to .NET's balancing groups or PCRE regex in Perl are not immediately possible in Python.</p> <p>Like you said yourself: this is NOT a problem you should really be solving with a single regex.</p>
2
2009-07-08T16:38:07Z
[ "python", "regex", "recursive-regex" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
1,099,316
<p>Are you talking about recursion? It's not clear from your question. An example:</p> <pre><code>ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. &gt;&g...
0
2009-07-08T16:57:31Z
[ "python", "regex", "recursive-regex" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
1,101,030
<p>Regular expressions <em>cannot</em> parse nested structures. Nested structures are not regular, by definition. They cannot be constructed by a regular grammar, and they cannot be parsed by a finite state automaton (a regular expression can be seen as a shorthand notation for an FSA).</p> <p>Today's "regex" engine...
20
2009-07-08T23:10:34Z
[ "python", "regex", "recursive-regex" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
1,101,046
<p>You can't do this generally using Python regular expressions. (.NET regular expressions have been extended with "balancing groups" which is what allows nested matches.)</p> <p>However, PyParsing is a very nice package for this type of thing:</p> <pre><code>from pyparsing import nestedExpr data = "( (a ( ( c ) b ...
15
2009-07-08T23:14:09Z
[ "python", "regex", "recursive-regex" ]
Matching Nested Structures With Regular Expressions in Python
1,099,178
<p>I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "<code>( (a ( ( c ) b ) ) ( d ) e )</code>". </p> <p>What is the python equivalent of this feature? Can this be achieved using regular expressions with some ...
14
2009-07-08T16:30:38Z
14,715,850
<p><strong>Edit:</strong> <a href="http://stackoverflow.com/a/17141899/190597">falsetru's nested parser</a>, which I've slightly modified to accept arbitrary regex patterns to specify delimiters and item separators, is faster and simpler than my original <code>re.Scanner</code> solution:</p> <pre><code>import re def ...
13
2013-02-05T19:56:12Z
[ "python", "regex", "recursive-regex" ]
Replacing variable with function/class indicating dynamic value
1,099,328
<p>In my program, I draw some quads. I want to add the functionality for them to scale up, then down, then go back to being static (to draw attention). In the quads I have:</p> <pre><code>self.scale = 10 </code></pre> <p>Making scale change according to sin would be nice. But adding frequency, amplitude and logic to ...
2
2009-07-08T17:00:06Z
1,099,347
<p>It's sort of like <a href="http://en.wikipedia.org/wiki/Lazy%5Fevaluation" rel="nofollow">lazy-evaluation</a>. It is definitely a valid tecnique when used properly, but I don't think this is the right place to use it. It makes the code kind of confusing.</p>
0
2009-07-08T17:04:43Z
[ "python" ]
Replacing variable with function/class indicating dynamic value
1,099,328
<p>In my program, I draw some quads. I want to add the functionality for them to scale up, then down, then go back to being static (to draw attention). In the quads I have:</p> <pre><code>self.scale = 10 </code></pre> <p>Making scale change according to sin would be nice. But adding frequency, amplitude and logic to ...
2
2009-07-08T17:00:06Z
1,099,382
<p>It sure is a valid technique, but a name? Having an object.value() instead of an int? Uhm. Object orientation? :)</p> <p>If the methods that use this value requires an integer, and won't call any method on it, you could in fact create your own integer class, that behaves exactly like an integer, but changes the val...
0
2009-07-08T17:13:42Z
[ "python" ]
Replacing variable with function/class indicating dynamic value
1,099,328
<p>In my program, I draw some quads. I want to add the functionality for them to scale up, then down, then go back to being static (to draw attention). In the quads I have:</p> <pre><code>self.scale = 10 </code></pre> <p>Making scale change according to sin would be nice. But adding frequency, amplitude and logic to ...
2
2009-07-08T17:00:06Z
1,099,392
<p>The distinction between</p> <pre><code>quad.scale= 10 </code></pre> <p>and</p> <pre><code>quad.scale= MySin() </code></pre> <p>Is minor. Within the <code>Quad</code> class definition the "scale" attribute can be a property with proper getter and setter functions.</p> <pre><code>class Quad( object ): @prope...
4
2009-07-08T17:15:04Z
[ "python" ]
Replacing variable with function/class indicating dynamic value
1,099,328
<p>In my program, I draw some quads. I want to add the functionality for them to scale up, then down, then go back to being static (to draw attention). In the quads I have:</p> <pre><code>self.scale = 10 </code></pre> <p>Making scale change according to sin would be nice. But adding frequency, amplitude and logic to ...
2
2009-07-08T17:00:06Z
1,099,414
<p>It sounds like you want your quads to be dumb, and to have an animator class which is smart. So,here are some suggestions:</p> <ol> <li>Give the quads an attribute which indicates how to animate them (in addition to the <code>scale</code> and whatever else).</li> <li>In an <code>Animator</code> class, on a frame up...
1
2009-07-08T17:18:41Z
[ "python" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
1,100,016
<p><code>sys.path</code> is only searched for Python modules. For dynamic linked libraries, the paths searched must be in <code>LD_LIBRARY_PATH</code>. Check if your <code>LD_LIBRARY_PATH</code> includes <code>/usr/local/lib</code>, and if it doesn't, add it and try again.</p> <p>Some more information (<a href="http:/...
97
2009-07-08T19:12:33Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
1,100,297
<p>Ensure your libcurl.so module is in the system library path, which is distinct and separate from the python library path.</p> <p>A "quick fix" is to add this path to a LD_LIBRARY_PATH variable. However, setting that system wide (or even account wide) is a BAD IDEA, as it is possible to set it in such a way that som...
41
2009-07-08T20:13:10Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
1,109,196
<p>You can also set LD_RUN_PATH to /usr/local/lib in your user environment when you compile pycurl in the first place. This will embed /usr/local/lib in the RPATH attribute of the C extension module .so so that it automatically knows where to find the library at run time without having to have LD_LIBRARY_PATH set at ru...
19
2009-07-10T12:17:02Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
2,384,146
<p>Had the exact same issue. I installed curl 7.19 to /opt/curl/ to make sure that I would not affect current curl on our production servers. Once I linked libcurl.so.4 to /usr/lib:</p> <p>sudo ln -s /opt/curl/lib/libcurl.so /usr/lib/libcurl.so.4</p> <p>I still got the same error! Durf.</p> <p>But running ldconfig ...
8
2010-03-05T02:18:08Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
10,986,298
<p>As a supplement to above answers - I'm just bumping into a similar problem, and working completely of the default installed python. </p> <p>When I call the example of the shared object library I'm looking for with <code>LD_LIBRARY_PATH</code>, I get something like this: </p> <pre><code>$ LD_LIBRARY_PATH=/path/to/m...
6
2012-06-11T19:26:55Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
Why can't Python find shared objects that are in directories in sys.path?
1,099,981
<p>I'm trying to import pycurl:</p> <pre><code>$ python -c "import pycurl" Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; ImportError: libcurl.so.4: cannot open shared object file: No such file or directory </code></pre> <p>Now, libcurl.so.4 is in /usr/local/lib. As you can see, t...
72
2009-07-08T19:06:17Z
36,791,034
<p>I use <code>python setup.py build_ext -R/usr/local/lib -I/usr/local/include/libcalg-1.0</code> and the compiled .so file is under the build folder. you can type <code>python setup.py --help build_ext</code> to see the explanations of -R and -I</p>
0
2016-04-22T10:16:21Z
[ "python", "shared-libraries", "libcurl", "pycurl" ]
how to fix or make an exception for this error
1,100,029
<p>I'm creating a code that gets image's urls from any web pages, the code are in python and use BeutifulSoup and httplib2. When I run the code, I get the next error:</p> <pre><code>Look me http://movies.nytimes.com (this line is printed by the code) Traceback (most recent call last): File "main.py", line 103...
1
2009-07-08T19:15:58Z
1,100,047
<p>To catch that error specifically, change your code to look like this:</p> <pre><code>try: iSoupList = BeautifulSoup(response, parseOnlyThese=SoupStrainer('img')) except HTMLParseError: #Do something intelligent here </code></pre> <p>Here's some more reading on Python's try except blocks: <a href="http://d...
2
2009-07-08T19:20:53Z
[ "python", "beautifulsoup", "httplib2" ]
how to fix or make an exception for this error
1,100,029
<p>I'm creating a code that gets image's urls from any web pages, the code are in python and use BeutifulSoup and httplib2. When I run the code, I get the next error:</p> <pre><code>Look me http://movies.nytimes.com (this line is printed by the code) Traceback (most recent call last): File "main.py", line 103...
1
2009-07-08T19:15:58Z
1,100,462
<p>Are you using latest version of BeautifulSoup?<br /> This seems a known issue of version 3.1.x, because it started using a new parser (HTMLParser, instead of SGMLParser) that is much worse at processing malformed HTML. You can find more information about this on <a href="http://www.crummy.com/software/BeautifulSoup/...
4
2009-07-08T20:46:06Z
[ "python", "beautifulsoup", "httplib2" ]
how to fix or make an exception for this error
1,100,029
<p>I'm creating a code that gets image's urls from any web pages, the code are in python and use BeutifulSoup and httplib2. When I run the code, I get the next error:</p> <pre><code>Look me http://movies.nytimes.com (this line is printed by the code) Traceback (most recent call last): File "main.py", line 103...
1
2009-07-08T19:15:58Z
1,843,482
<p>I got that error when I had the string <strong>=&amp;</strong> in my HTML document. When I replaced that string (in my case with <strong>=and</strong>) then I no longer received that parsing error.</p>
0
2009-12-03T22:34:07Z
[ "python", "beautifulsoup", "httplib2" ]
FFT-based 2D convolution and correlation in Python
1,100,100
<p>Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)?</p> <p>There are functions like these:</p> <ul> <li><code>scipy.signal.correlate2d</code> - "the direct method implemented by <code>convolveND</code> will be slow for large data"</li> <li><code>scipy.nd...
19
2009-07-08T19:32:19Z
1,100,281
<p>I think you want the scipy.stsci package:</p> <p><a href="http://docs.scipy.org/doc/scipy/reference/stsci.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/stsci.html</a></p> <pre><code>In [30]: scipy.__version__ Out[30]: '0.7.0' In [31]: from scipy.stsci.convolve import convolve2d, correlate2d </cod...
4
2009-07-08T20:07:59Z
[ "python", "image", "numpy", "signal-processing", "fft" ]
FFT-based 2D convolution and correlation in Python
1,100,100
<p>Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)?</p> <p>There are functions like these:</p> <ul> <li><code>scipy.signal.correlate2d</code> - "the direct method implemented by <code>convolveND</code> will be slow for large data"</li> <li><code>scipy.nd...
19
2009-07-08T19:32:19Z
1,101,764
<p>I've lost track of the status of this package in scipy, but I know we include ndimage as part of the stsci_python release package as a convenience for our users:</p> <p><a href="http://www.stsci.edu/resources/software_hardware/pyraf/stsci_python/current/download" rel="nofollow">http://www.stsci.edu/resources/softwa...
2
2009-07-09T03:53:20Z
[ "python", "image", "numpy", "signal-processing", "fft" ]
FFT-based 2D convolution and correlation in Python
1,100,100
<p>Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)?</p> <p>There are functions like these:</p> <ul> <li><code>scipy.signal.correlate2d</code> - "the direct method implemented by <code>convolveND</code> will be slow for large data"</li> <li><code>scipy.nd...
19
2009-07-08T19:32:19Z
1,477,259
<p>look at scipy.signal.fftconvolve, signal.convolve and signal.correlate (there is a signal.correlate2d but it seems to return an shifted array, not centered).</p>
6
2009-09-25T13:22:24Z
[ "python", "image", "numpy", "signal-processing", "fft" ]
FFT-based 2D convolution and correlation in Python
1,100,100
<p>Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)?</p> <p>There are functions like these:</p> <ul> <li><code>scipy.signal.correlate2d</code> - "the direct method implemented by <code>convolveND</code> will be slow for large data"</li> <li><code>scipy.nd...
19
2009-07-08T19:32:19Z
1,768,140
<p>I found <code>scipy.signal.fftconvolve</code>, <a href="http://stackoverflow.com/a/1477259/125507">as also pointed out by magnus</a>, but didn't realize at the time that it's <em>n</em>-dimensional. Since it's built-in and produces the right values, it seems like the ideal solution.</p> <p>From <a href="http://www...
15
2009-11-20T03:22:54Z
[ "python", "image", "numpy", "signal-processing", "fft" ]
FFT-based 2D convolution and correlation in Python
1,100,100
<p>Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)?</p> <p>There are functions like these:</p> <ul> <li><code>scipy.signal.correlate2d</code> - "the direct method implemented by <code>convolveND</code> will be slow for large data"</li> <li><code>scipy.nd...
19
2009-07-08T19:32:19Z
8,454,010
<p>I wrote a cross-correlation/convolution wrapper that takes care of padding &amp; nans and includes a simple smooth wrapper <a href="http://code.google.com/p/agpy/source/browse/trunk/AG_fft_tools/convolve_nd.py" rel="nofollow">here</a>. It's not a popular package, but it also has no dependencies besides numpy (or ff...
2
2011-12-10T02:45:41Z
[ "python", "image", "numpy", "signal-processing", "fft" ]
How to properly do one-to-many joins on an (Python) Google App Engine datasource?
1,100,472
<p>I have some models set up like:</p> <pre><code>class Apps(db.Model): name = db.StringProperty(multiline=False) description = db.TextProperty() class AppScreenshots(db.Model): image_file = db.StringProperty(multiline=False) description = db.StringProperty(multiline=False) app ...
2
2009-07-08T20:48:13Z
1,101,289
<p>The problem I found when trying to run your code was that apparently you need to change the name of 'app' in AppScreenshots to something else such as 'apps'. The word 'app' must be reserved in this context.</p> <p>Try this Query instead. You could do .filter() too on this if you don't want the first entity.</p> <p...
5
2009-07-09T00:49:44Z
[ "python", "google-app-engine", "gql" ]
Create PyQt menu from a list of strings
1,100,775
<p>I have a list of strings and want to create a menu entry for each of those strings. When the user clicks on one of the entries, always the same function shall be called with the string as an argument. After some trying and research I came up with something like this:</p> <pre><code>import sys from PyQt4 import QtGu...
10
2009-07-08T22:01:56Z
1,100,828
<p>This should work, but I'm pretty sure there was a better way that I can't recall right now.</p> <pre><code>def do_stuff_caller(self, item): return lambda: self.doStuff(item) ... self.connect(entry, QtCore.SIGNAL('triggered()'), self.do_stuff_caller(item)) </code></pre> <p><strong>Edit</strong>: Shorter versio...
2
2009-07-08T22:13:07Z
[ "python", "qt", "pyqt", "signals-slots" ]
Create PyQt menu from a list of strings
1,100,775
<p>I have a list of strings and want to create a menu entry for each of those strings. When the user clicks on one of the entries, always the same function shall be called with the string as an argument. After some trying and research I came up with something like this:</p> <pre><code>import sys from PyQt4 import QtGu...
10
2009-07-08T22:01:56Z
1,102,089
<p>You're meeting what's been often referred to (maybe not entirely pedantically-correctly;-) as the "scoping problem" in Python -- the binding is late (lexical lookup at call-time) while you'd like it early (at def-time). So where you now have:</p> <pre><code> for item in menuitems: entry = menu.addAction(...
23
2009-07-09T06:10:54Z
[ "python", "qt", "pyqt", "signals-slots" ]
Why would Django's cache work with locmem but fail with memcached?
1,101,049
<p>Using Django's cache with locmem (with simple Python classes as values stored in lists/tuples/maps) works perfectly but does not work with memcached.</p> <p>Only a fraction of the keys (despite ample memory allocated and large timeouts) make their way into memcached, and none of them appear to have any associated v...
4
2009-07-08T23:14:32Z
1,101,991
<p>To find out what's going on, run <code>memcached -vv 2&gt;/tmp/mc_debug_log</code> (I'm assuming you're on some sort of Unixy system) and run it for a <em>short</em> time -- you'll find detailed information in that logfile when you're done.</p> <p>Depending on what Python interface to memcached you're using, it may...
3
2009-07-09T05:36:16Z
[ "python", "django", "caching", "memcached" ]
Why would Django's cache work with locmem but fail with memcached?
1,101,049
<p>Using Django's cache with locmem (with simple Python classes as values stored in lists/tuples/maps) works perfectly but does not work with memcached.</p> <p>Only a fraction of the keys (despite ample memory allocated and large timeouts) make their way into memcached, and none of them appear to have any associated v...
4
2009-07-08T23:14:32Z
1,105,858
<p>Apparently, keys can not have spaces in them:</p> <p><a href="http://code.djangoproject.com/ticket/6447" rel="nofollow">http://code.djangoproject.com/ticket/6447</a><br/> <a href="http://blog.pos.thum.us/2009/05/22/memcached-keys-cant-have-spaces-in-them/" rel="nofollow">http://blog.pos.thum.us/2009/05/22/memcached...
3
2009-07-09T19:01:31Z
[ "python", "django", "caching", "memcached" ]
Library to read ELF file DWARF debug information
1,101,272
<p>Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I'd like to read the DWARF debug info in a Python program.</p>
19
2009-07-09T00:37:14Z
1,101,352
<p>The concept of "ELF debug info" doesn't really exist: the ELF specification leaves the content of the .debug section deliberately unspecified.</p> <p>Common debug formats are STAB and <a href="http://dwarfstd.org/" rel="nofollow">DWARF</a>. A library to read DWARF is <a href="http://www.prevanders.net/dwarf.html" r...
9
2009-07-09T01:11:00Z
[ "python", "debugging", "elf", "dwarf" ]
Library to read ELF file DWARF debug information
1,101,272
<p>Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I'd like to read the DWARF debug info in a Python program.</p>
19
2009-07-09T00:37:14Z
1,101,356
<p>You might find useful informations here:</p> <ul> <li><a href="http://reality.sgiweb.org/davea/dwarf.html">David A's DWARF Page</a></li> <li><a href="http://stackoverflow.com/questions/45954/python-libdwarf-module">SO question</a></li> </ul>
5
2009-07-09T01:12:11Z
[ "python", "debugging", "elf", "dwarf" ]
Library to read ELF file DWARF debug information
1,101,272
<p>Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I'd like to read the DWARF debug info in a Python program.</p>
19
2009-07-09T00:37:14Z
1,128,586
<p>Your options for reading the DWARF debugging information are unfortunately quite limited.</p> <p>As far as I know there is only one general purpose library for parsing DWARF debugging information and that is <a href="http://reality.sgiweb.org/davea/dwarf.html" rel="nofollow" title="libdwarf">libdwarf</a>. Unfortuna...
4
2009-07-14T23:11:17Z
[ "python", "debugging", "elf", "dwarf" ]
Library to read ELF file DWARF debug information
1,101,272
<p>Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I'd like to read the DWARF debug info in a Python program.</p>
19
2009-07-09T00:37:14Z
3,647,042
<p>You might be interested in the DWARF library from <a href="http://code.google.com/p/pydevtools/">pydevtools</a>:</p> <pre><code>&gt;&gt;&gt; from devtools.dwarf import DWARF &gt;&gt;&gt; dwarf = DWARF('test/test') &gt;&gt;&gt; dwarf.get_loc_by_addr(0x8048475) ('/home/emilmont/Workspace/dbg/test/main.c', 36, 0) &gt;...
7
2010-09-05T17:40:47Z
[ "python", "debugging", "elf", "dwarf" ]
Library to read ELF file DWARF debug information
1,101,272
<p>Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I'd like to read the DWARF debug info in a Python program.</p>
19
2009-07-09T00:37:14Z
8,754,544
<p>There's a new kid on the block - <a href="https://github.com/eliben/pyelftools">pyelftools</a> - a pure Python library for parsing the ELF and DWARF formats. Give it a try.</p> <p>It aims to be feature-complete and is currently in active development, so any problems should be handled quickly and enthusiastically :-...
19
2012-01-06T07:09:00Z
[ "python", "debugging", "elf", "dwarf" ]
Are there any class diagram generating tools for python source code?
1,101,301
<p>Are there any reverse-egineering UML tools for Python?</p>
7
2009-07-09T00:56:30Z
1,101,333
<p><a href="http://sourceforge.net/projects/eclipse-pyuml/" rel="nofollow">pyUML</a> may be what you are looking for. Although it is an Eclipse plugin for PyDev.</p>
2
2009-07-09T01:05:51Z
[ "python", "uml" ]
Are there any class diagram generating tools for python source code?
1,101,301
<p>Are there any reverse-egineering UML tools for Python?</p>
7
2009-07-09T00:56:30Z
1,101,342
<p><a href="http://www.sparxsystems.com/" rel="nofollow">Sparx Enterprise Architect</a> can reverse engineer Python code, at least according to the documentation. I've never tried it, so I don't know for certain.</p>
2
2009-07-09T01:07:45Z
[ "python", "uml" ]
Are there any class diagram generating tools for python source code?
1,101,301
<p>Are there any reverse-egineering UML tools for Python?</p>
7
2009-07-09T00:56:30Z
1,101,417
<p>This looks good: <a href="http://www.andypatterns.com/index.php?cID=65">http://www.andypatterns.com/index.php?cID=65</a></p> <p>How about this? <a href="http://www.greenteapress.com/thinkpython/swampy/lumpy.html">http://www.greenteapress.com/thinkpython/swampy/lumpy.html</a></p>
5
2009-07-09T01:36:04Z
[ "python", "uml" ]
How to parse dates with -0400 timezone string in python?
1,101,508
<p>I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that previous versions of python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.</p> <p>What's the right way to parse this string into a datetime object?</p>
47
2009-07-09T02:19:03Z
1,101,597
<p>You can use the parse function from dateutil:</p> <pre><code>&gt;&gt;&gt; from dateutil.parser import parse &gt;&gt;&gt; d = parse('2009/05/13 19:19:30 -0400') &gt;&gt;&gt; d datetime.datetime(2009, 5, 13, 19, 19, 30, tzinfo=tzoffset(None, -14400)) </code></pre> <p>This way you obtain a datetime object you can the...
72
2009-07-09T02:47:14Z
[ "python", "datetime", "timezone" ]
How to parse dates with -0400 timezone string in python?
1,101,508
<p>I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that previous versions of python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.</p> <p>What's the right way to parse this string into a datetime object?</p>
47
2009-07-09T02:19:03Z
1,101,688
<p>If you are on linux, then you can use the external <code>date</code> command to dwim :</p> <pre><code>import commands, datetime def parsedate(text): output=commands.getoutput('date -d "%s" +%%s' % text ) try: stamp=eval(output) except: print output raise return datetime.datetime.frometime...
-4
2009-07-09T03:21:44Z
[ "python", "datetime", "timezone" ]
How to parse dates with -0400 timezone string in python?
1,101,508
<p>I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that previous versions of python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.</p> <p>What's the right way to parse this string into a datetime object?</p>
47
2009-07-09T02:19:03Z
15,516,170
<p>The problem with using dateutil is that you can't have the same format string for both serialization and deserialization, as dateutil has limited formatting options (only <code>dayfirst</code> and <code>yearfirst</code>).</p> <p>In my application, I store the format string in .INI file, and each deployment can have...
7
2013-03-20T05:41:41Z
[ "python", "datetime", "timezone" ]
How to parse dates with -0400 timezone string in python?
1,101,508
<p>I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that previous versions of python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.</p> <p>What's the right way to parse this string into a datetime object?</p>
47
2009-07-09T02:19:03Z
23,122,493
<p><code>%z</code> is supported in Python 3.2+:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; datetime.strptime('2009/05/13 19:19:30 -0400', '%Y/%m/%d %H:%M:%S %z') datetime.datetime(2009, 5, 13, 19, 19, 30, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000))) </code></pr...
25
2014-04-17T00:21:33Z
[ "python", "datetime", "timezone" ]
How to parse dates with -0400 timezone string in python?
1,101,508
<p>I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that previous versions of python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.</p> <p>What's the right way to parse this string into a datetime object?</p>
47
2009-07-09T02:19:03Z
38,992,733
<p>Here is a fix of the <code>"%z"</code> issue for python 2.7</p> <p>Instead of using:</p> <pre><code>datetime.strptime(t,'%Y-%m-%dT%H:%M %z') </code></pre> <p>use the <code>timedelta</code> to account for the timezone, like this:</p> <pre><code>from datetime import datetime,timedelta def dt_parse(t): ret = da...
3
2016-08-17T09:25:32Z
[ "python", "datetime", "timezone" ]
python calendar.HTMLCalendar
1,101,524
<p>I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I'll probably think of a better way, but right now it's a little personal. I don't know if this was intended to be used this way but it seems like it is a little pointless if you can't at least making...
3
2009-07-09T02:23:48Z
1,101,566
<p>It's hard to say without knowing exactly what you're trying to accomplish, but here's one idea.</p> <p>Instead of printing myCal.formatmonth(2009, 7), why don't you assign it to a string. Then you could manipulate it, perhaps with a regex.</p> <p>Here's a really bad example:</p> <pre><code>import calendar import...
0
2009-07-09T02:34:52Z
[ "python", "html", "calendar" ]
python calendar.HTMLCalendar
1,101,524
<p>I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I'll probably think of a better way, but right now it's a little personal. I don't know if this was intended to be used this way but it seems like it is a little pointless if you can't at least making...
3
2009-07-09T02:23:48Z
1,101,743
<p>You may load html, which seems to be valid XMl into a XML tree, modify it and again output it. e.g. this adds <code>&lt;br/&gt; cool</code> to each Tue td node.</p> <pre><code>import calendar import xml.etree.ElementTree as etree myCal = calendar.HTMLCalendar(calendar.SUNDAY) htmlStr = myCal.formatmonth(2009, 7) h...
0
2009-07-09T03:47:44Z
[ "python", "html", "calendar" ]
python calendar.HTMLCalendar
1,101,524
<p>I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I'll probably think of a better way, but right now it's a little personal. I don't know if this was intended to be used this way but it seems like it is a little pointless if you can't at least making...
3
2009-07-09T02:23:48Z
1,102,014
<p>The calendar module has usually been pretty useless, but in 2.5 it introduced the Calendar object. This won't render an HTML calendar for you, but it has loads of methods that will help you render a calendar.</p> <p>For example, monthdatescalendar(year, month) will give you a list of all weeks in the month given, w...
16
2009-07-09T05:42:33Z
[ "python", "html", "calendar" ]
python calendar.HTMLCalendar
1,101,524
<p>I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I'll probably think of a better way, but right now it's a little personal. I don't know if this was intended to be used this way but it seems like it is a little pointless if you can't at least making...
3
2009-07-09T02:23:48Z
1,458,077
<p>Create a new class inheriting from HTMLCalendar. Override the formatday method.</p> <p>Whoever makes comments like "this library is useless" obviously doesn't understand Python.</p> <pre><code>class EmployeeScheduleCalendar(HTMLCalendar): def formatday(self, day, weekday): """ Return a day as...
33
2009-09-22T04:17:47Z
[ "python", "html", "calendar" ]
python calendar.HTMLCalendar
1,101,524
<p>I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I'll probably think of a better way, but right now it's a little personal. I don't know if this was intended to be used this way but it seems like it is a little pointless if you can't at least making...
3
2009-07-09T02:23:48Z
5,561,014
<p>You can subclass HTMLCalendar and override its methods in order to do whatever you want, like so: <a href="http://journal.uggedal.com/creating-a-flexible-monthly-calendar-in-django/" rel="nofollow">http://journal.uggedal.com/creating-a-flexible-monthly-calendar-in-django/</a></p> <p>If you refer to the documentatio...
3
2011-04-06T03:07:04Z
[ "python", "html", "calendar" ]
Why my Python test generator simply doesn't work?
1,101,550
<p>This is a sample script to test the use of yield... am I doing it wrong? It always returns '1'...</p> <pre><code>#!/usr/bin/python def testGen(): for a in [1,2,3,4,5,6,7,8,9,10]: yield a w = 0 while w &lt; 10: print testGen().next() w += 1 </code></pre>
1
2009-07-09T02:30:01Z
1,101,579
<p>You're creating a new generator each time. You should only call <code>testGen()</code> once and then use the object returned. Try:</p> <pre><code>w = 0 g = testGen() while w &lt; 10: print g.next() w += 1 </code></pre> <p>Then of course there's the normal, idiomatic generator usage:</p> <pre><code>for n i...
10
2009-07-09T02:37:06Z
[ "python", "testing", "generator", "yield" ]
Help needed improving Python code using List Comprehensions
1,101,611
<p>I've been writing little Python programs at home to learn more about the language. The most recent feature I've tried to understand are List Comprehensions. I created a little script that estimates when my car needs its next oil change based on how frequently I've gotten the oil changed in the past. In the code s...
3
2009-07-09T02:51:36Z
1,101,622
<p>It seems fine, really. Not everything is simple (you've got several steps in an otherwise simple calculation, no matter how you frame it). There are options to reduce the copies, like using itertools.islice and itertools.izip, but (aside from izip) the extra steps in the code would just complicate it further. Not ev...
2
2009-07-09T02:56:11Z
[ "python", "list-comprehension" ]
Help needed improving Python code using List Comprehensions
1,101,611
<p>I've been writing little Python programs at home to learn more about the language. The most recent feature I've tried to understand are List Comprehensions. I created a little script that estimates when my car needs its next oil change based on how frequently I've gotten the oil changed in the past. In the code s...
3
2009-07-09T02:51:36Z
1,101,640
<p>The <a href="http://docs.python.org/library/itertools.html" rel="nofollow"><code>itertools</code></a> package provides additional generator-style functions. For instance, you can use <code>izip</code> in place of <code>zip</code> to save on some memory.</p> <p>You could also perhaps write an <code>average</code> fu...
3
2009-07-09T03:01:17Z
[ "python", "list-comprehension" ]
Help needed improving Python code using List Comprehensions
1,101,611
<p>I've been writing little Python programs at home to learn more about the language. The most recent feature I've tried to understand are List Comprehensions. I created a little script that estimates when my car needs its next oil change based on how frequently I've gotten the oil changed in the past. In the code s...
3
2009-07-09T02:51:36Z
1,101,656
<p>Try this: </p> <pre><code>assert len(oil_changes) &gt;= 2 sum_of_diffs = oil_changes[-1] - oil_changes[0] number_of_diffs = len(oil_changes) - 1 average_diff = sum_of_diffs / float(number_of_diffs) </code></pre>
9
2009-07-09T03:07:40Z
[ "python", "list-comprehension" ]
Help needed improving Python code using List Comprehensions
1,101,611
<p>I've been writing little Python programs at home to learn more about the language. The most recent feature I've tried to understand are List Comprehensions. I created a little script that estimates when my car needs its next oil change based on how frequently I've gotten the oil changed in the past. In the code s...
3
2009-07-09T02:51:36Z
1,101,804
<blockquote> <p>Am I doing a lot of needless copying of the original list in the first line?</p> </blockquote> <p>Technically, yes. Realistically, no. Unless you've changed your oil literally millions of times, the speed penalty is unlikely to be significant. You could change <code>zip</code> to <code>izip</c...
2
2009-07-09T04:11:17Z
[ "python", "list-comprehension" ]
Help needed improving Python code using List Comprehensions
1,101,611
<p>I've been writing little Python programs at home to learn more about the language. The most recent feature I've tried to understand are List Comprehensions. I created a little script that estimates when my car needs its next oil change based on how frequently I've gotten the oil changed in the past. In the code s...
3
2009-07-09T02:51:36Z
1,101,939
<p>As other answers pointed out, you don't really need to worry unless your <code>oil_changes</code> list is extremely long. However, as a fan of "stream-based" computing, I think it's interesting to point out that <code>itertools</code> offers all the tools you need to compute your <code>next_oil</code> value in O(1) ...
9
2009-07-09T05:15:57Z
[ "python", "list-comprehension" ]
Unicode problem Django-Python-URLLIB-MySQL
1,101,715
<p>I am fetching a webpage (<a href="http://autoweek.com" rel="nofollow">http://autoweek.com</a>) and trying to process it but getting encoding error. Autoweek declares "iso-8859-1" encoding and has the word "Nürburgring" (u with umlaut)</p> <p>I do: </p> <pre><code># -*- encoding: utf-8 -*- import urllib webpage =...
0
2009-07-09T03:34:42Z
1,101,745
<p>If the <code>webpage</code> declares encoding <code>iso-8859-1</code>, can't you just do <code>webpage.decode("iso-8859-1")</code>?</p> <p>At that point, <code>webpage</code> is decoded for your app. When it is written into the database, the mapping there should handle the char-to-utf8 encoding.</p> <p>To get the ...
3
2009-07-09T03:48:02Z
[ "python", "unicode", "encoding", "utf-8", "urllib" ]
Unicode problem Django-Python-URLLIB-MySQL
1,101,715
<p>I am fetching a webpage (<a href="http://autoweek.com" rel="nofollow">http://autoweek.com</a>) and trying to process it but getting encoding error. Autoweek declares "iso-8859-1" encoding and has the word "Nürburgring" (u with umlaut)</p> <p>I do: </p> <pre><code># -*- encoding: utf-8 -*- import urllib webpage =...
0
2009-07-09T03:34:42Z
1,102,213
<p><a href="http://autoweek.com" rel="nofollow">autoweek.com</a> seems confused about it's own encoding. It declares conflicting charset definitions:</p> <pre><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; </code></pre> <p>and later...</p> <pre><code>&lt;meta charset=iso-8859-1"/&g...
0
2009-07-09T06:50:44Z
[ "python", "unicode", "encoding", "utf-8", "urllib" ]
Tkinter: AttributeError: NoneType object has no attribute get
1,101,750
<p>I have seen a couple of other posts on similar error message but couldn't find a solution which would fix it in my case.</p> <p>I dabbled a bit with TkInter and created a very simple UI. The code follows-</p> <pre><code>from string import * from Tkinter import * import tkMessageBox root=Tk() vid = IntVar() def g...
14
2009-07-09T03:48:56Z
1,101,765
<p>The <code>grid</code> (and <code>pack</code>, and <code>place</code>) function of the <code>Entry</code> object (and of all other widgets) returns <code>None</code>. In python when you do <code>a().b()</code>, the result of the expression is whatever <code>b()</code> returns, therefore <code>Entry(...).grid(...)</co...
39
2009-07-09T03:53:34Z
[ "python", "user-interface", "tkinter" ]
Tkinter: AttributeError: NoneType object has no attribute get
1,101,750
<p>I have seen a couple of other posts on similar error message but couldn't find a solution which would fix it in my case.</p> <p>I dabbled a bit with TkInter and created a very simple UI. The code follows-</p> <pre><code>from string import * from Tkinter import * import tkMessageBox root=Tk() vid = IntVar() def g...
14
2009-07-09T03:48:56Z
1,102,053
<p>Change this line:</p> <pre><code>entryBox=Entry(root,width=60).grid(row=2, column=1,sticky=W) </code></pre> <p>into these two lines:</p> <pre><code>entryBox=Entry(root,width=60) entryBox.grid(row=2, column=1,sticky=W) </code></pre> <p>The same goes for <code>label</code> by the way - just as you already correctl...
3
2009-07-09T05:55:49Z
[ "python", "user-interface", "tkinter" ]
Is there a way to plan and diagram an architecture for dynamic scripting languages like groovy or python?
1,102,134
<p>Say I want to write a large application in groovy, and take advantage of closures, categories and other concepts (that I regularly use to separate concerns). Is there a way to diagram or otherwise communicate in a simple way the architecture of some of this stuff? How do you detail (without verbose documentation) ...
1
2009-07-09T06:23:17Z
1,102,164
<p>If you don't want to generate verbose documentation, a picture is worth a thousand words. I've found tools like <a href="http://freemind.sourceforge.net/wiki/index.php/Main_Page" rel="nofollow">FreeMind</a> useful, both for clarifying my ideas and for communicating them to others. And if you are willing to invest in...
1
2009-07-09T06:34:21Z
[ "python", "architecture", "groovy", "uml", "dynamic-languages" ]
Is there a way to plan and diagram an architecture for dynamic scripting languages like groovy or python?
1,102,134
<p>Say I want to write a large application in groovy, and take advantage of closures, categories and other concepts (that I regularly use to separate concerns). Is there a way to diagram or otherwise communicate in a simple way the architecture of some of this stuff? How do you detail (without verbose documentation) ...
1
2009-07-09T06:23:17Z
1,102,219
<p>UML isn't too well equipped to handle such things, but you can still use it to communicate your design if you are willing to do some mental mapping. You can find an isomorphism between most dynamic concepts and UMLs static object-model.</p> <p>For example you can think of a closure as an object implementing a one m...
3
2009-07-09T06:52:39Z
[ "python", "architecture", "groovy", "uml", "dynamic-languages" ]
Should I use Celery or Carrot for a Django project?
1,102,254
<p>I'm a little confused as to which one I should use. I think either will work, but is one better or more appropriate than the other?</p> <p><a href="http://github.com/ask/carrot/tree/master">http://github.com/ask/carrot/tree/master</a></p> <p><a href="http://github.com/ask/celery/tree/master">http://github.com/ask/...
19
2009-07-09T07:05:44Z
1,102,290
<p>If you need to send/receive messages to/from AMQP message queues, use <code>carrot</code>.</p> <p>If you want to run scheduled tasks on a number of machines, use <code>celery</code>.</p> <p>If you're making soup, use both ;-)</p>
69
2009-07-09T07:15:14Z
[ "python", "django", "message-queue", "rabbitmq", "amqp" ]
Should I use Celery or Carrot for a Django project?
1,102,254
<p>I'm a little confused as to which one I should use. I think either will work, but is one better or more appropriate than the other?</p> <p><a href="http://github.com/ask/carrot/tree/master">http://github.com/ask/carrot/tree/master</a></p> <p><a href="http://github.com/ask/celery/tree/master">http://github.com/ask/...
19
2009-07-09T07:05:44Z
1,970,813
<p>May you should see this <a href="http://www.slideshare.net/idangazit/an-introduction-to-celery">http://www.slideshare.net/idangazit/an-introduction-to-celery</a></p>
6
2009-12-28T18:22:08Z
[ "python", "django", "message-queue", "rabbitmq", "amqp" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,102,488
<p>I was working on this yesterday, and I found that adding "charset=utf8" and "use_unicode=1" to the connection string made it work (using SQLAlchemy, guess it's the same problem).</p> <p>So my string looks like: "mysql://user:pass@host:3306/database?use_unicode=1&amp;charset=utf8"</p>
1
2009-07-09T08:11:43Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,102,490
<p>You are using strings of type 'unicode'. If your model or SQL backend does not support them or does not know how to convert to UTF-8, simply do the conversion yourself. Stick with simple strings (python type str) and convert like in</p> <pre><code>a = models.Achievement(name=u"Played Mirror's Edge\u2122".encode("UT...
3
2009-07-09T08:11:52Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,102,518
<p><del>To me the apostrophe looks strange, should it not be escapded like so:</del></p> <pre><code>u"Played Mirror\'s Edge\u2122" </code></pre>
-1
2009-07-09T08:25:41Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,102,567
<p>I agree with Nikolai. I already encountered problem to use UTF-8, even in pure Python (2.5).</p> <p>I finally used the unicode function(?): </p> <pre><code>entry = unicode(sys.stdin, ENCODING) </code></pre> <p>ENCODING was depending on the locale, if I remember well:</p> <pre><code>import sys, locale ENCODIN...
0
2009-07-09T08:33:52Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,104,201
<p>A few remarks: </p> <ul> <li><p>Python 2.x has two string types</p> <ul> <li>"str", which is basically a byte array (so you can store anything you like in it)</li> <li>"unicode" , which is UCS2/UCS4 encoded unicode internally</li> </ul></li> <li><p>Instances of these types are considered "decoded" data. The intern...
4
2009-07-09T14:22:19Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,104,322
<p>I was having similar problems with mysql and postgres but no problems with sqllite.</p> <p>This is how i solved the problem with postgres (didnt test this trick with mysql but id asume it would solve it as well)</p> <p>in the file where u are dealing with the unicode string do a </p> <pre><code>from django.utils....
0
2009-07-09T14:42:11Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python - Problem storing Unicode character to MySQL with Django
1,102,465
<p>I have the string </p> <pre><code> u"Played Mirror's Edge\u2122" </code></pre> <p>Which should be shown as </p> <pre><code> Played Mirror's Edge™ </code></pre> <p>But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA:</p> <pre><code>a = m...
6
2009-07-09T08:04:19Z
1,106,383
<p>Thank you to everyone who was posting here. It really helps my unicode knowledge (and hoepfully other people learned something).</p> <p>We seemed to be all barking up the wrong tree since I tried to simplify my problem and didn't give ALL information. It seems that I wasn't using "REAL" unicode strings, but rather ...
11
2009-07-09T20:52:28Z
[ "python", "mysql", "django", "unicode", "django-models" ]
python how to create different instances of the same class into an iteration
1,102,822
<p>My problem is:</p> <p>I would like to add to a Composite class Leaf objects created at runtime inside a Composite routine like this:</p> <pre><code>def update(self, tp, msg, stt): """It updates composite objects """ d = Leaf() d.setDict(tp, msg, stt) self.append_child(d) return self.statu...
0
2009-07-09T09:35:44Z
1,102,937
<p>What is doing the append_child? I think it should store the leafs in a list. Does it?</p> <p>Update: you shouldn't pass self as first argument in the main function. I think that it raises an exception.</p> <p>See code below that seems to work ok</p> <pre> class Component(object): def __init__(self, *args, **k...
0
2009-07-09T09:58:12Z
[ "python", "design-patterns", "composite" ]
python how to create different instances of the same class into an iteration
1,102,822
<p>My problem is:</p> <p>I would like to add to a Composite class Leaf objects created at runtime inside a Composite routine like this:</p> <pre><code>def update(self, tp, msg, stt): """It updates composite objects """ d = Leaf() d.setDict(tp, msg, stt) self.append_child(d) return self.statu...
0
2009-07-09T09:35:44Z
1,103,288
<p>"But in this way I found always that my composite has just one leaf ("d") added even if update was called many times."</p> <p>No, that code makes Composite having ten children.</p> <pre><code>&gt;&gt;&gt; c.children [&lt;__main__.Leaf object at 0xb7da77ec&gt;, &lt;__main__.Leaf object at 0xb7da780c&gt;, &lt;__mai...
3
2009-07-09T11:27:46Z
[ "python", "design-patterns", "composite" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,102,857
<p>You will need to state the full path it's being moved to:</p> <pre><code>src = 'C:\a' dst_dir = 'C:\b' last_part = os.path.split(src)[1] os.rename(src, os.path.join(dst_dir, last_part)) </code></pre> <p>Actually, it looks like <code>shutil.move</code> will do what you want by looking at its documentation:</p> <bl...
0
2009-07-09T09:43:11Z
[ "python", "windows", "move" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,102,860
<p>You can try using the <a href="http://docs.python.org/library/shutil.html#module-shutil">Shutil</a> module.</p>
8
2009-07-09T09:43:43Z
[ "python", "windows", "move" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,102,872
<pre><code>os.rename("c:/a", "c:/b/a") </code></pre> <p>is equivalent to </p> <pre><code>move c:\a c:\b </code></pre> <p>under windows commandline</p>
16
2009-07-09T09:46:37Z
[ "python", "windows", "move" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,102,971
<p>When i need many file system operations I prefer using 'path' module:<br> <strong><a href="http://pypi.python.org/pypi/path.py/2.2" rel="nofollow">http://pypi.python.org/pypi/path.py/2.2</a></strong><br></p> <p>It's quite a good and lightweight wrapper around built-in 'os.path' module.</p> <p>Also code:</p> <pre>...
1
2009-07-09T10:04:44Z
[ "python", "windows", "move" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,102,992
<p>os.rename("c:/a/", "c:/b"/) --> Changes the name of folder a in folder b</p> <p>os.rename("c:/a/", "c:/b/a") --> Put folder b into folder a</p>
2
2009-07-09T10:09:12Z
[ "python", "windows", "move" ]
Moving files under python
1,102,825
<p>I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do</p> <pre><code>move c:\a c:\b </code></pre> <p>which moves a to b result is directory structure c:\b\a</p> <p>If I try this with os.rename or shutil.move:</p> <pre><code>os.rename("c:/a"...
8
2009-07-09T09:36:13Z
1,103,106
<p>Using Twisted's <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.python.filepath.FilePath.html" rel="nofollow">FilePath</a>:</p> <pre><code>from twisted.python.filepath import FilePath FilePath("c:/a").moveTo(FilePath("c:/b/a")) </code></pre> <p>or, more generally:</p> <pre><code>from twisted.python....
0
2009-07-09T10:34:00Z
[ "python", "windows", "move" ]
Python data/file Crc
1,103,104
<p>I am wanting to generate and store a CRC (or similar) value for a given list of files which can be used as a comparison at a later point. Writing a function to do this is simple enough, but is there a more standard way to do it within the Python libs?</p> <p>The value generated does not need to be of any particular...
1
2009-07-09T10:33:02Z
1,103,116
<p>recommend <a href="http://docs.python.org/library/hashlib.html" rel="nofollow">hashlib</a>, it implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1 and MD5. a demo code:</p> <pre><code>import hashlib m = hashlib.md5() for line...
5
2009-07-09T10:36:24Z
[ "python", "file", "md5", "crc", "hashlib" ]
Python data/file Crc
1,103,104
<p>I am wanting to generate and store a CRC (or similar) value for a given list of files which can be used as a comparison at a later point. Writing a function to do this is simple enough, but is there a more standard way to do it within the Python libs?</p> <p>The value generated does not need to be of any particular...
1
2009-07-09T10:33:02Z
1,103,137
<p>If you don't need one-way security you could also use <code>zlib.crc32</code> or <code>zlib.adler32</code>, as documented <a href="http://docs.python.org/library/zlib.html" rel="nofollow">here</a>.</p>
1
2009-07-09T10:43:38Z
[ "python", "file", "md5", "crc", "hashlib" ]
Can I detect if my code is running on cPython or Jython?
1,103,487
<p>I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_p...
8
2009-07-09T12:19:34Z
1,103,497
<p>if you're running Jython </p> <pre><code>import platform platform.system() </code></pre> <p>return 'Java'<br /> <a href="http://stackoverflow.com/questions/1086000/">here has some discussion</a>, hope this helps.</p>
13
2009-07-09T12:22:41Z
[ "python", "django", "jython" ]
Can I detect if my code is running on cPython or Jython?
1,103,487
<p>I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_p...
8
2009-07-09T12:19:34Z
1,103,680
<p>You'll have unique settings.py for every different environment.</p> <p>Your development settings.py should not be your QA/Test or production settings.py.</p> <p>What we do is this.</p> <p>We have a "master" settings.py that contains the installed apps and other items which don't change much.</p> <p>We have envir...
3
2009-07-09T12:53:18Z
[ "python", "django", "jython" ]
Can I detect if my code is running on cPython or Jython?
1,103,487
<p>I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_p...
8
2009-07-09T12:19:34Z
1,147,610
<p>As sunqiang pointed out</p> <pre><code>import platform platform.system() </code></pre> <p>works for Jython 2.5, but this doesn't work on Jython 2.2 (the previous Jython release). Also, there has been some discussion about returning more operating system specific details for calls like these in Jython 3.x. Nothin...
19
2009-07-18T14:01:38Z
[ "python", "django", "jython" ]
Can I detect if my code is running on cPython or Jython?
1,103,487
<p>I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_p...
8
2009-07-09T12:19:34Z
13,682,964
<p>The most clear-cut way is:</p> <blockquote> <blockquote> <blockquote> <p>import platform</p> <p>platform.python_implementation()</p> </blockquote> </blockquote> </blockquote> <p>'CPython'</p> <p>By default, most of the time the underlying interpreter is CPython only which is also ar...
12
2012-12-03T12:10:53Z
[ "python", "django", "jython" ]
How to match search strings to content in python
1,103,685
<p>Usually when we search, we have a list of stories, we provide a search string, and expect back a list of results where the given search strings matches the story.</p> <p>What I am looking to do, is the opposite. Give a list of search strings, and one story and find out which search strings match to that story.</p> ...
0
2009-07-09T12:54:23Z
1,103,884
<p>Probably slow, but easy solution:</p> <p>Make a query on the story plus each string to the search engine. If it returns anything, then it matches.</p> <p>Otherwise you need to implement the search syntax yourself. If that includes things like "title:" and stuff this can be rather complex. If it's only the AND and ...
0
2009-07-09T13:25:06Z
[ "python", "search", "lucene", "solr" ]
How to match search strings to content in python
1,103,685
<p>Usually when we search, we have a list of stories, we provide a search string, and expect back a list of results where the given search strings matches the story.</p> <p>What I am looking to do, is the opposite. Give a list of search strings, and one story and find out which search strings match to that story.</p> ...
0
2009-07-09T12:54:23Z
1,103,974
<p>Some time ago I looked for a python implementaion of lucene and I came accross of <a href="http://whoosh.ca/" rel="nofollow">Woosh</a> which is a pure python text-based research engine. Maybe it will statisfy your needs.</p> <p>You can also try <a href="http://lucene.apache.org/pylucene/" rel="nofollow">pyLucene</a...
0
2009-07-09T13:42:29Z
[ "python", "search", "lucene", "solr" ]