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
Python vars() global name error
2,226,386
<p>I'm having a bit of trouble understanding what's going wrong with the following function:</p> <pre><code>def ness(): pie='yum' vars()[pie]=4 print vars()[pie] print yum </code></pre> <p>So When I run that I get this result:</p> <pre><code>&gt;&gt;&gt; ness() 4 Traceback (most recent call last): File "&lt;st...
3
2010-02-09T02:38:47Z
2,226,410
<p><code>vars()</code> within a function gives you the local namespace, just like <code>locals()</code> -- see <a href="http://docs.python.org/library/functions.html?highlight=vars#vars" rel="nofollow">the docs</a>. Outside of a function (e.g. at the prompt) <code>locals()</code> (and <code>vars()</code> of course) gi...
4
2010-02-09T02:45:15Z
[ "python", "global" ]
Python vars() global name error
2,226,386
<p>I'm having a bit of trouble understanding what's going wrong with the following function:</p> <pre><code>def ness(): pie='yum' vars()[pie]=4 print vars()[pie] print yum </code></pre> <p>So When I run that I get this result:</p> <pre><code>&gt;&gt;&gt; ness() 4 Traceback (most recent call last): File "&lt;st...
3
2010-02-09T02:38:47Z
2,226,424
<p><code>vars()</code> is equivalent to <code>locals()</code>, which in the case of the function is the local variables in its scope and at in the interactive interpreter at the scope you have it, <code>vars() is globals()</code>. <code>locals()</code> is for reading only; the effects of trying to change it are undefin...
0
2010-02-09T02:47:50Z
[ "python", "global" ]
Python vars() global name error
2,226,386
<p>I'm having a bit of trouble understanding what's going wrong with the following function:</p> <pre><code>def ness(): pie='yum' vars()[pie]=4 print vars()[pie] print yum </code></pre> <p>So When I run that I get this result:</p> <pre><code>&gt;&gt;&gt; ness() 4 Traceback (most recent call last): File "&lt;st...
3
2010-02-09T02:38:47Z
2,226,448
<p>[Edit: I must be wrong here, since the 'exec' example works.]</p> <p>As everyone points out, it's a bad idea to modify vars(). You can understand the error, though, by realizing that python in some sense doesn't "see" that "yum" is a local. "print yum" is still resolved as a global reference; this happens before ...
0
2010-02-09T02:53:29Z
[ "python", "global" ]
Python vars() global name error
2,226,386
<p>I'm having a bit of trouble understanding what's going wrong with the following function:</p> <pre><code>def ness(): pie='yum' vars()[pie]=4 print vars()[pie] print yum </code></pre> <p>So When I run that I get this result:</p> <pre><code>&gt;&gt;&gt; ness() 4 Traceback (most recent call last): File "&lt;st...
3
2010-02-09T02:38:47Z
2,226,494
<p>There is way to do it with exec</p> <pre><code>&gt;&gt;&gt; def ness(): ... pie='yum' ... exec pie+"=4" ... print vars()[pie] ... print yum ... &gt;&gt;&gt; &gt;&gt;&gt; ness() 4 4 </code></pre> <p>But Instead of doing that, using a new dict is better and safe</p> <pre><code>&gt;&gt;&gt; def ness(): ... dic=...
2
2010-02-09T03:07:33Z
[ "python", "global" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
2,226,907
<p>"Two channels" means stereo, so it makes no sense to <em>sum</em> each channel's duration -- so you're off by a factor of two (2.18 seconds, not 4.37). As for signedness, as explained for example <a href="https://ccrma.stanford.edu/courses/422/projects/WaveFormat/">here</a>, and I quote:</p> <blockquote> <p>8-bi...
6
2010-02-09T05:15:36Z
[ "python", "audio", "pcm" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
2,226,910
<p>Each sample is 16 bits and there 2 channels, so the frame takes 4 bytes</p>
2
2010-02-09T05:17:05Z
[ "python", "audio", "pcm" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
2,226,925
<p>The duration is simply the number of frames divided by the number of frames per second. From your data this is: <code>96333 / 44100 = 2.18 seconds</code>.</p>
2
2010-02-09T05:21:32Z
[ "python", "audio", "pcm" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
2,227,076
<p>I know that an answer has already been accepted, but I did some things with audio a while ago and you have to unpack the wave doing something like this.</p> <pre><code>pcmdata = wave.struct.unpack("%dh"%(wavedatalength),wavedata) </code></pre> <p>Also, one package that I used was called PyAudio, though I still had...
3
2010-02-09T05:52:49Z
[ "python", "audio", "pcm" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
2,227,174
<p>Thank you for your help! I got it working and I'll post the solution here for everyone to use in case some other poor soul needs it:</p> <pre><code>import wave import struct def pcm_channels(wave_file): """Given a file-like object or file path representing a wave file, decompose it into its constituent PCM...
13
2010-02-09T06:18:05Z
[ "python", "audio", "pcm" ]
Interpreting WAV Data
2,226,853
<p>I'm trying to write a program to display PCM data. I've been very frustrated trying to find a library with the right level of abstraction, but I've found the python wave library and have been using that. However, I'm not sure how to interpret the data.</p> <p>The wave.getparams function returns (2 channels, 2 bytes...
6
2010-02-09T05:01:25Z
31,625,891
<p>Building upon <a href="http://stackoverflow.com/a/2227174/836995">this answer</a>, you can get a good performance boost by using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromstring.html" rel="nofollow">numpy.fromstring</a> or <a href="http://docs.scipy.org/doc/numpy/reference/generated/nump...
1
2015-07-25T11:16:16Z
[ "python", "audio", "pcm" ]
PyObjC + Xcode 3.2 + Non-Apple Python
2,226,902
<p>I want to get started trying to develop a few simple applications with PyObjC. I installed PyObjC and the Xcode templates. I know that PyObjC itself works, since I've run <a href="http://svn.picidae.net/trunk/pici-server/ADMIN/picidae.py" rel="nofollow">this script</a> successfully. When I tried to create a project ...
2
2010-02-09T05:14:56Z
2,227,023
<p>You have a 32-bit vs 64-bit problem. It appears you are using a Python 2.6 installed from MacPorts and apparently it was not a universal (32-bit/64-bit) build. Either your app is running as 64-bit and the Python is only 32-bit or the reverse. You can check by using <code>file</code>:</p> <pre><code>cd /opt/local...
3
2010-02-09T05:43:41Z
[ "python", "xcode", "pyobjc", "itertools" ]
Does anyone know of a Urwid like environment that is cross-platform for Python 3.x?
2,226,913
<p>I would like it to run on Linux, OS X, and Windows (XP/Vista/7).</p> <p>Thanks for any input.</p>
0
2010-02-09T05:18:38Z
2,226,922
<p>Your best bet is probably to use <a href="http://docs.python.org/library/2to3.html" rel="nofollow">2to3</a> to convert Urwid itself.</p>
2
2010-02-09T05:20:41Z
[ "python", "cross-platform", "python-3.x" ]
Does anyone know of a Urwid like environment that is cross-platform for Python 3.x?
2,226,913
<p>I would like it to run on Linux, OS X, and Windows (XP/Vista/7).</p> <p>Thanks for any input.</p>
0
2010-02-09T05:18:38Z
2,226,926
<p>I believe you're out of luck until Urwid itself is ported to Python 3 (and according to <a href="http://www.mail-archive.com/urwid@lists.excess.org/msg00503.html" rel="nofollow">this post</a> from last month, "the real work to port to python 3 hasn't started yet").</p>
2
2010-02-09T05:21:39Z
[ "python", "cross-platform", "python-3.x" ]
Does anyone know of a Urwid like environment that is cross-platform for Python 3.x?
2,226,913
<p>I would like it to run on Linux, OS X, and Windows (XP/Vista/7).</p> <p>Thanks for any input.</p>
0
2010-02-09T05:18:38Z
2,239,928
<p>Help port Urwid to Python 3! That is most likely more work that just running 2to3 on it, though. </p>
0
2010-02-10T19:59:44Z
[ "python", "cross-platform", "python-3.x" ]
formatting currencies with Python
2,226,935
<p>I would like to format integers as professional looking currency strings. For example:</p> <p>1200000 -> $1.2 million<br> 456 -> $456.00</p> <p>Do you know a good library for this, ideally with localization to handle European formats.</p>
3
2010-02-09T05:24:42Z
2,226,970
<p><a href="http://docs.python.org/library/locale.html#locale.currency" rel="nofollow"><code>locale.currency()</code></a> can handle the number bits, but I've not seen a module for the word part.</p>
4
2010-02-09T05:32:55Z
[ "python", "string", "integer", "format", "currency" ]
formatting currencies with Python
2,226,935
<p>I would like to format integers as professional looking currency strings. For example:</p> <p>1200000 -> $1.2 million<br> 456 -> $456.00</p> <p>Do you know a good library for this, ideally with localization to handle European formats.</p>
3
2010-02-09T05:24:42Z
2,227,094
<p>Such formatting seems reasonable in some limited uses. But, should 1200000 be formatted as 1.2 million or 1.20 million? And isn't 456 more friendly as $456 (without the cents)?</p> <p>Adding cents to large precise numbers is common in sweepstakes mailers (<em>Ed McMann says you can win $12,000,000.00</em>).</p> ...
2
2010-02-09T05:57:55Z
[ "python", "string", "integer", "format", "currency" ]
python mechanize proxy question
2,227,117
<p>I've got mechanize setup and working with python. I am adding support for using a proxy, but how do I check that I am actually using the proxy? </p> <p>Here is some code I am using:</p> <pre><code>ip = 'some proxy ip address' br.set_proxies({"http://": ip} ) </code></pre> <p>I started to wonder if it was workin...
0
2010-02-09T06:04:05Z
2,454,733
<p>I am not sure how to handle this issue with mechanize, but you could read the next link that explains how to do it without mechanize (but still in python):</p> <p><a href="http://stackoverflow.com/questions/765305/proxy-check-in-python">Proxy Check in python</a></p> <p>The simple solution provided at the above-men...
0
2010-03-16T13:39:49Z
[ "python", "django", "proxy", "mechanize" ]
python mechanize proxy question
2,227,117
<p>I've got mechanize setup and working with python. I am adding support for using a proxy, but how do I check that I am actually using the proxy? </p> <p>Here is some code I am using:</p> <pre><code>ip = 'some proxy ip address' br.set_proxies({"http://": ip} ) </code></pre> <p>I started to wonder if it was workin...
0
2010-02-09T06:04:05Z
3,849,869
<p>maybe like this ?</p> <pre><code>br = mechanize.Browser() br.set_proxies({"http": '127.0.0.1:80'}) </code></pre> <p>you need to debug for more information</p> <pre><code>br.set_debug_http(True) br.set_debug_redirects(True) </code></pre>
2
2010-10-03T13:08:52Z
[ "python", "django", "proxy", "mechanize" ]
Get types of arguments in python
2,227,141
<p>I'm learning python. I like to use help() or interinspect.getargspec to get information of functions in shell. But is there anyway I can get the argument/return type of function.</p>
4
2010-02-09T06:11:07Z
2,227,152
<p>There is a function called <code>type()</code>.<br> <a href="http://docs.python.org/library/functions.html#type" rel="nofollow">Here are the docs</a></p> <p>You can't tell in advance what type a function will return</p> <pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; def f(): ... c=random.choice("IFSN") ... i...
1
2010-02-09T06:13:31Z
[ "python", "types", "arguments" ]
Get types of arguments in python
2,227,141
<p>I'm learning python. I like to use help() or interinspect.getargspec to get information of functions in shell. But is there anyway I can get the argument/return type of function.</p>
4
2010-02-09T06:11:07Z
2,227,163
<p>If you mean during a certain call of the function, the function itself can get the types of its arguments by calling <code>type</code> on each of them (and will certainly know the type it returns).</p> <p>If you mean from outside the function, no: the function can be called with arguments of any types -- some such ...
4
2010-02-09T06:16:06Z
[ "python", "types", "arguments" ]
Get types of arguments in python
2,227,141
<p>I'm learning python. I like to use help() or interinspect.getargspec to get information of functions in shell. But is there anyway I can get the argument/return type of function.</p>
4
2010-02-09T06:11:07Z
2,227,551
<p>Easy way is to use <strong><a href="http://bpython-interpreter.org/" rel="nofollow">bpython</a></strong></p> <p>Python Learning gets easy &amp; fun again!</p> <p><img src="http://www.noiseforfree.com/bpython/img/bpython01.png" alt="alt text"></p>
0
2010-02-09T07:55:54Z
[ "python", "types", "arguments" ]
Get types of arguments in python
2,227,141
<p>I'm learning python. I like to use help() or interinspect.getargspec to get information of functions in shell. But is there anyway I can get the argument/return type of function.</p>
4
2010-02-09T06:11:07Z
26,779,591
<p>In the 3.4.2 documentation <a href="https://docs.python.org/3/library/inspect.html" rel="nofollow">https://docs.python.org/3/library/inspect.html</a>, there is a mention of what you exactly need (namely getting the types of arguments to a function).</p> <p>You will first need to define your function like this:</p> ...
1
2014-11-06T12:32:14Z
[ "python", "types", "arguments" ]
Are Python built-in containers thread-safe?
2,227,169
<p>I would like to know if the Python built-in containers (list, vector, set...) are thread-safe? Or do I need to implement a locking/unlocking environment for my shared variable?</p>
30
2010-02-09T06:17:20Z
2,227,210
<p>They are thread-safe as long as you don't disable the GIL in C code for the thread.</p>
3
2010-02-09T06:28:08Z
[ "python", "thread-safety" ]
Are Python built-in containers thread-safe?
2,227,169
<p>I would like to know if the Python built-in containers (list, vector, set...) are thread-safe? Or do I need to implement a locking/unlocking environment for my shared variable?</p>
30
2010-02-09T06:17:20Z
2,227,220
<p>You need to implement your own locking for all shared variables that will be modified in Python. You don't have to worry about reading from the variables that won't be modified (ie, concurrent reads are ok), so immutable types (<code>frozenset</code>, <code>tuple</code>, <code>str</code>) are <em>probably</em> safe,...
34
2010-02-09T06:29:50Z
[ "python", "thread-safety" ]
Are Python built-in containers thread-safe?
2,227,169
<p>I would like to know if the Python built-in containers (list, vector, set...) are thread-safe? Or do I need to implement a locking/unlocking environment for my shared variable?</p>
30
2010-02-09T06:17:20Z
2,227,228
<p>Yes, but you still need to be careful of course</p> <p>For example:</p> <p>If two threads are racing to <code>pop()</code> from a list with only one item, One thread will get the item successfully and the other will get an <code>IndexError</code></p> <p>Code like this is not thread-safe</p> <pre><code>if L: ...
5
2010-02-09T06:31:19Z
[ "python", "thread-safety" ]
how does create a new app in pinax?
2,227,246
<p>thanks</p> <p>only need 'python manage.py startapp xx' ???</p>
-3
2010-02-09T06:34:10Z
2,227,255
<p>You don't create a new app in pinax, you create a new app in your project. And yes, that command will do it.</p>
4
2010-02-09T06:37:27Z
[ "python", "django", "pinax" ]
Python question - I have a List of Classes, how do I remove duplicates?
2,227,297
<p>Am writing an App Engine application (it's a simple quest system for a game):</p> <p>so I have a list</p> <pre><code>class Quest(db.Model): name = db.StringProperty() # note: I made about 10 different quest entities ( quest1 to quest10) class User(db.Model): completed_quests = db.StringListProperty() # to st...
2
2010-02-09T06:48:50Z
2,227,332
<p>You can use <code>difference</code>:</p> <pre><code>all = set(quest.key() for quest in all_quests) complete = set(completed_quests) incomplete = all.difference(complete) </code></pre>
3
2010-02-09T06:58:40Z
[ "python", "google-app-engine" ]
Python question - I have a List of Classes, how do I remove duplicates?
2,227,297
<p>Am writing an App Engine application (it's a simple quest system for a game):</p> <p>so I have a list</p> <pre><code>class Quest(db.Model): name = db.StringProperty() # note: I made about 10 different quest entities ( quest1 to quest10) class User(db.Model): completed_quests = db.StringListProperty() # to st...
2
2010-02-09T06:48:50Z
2,227,908
<p>Try something like this:</p> <pre><code>quests = [(x.key(), x) for x in Quest.all.fetch(1000)] incomplete_quests = [v for k, v in quests if k not in a_user.completed_quests] </code></pre> <p>This presumes, for simplicity, that you first converted your list of completed quests to a db.ListProperty(db.Key).</p>
0
2010-02-09T09:17:16Z
[ "python", "google-app-engine" ]
Is there a way to prevent detection by the website when a screenshot is taken using a Mac Os X Safari browser?
2,227,469
<p>There is a thread discussing Darwin notifications being sent after a screenshot is taken. Does this apply to websites viewed via Safari? Do the same restrictions apply to PC sytems? Would taking the picture via a Python script in Linux or running Safari in a VM circumvent detection?</p>
0
2010-02-09T07:34:37Z
2,228,502
<p>if you are talking about <a href="http://stackoverflow.com/questions/2121970/notification-of-or-detecting-screenshot-being-taken">this thread</a>, please note that it seems to apply only to the iPhone. there is nothing similar in any decent web browser on any desktop platform (plus, anybody can put a proxy to filter...
2
2010-02-09T11:05:35Z
[ "python", "safari", "screenshot", "virtual-machine", "browser-detection" ]
ReportLab and Python Imaging Library images from memory issue
2,227,493
<p>I've run into an issue I can't seem to figure out with PIL and reportlab. Specifically, I would like to use drawImage on a canvas in reportlab using a PIL Image object.</p> <p>In the past I've inserted images into reportlab documents from the web using raw data, StringIO and reportlab's ImageReader class. Unfortuna...
8
2010-02-09T07:41:17Z
2,228,358
<p>Looking at the source for ReportLab 2.4, it seems that ImageReader will accept a PIL Image object as "filename".</p> <pre><code> def _isPILImage(im): try: return isinstance(im,Image.Image) except ImportError: return 0 class ImageReader(object): "Wraps up either PIL or Java to get data f...
2
2010-02-09T10:38:07Z
[ "python", "python-imaging-library", "reportlab" ]
ReportLab and Python Imaging Library images from memory issue
2,227,493
<p>I've run into an issue I can't seem to figure out with PIL and reportlab. Specifically, I would like to use drawImage on a canvas in reportlab using a PIL Image object.</p> <p>In the past I've inserted images into reportlab documents from the web using raw data, StringIO and reportlab's ImageReader class. Unfortuna...
8
2010-02-09T07:41:17Z
2,230,661
<p>Although it does look like it should work, it really doesn't. I finally was able to track down the problem, and it was in the _isPILImage() function. The problem is that "Image.Image" is actually "from PIL import Image" whereas my object is actually just from Image. I would have assumed they were the same, but in an...
4
2010-02-09T16:27:55Z
[ "python", "python-imaging-library", "reportlab" ]
ReportLab and Python Imaging Library images from memory issue
2,227,493
<p>I've run into an issue I can't seem to figure out with PIL and reportlab. Specifically, I would like to use drawImage on a canvas in reportlab using a PIL Image object.</p> <p>In the past I've inserted images into reportlab documents from the web using raw data, StringIO and reportlab's ImageReader class. Unfortuna...
8
2010-02-09T07:41:17Z
19,102,556
<p>weired the documentation claims that drawImage and drawInlineImage work the same way, but it works with drawInlineImage out of the box, and do not work in drawImage</p>
0
2013-09-30T19:49:34Z
[ "python", "python-imaging-library", "reportlab" ]
Group and stack tuples
2,227,532
<p>I'm just starting with Python, and I can't figure out how to group tuples.</p> <p>For instance, I have <code>tuple1=("A", "B", "C")</code> and <code>tuple2=("1","2","3")</code>. I want to combine these into a list, grouped by the first tuple. I want it to appear stacked, as in A1 A2 A3 on one line, and B1 B2 B3 on ...
2
2010-02-09T07:52:29Z
2,227,566
<pre><code>&gt;&gt;&gt; t1 = ("A", "B", "C") &gt;&gt;&gt; t2 = ("1", "2", "3") &gt;&gt;&gt; [x + y for x in t1 for y in t2] ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3'] &gt;&gt;&gt; [[x + y for y in t2] for x in t1] [['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']] &gt;&gt;&gt; x = _ # assign x to...
3
2010-02-09T07:58:29Z
[ "python", "list" ]
Group and stack tuples
2,227,532
<p>I'm just starting with Python, and I can't figure out how to group tuples.</p> <p>For instance, I have <code>tuple1=("A", "B", "C")</code> and <code>tuple2=("1","2","3")</code>. I want to combine these into a list, grouped by the first tuple. I want it to appear stacked, as in A1 A2 A3 on one line, and B1 B2 B3 on ...
2
2010-02-09T07:52:29Z
2,227,593
<p>I'm not exacly sure what your problem is precisely, but do you mean the following?</p> <pre><code>for x in ("A", "B", "C"): print [x + y for y in ("1", "2", "3")] </code></pre> <p>What do you mean by stacked?</p>
1
2010-02-09T08:04:16Z
[ "python", "list" ]
What are features considerd as advanced python?
2,227,537
<p>I do basic python programming and now I want to get deep into language features. I have collected/considered the following to be advanced python capabilities and learning them now. </p> <ol> <li>Decorator</li> <li>Iterator</li> <li>Generator</li> <li>Meta Class</li> </ol> <p>Anything else to be added/considered to...
5
2010-02-09T07:53:20Z
2,227,560
<p>The first 3 are intermediate Python, not advanced. For advanced add the stuff in the <a href="http://docs.python.org/library/modules.html" rel="nofollow">Importing Modules</a> and <a href="http://docs.python.org/library/language.html" rel="nofollow">Python Language Services</a> sections of the library reference.</p>...
1
2010-02-09T07:57:46Z
[ "python" ]
What are features considerd as advanced python?
2,227,537
<p>I do basic python programming and now I want to get deep into language features. I have collected/considered the following to be advanced python capabilities and learning them now. </p> <ol> <li>Decorator</li> <li>Iterator</li> <li>Generator</li> <li>Meta Class</li> </ol> <p>Anything else to be added/considered to...
5
2010-02-09T07:53:20Z
2,227,567
<p>First, this thread should be community wiki.</p> <p>Second, iterators and generators are pretty basic Python IMHO. I agree with you on decorators and metaclasses. But I'm not a very good programmer, so I probably find this more difficult to wrap my brain around than others.</p> <p>Third, I would add threading/mult...
2
2010-02-09T07:58:51Z
[ "python" ]
What are features considerd as advanced python?
2,227,537
<p>I do basic python programming and now I want to get deep into language features. I have collected/considered the following to be advanced python capabilities and learning them now. </p> <ol> <li>Decorator</li> <li>Iterator</li> <li>Generator</li> <li>Meta Class</li> </ol> <p>Anything else to be added/considered to...
5
2010-02-09T07:53:20Z
2,227,955
<p>There are some useful core concepts that can be added to your list, and that I would not necessarily teach in an introductory Python class (from the most common to the more specific):</p> <ul> <li>the <a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">various protocols</a> (sequence, iterator,...
2
2010-02-09T09:26:55Z
[ "python" ]
What are features considerd as advanced python?
2,227,537
<p>I do basic python programming and now I want to get deep into language features. I have collected/considered the following to be advanced python capabilities and learning them now. </p> <ol> <li>Decorator</li> <li>Iterator</li> <li>Generator</li> <li>Meta Class</li> </ol> <p>Anything else to be added/considered to...
5
2010-02-09T07:53:20Z
2,229,792
<p>I think you'll find that there isn't a good answer to your question. What's great about Python is that all of its features are fairly easy to understand. But there's enough stuff in the language and the library that you never get around to learning it all. So it really boils down to which you've had occasion to u...
1
2010-02-09T14:34:39Z
[ "python" ]
cross-platform html widget for pygtk
2,227,770
<p>I'm trying to write a small gui app in pygtk which needs an html-rendering widget. I'd like to be able to use it in a windows environment.</p> <p>Currently I'm using pywebkitgtk on my GNU/Linux system, and it works extremely well, but it seems it's not possible to use this on Windows at this time.</p> <p>Can anyo...
0
2010-02-09T08:48:47Z
2,227,957
<p>In my experience, having developed cross-platform applications with both PyQt and PyGTK, you should consider moving to PyQt. It comes with a browser widget by default which runs fine on all platforms, and support for non-Linux platforms is outstanding compared to PyGTK. For PyGTK, you will have to be prepared buildi...
2
2010-02-09T09:27:15Z
[ "python", "cross-platform", "pyqt", "pygtk", "html-rendering" ]
cross-platform html widget for pygtk
2,227,770
<p>I'm trying to write a small gui app in pygtk which needs an html-rendering widget. I'd like to be able to use it in a windows environment.</p> <p>Currently I'm using pywebkitgtk on my GNU/Linux system, and it works extremely well, but it seems it's not possible to use this on Windows at this time.</p> <p>Can anyo...
0
2010-02-09T08:48:47Z
2,228,268
<p>There is also <a href="http://www.mail-archive.com/pygtk@daa.com.au/msg16368.html" rel="nofollow">gtkhtml2</a>, but might not solve your problem on Windows. I haven't used it before myself. Another option to consider is pymozembed, to embed a Mozilla browser window in your GTK app.</p>
0
2010-02-09T10:20:43Z
[ "python", "cross-platform", "pyqt", "pygtk", "html-rendering" ]
How to retrieve attributes of xml tag in Python?
2,228,049
<p>hello<br> I'm looking for a way to add attributes to xml tags in python. Or to create a new tag with a new attributes for example, I have the following xml file:</p> <pre><code>&lt;types name='character' shortName='chrs'&gt; .... ... &lt;/types&gt; </code></pre> <p>and i want to add an attribute to make it look ...
2
2010-02-09T09:40:46Z
2,228,087
<p>It would seem that you just call <code>setAttribute</code> for the parsed dom objects.</p> <p><a href="http://developer.taboca.com/cases/en/creating_a_new_xml_document_with_python/" rel="nofollow">http://developer.taboca.com/cases/en/creating_a_new_xml_document_with_python/</a></p>
0
2010-02-09T09:47:04Z
[ "python", "xml", "tags" ]
How to retrieve attributes of xml tag in Python?
2,228,049
<p>hello<br> I'm looking for a way to add attributes to xml tags in python. Or to create a new tag with a new attributes for example, I have the following xml file:</p> <pre><code>&lt;types name='character' shortName='chrs'&gt; .... ... &lt;/types&gt; </code></pre> <p>and i want to add an attribute to make it look ...
2
2010-02-09T09:40:46Z
2,228,109
<p>You can use the <a href="http://docs.python.org/library/xml.dom.html#xml.dom.Node.attributes" rel="nofollow">attributes</a> property of the respective <code>Node</code> object.</p> <p>For example:</p> <pre><code>from xml.dom.minidom import parseString documentNode = parseString("&lt;types name='character' shortNam...
5
2010-02-09T09:49:58Z
[ "python", "xml", "tags" ]
How to retrieve attributes of xml tag in Python?
2,228,049
<p>hello<br> I'm looking for a way to add attributes to xml tags in python. Or to create a new tag with a new attributes for example, I have the following xml file:</p> <pre><code>&lt;types name='character' shortName='chrs'&gt; .... ... &lt;/types&gt; </code></pre> <p>and i want to add an attribute to make it look ...
2
2010-02-09T09:40:46Z
2,228,152
<p>I learned xml parsing in python from <a href="http://www.boddie.org.uk/python/XML_intro.html" rel="nofollow">this great article</a>. It has an attribute section, which cant be linked to, but just search for "<em>Attributes</em>" on that page and you'll find it, that holds the information you need.</p> <p>But in sho...
1
2010-02-09T09:56:51Z
[ "python", "xml", "tags" ]
how can i pass xml format data from flex to python
2,228,078
<p>Hi i want to pass xml format data into python from flex.i know how to pass from flex but my question is how can i get the passed data in python and then the data should be inserted into mysql.and aslo i want to retrieve the mysql data to the python(cgi),the python should convert all the data into xml format,and pass...
1
2010-02-09T09:45:56Z
2,231,841
<p>See <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208528" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=208528</a> for more details, here is a breif overview of what I think you are looking for.</p> <p>The SimpleXMLRPCServer library allows you to easily create a server. Here's about ...
1
2010-02-09T19:25:16Z
[ "python", "mysql", "flex3" ]
A blackbox testing frame with testing management system
2,228,349
<p>Is there a testing framework (preferable python) that executes test, monitor the progress (failed/passed/timeout) and controls the vmware? Thanks</p> <p>I am trying to make some automation functional testing in Vmware using Autoit script, VMs are controlled by a little python script on the host machine (deploy test...
2
2010-02-09T10:36:38Z
2,228,538
<p>There are lots of continuous integration tools that may do what you want.</p> <p>One implemented in Python that may fit your need is <a href="http://buildbot.net/trac" rel="nofollow">Buildbot</a> - it can manage running builds and tests across multiple machines and consolidating the results.</p>
2
2010-02-09T11:10:01Z
[ "python", "testing", "frameworks", "vmware" ]
How to transform tuple of string(object locations) to dictionary of objects in python
2,228,750
<p>I would like to transform a tuple:</p> <pre><code>TEST_CLASSES = ( 'common.test.TestClass', ) </code></pre> <p>to</p> <pre><code>TEST_CLASSES = { 'test': common.test.TestClass, } </code></pre> <p>How to make a dictionary is simple but I have a problem with conversion from string to object. Could anybody he...
0
2010-02-09T11:47:20Z
2,228,775
<p>You could use <a href="http://docs.python.org/library/functions.html#eval" rel="nofollow"><code>eval</code></a>, which can be <strong>evil</strong> if your inputs are not safe:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; eval('os.path.join') &lt;function join at 0x00BBA2B8&gt; </code></pre> <p>if the <code>...
1
2010-02-09T11:51:40Z
[ "python" ]
How to transform tuple of string(object locations) to dictionary of objects in python
2,228,750
<p>I would like to transform a tuple:</p> <pre><code>TEST_CLASSES = ( 'common.test.TestClass', ) </code></pre> <p>to</p> <pre><code>TEST_CLASSES = { 'test': common.test.TestClass, } </code></pre> <p>How to make a dictionary is simple but I have a problem with conversion from string to object. Could anybody he...
0
2010-02-09T11:47:20Z
2,228,797
<p>As far as I understand, you try to get class by its string name. There was a similar question: <a href="http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class">http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class</a></p>
0
2010-02-09T11:55:13Z
[ "python" ]
How to transform tuple of string(object locations) to dictionary of objects in python
2,228,750
<p>I would like to transform a tuple:</p> <pre><code>TEST_CLASSES = ( 'common.test.TestClass', ) </code></pre> <p>to</p> <pre><code>TEST_CLASSES = { 'test': common.test.TestClass, } </code></pre> <p>How to make a dictionary is simple but I have a problem with conversion from string to object. Could anybody he...
0
2010-02-09T11:47:20Z
2,228,803
<p>You can't directly "convert from string to object" (though in a technical sense, strings are objects), but you can use a function that can import the objects for you. Werkzeug's <code>werkzeug.utils</code> module has a function in it named <code>import_string</code> that does just that (<a href="http://bitbucket.org...
0
2010-02-09T11:56:27Z
[ "python" ]
How to transform tuple of string(object locations) to dictionary of objects in python
2,228,750
<p>I would like to transform a tuple:</p> <pre><code>TEST_CLASSES = ( 'common.test.TestClass', ) </code></pre> <p>to</p> <pre><code>TEST_CLASSES = { 'test': common.test.TestClass, } </code></pre> <p>How to make a dictionary is simple but I have a problem with conversion from string to object. Could anybody he...
0
2010-02-09T11:47:20Z
2,229,183
<p>The straightforward and oftenly not recomended way there is to use "eval".</p> <p>Simply doing:</p> <pre><code>obj = eval('common.test.TestClass') </code></pre> <p>Will give you the object as specified on the string.</p> <p>Other, more elegant ways, would involve querying each object on the chain for the next a...
0
2010-02-09T13:05:34Z
[ "python" ]
Why does Pylint give error E0702, raising NoneType, on this raise statement?
2,228,790
<p>Say I have the following code.</p> <pre><code>def foo(): foobar = None if foobar is not None: raise foobar </code></pre> <p>When I run this code through pylint, I get the following error:</p> <pre><code>E0702:4:foo: Raising NoneType while only classes, instances or string are allowed </code></pre>...
7
2010-02-09T11:54:23Z
2,228,811
<p>It's <strong><a href="http://www.logilab.org/ticket/3207">a known bug</a></strong>. Pylint doesn't do a lot of flow-control inferencing.</p>
11
2010-02-09T11:57:47Z
[ "python", "exception", "pylint" ]
Why does Pylint give error E0702, raising NoneType, on this raise statement?
2,228,790
<p>Say I have the following code.</p> <pre><code>def foo(): foobar = None if foobar is not None: raise foobar </code></pre> <p>When I run this code through pylint, I get the following error:</p> <pre><code>E0702:4:foo: Raising NoneType while only classes, instances or string are allowed </code></pre>...
7
2010-02-09T11:54:23Z
2,229,493
<p>Luckily you can tell pylint that you know better than it does:</p> <pre><code>def foo(): foobar = None if foobar is not None: raise foobar # pylint: disable-msg=E0702 </code></pre>
6
2010-02-09T13:52:11Z
[ "python", "exception", "pylint" ]
Python Authentication to SAMBA share
2,228,846
<p>I'm able to map the drive without problems on network shares without authentication. But I'm missing something once I try to authenticate with a username and password. Here is the current working example of the code with the error message I keep receiving.</p> <pre><code>#!/usr/bin/python # Drive Map Script import ...
3
2010-02-09T12:07:59Z
2,228,896
<p>You aren't passing <code>user_name</code> and <code>user_pass</code> to <code>MapNetworkDrive</code>. Try this instead:</p> <pre><code>testnetwork.MapNetworkDrive(drive_letter, network_path, True, user_name, user_pass) </code></pre> <p>Note: the <code>True</code> passed there is a flag that indicates whether the m...
2
2010-02-09T12:18:28Z
[ "python" ]
Using unicode in Python
2,228,953
<p>I have csv file having some address data mostly in Finnish language. I need to read that file and getting some geocode information of these address. But It doesn't work for Finnish alphabet and says it cant read those! Can anybody please help me out of this?</p> <pre><code>import urllib,urllib2,time addr_file = 'a...
1
2010-02-09T12:27:53Z
2,228,975
<p>I don't know Python, but I'm pretty sure this is an encoding issue.</p> <p>Make sure your address file is UTF-8 encoded and that <code>urlencode()</code> function you use can deal with UTF-8 characters (the latter shouldn't be a problem though, as Python can handle UTF-8 natively as far as I know).</p>
0
2010-02-09T12:33:11Z
[ "python", "unicode" ]
Using unicode in Python
2,228,953
<p>I have csv file having some address data mostly in Finnish language. I need to read that file and getting some geocode information of these address. But It doesn't work for Finnish alphabet and says it cant read those! Can anybody please help me out of this?</p> <pre><code>import urllib,urllib2,time addr_file = 'a...
1
2010-02-09T12:27:53Z
2,229,032
<p>Use the <a href="http://docs.python.org/library/codecs.html#module-codecs" rel="nofollow"><code>codecs</code></a> module.</p> <p><a href="http://docs.python.org/library/codecs.html#codecs.open" rel="nofollow"><code>codecs.open()</code></a>:</p> <blockquote> <p><code>codecs.open(filename, mode[, encoding[, errors...
0
2010-02-09T12:43:41Z
[ "python", "unicode" ]
Using unicode in Python
2,228,953
<p>I have csv file having some address data mostly in Finnish language. I need to read that file and getting some geocode information of these address. But It doesn't work for Finnish alphabet and says it cant read those! Can anybody please help me out of this?</p> <pre><code>import urllib,urllib2,time addr_file = 'a...
1
2010-02-09T12:27:53Z
2,229,067
<p>The argument of <a href="http://docs.python.org/library/urllib.html#urllib.urlencode" rel="nofollow">urllib.url</a> should be UTF-8 encoded beforehand:</p> <pre><code>addr_file = addr_file.encode("utf-8") values = {'q' : addr_file, 'output':out_fmt, 'key':gkey} data = urllib.urlencode(values) </code></pre> <p>And ...
1
2010-02-09T12:49:20Z
[ "python", "unicode" ]
Using unicode in Python
2,228,953
<p>I have csv file having some address data mostly in Finnish language. I need to read that file and getting some geocode information of these address. But It doesn't work for Finnish alphabet and says it cant read those! Can anybody please help me out of this?</p> <pre><code>import urllib,urllib2,time addr_file = 'a...
1
2010-02-09T12:27:53Z
2,229,290
<p>You need to open file <strong>using the correct encoding using the <a href="http://docs.python.org/library/codecs.html" rel="nofollow">codecs</a> module</strong>. The correct encoding for Finnish is probably <strong><a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1" rel="nofollow">ISO-8859-1</a></strong></p> <pr...
0
2010-02-09T13:21:24Z
[ "python", "unicode" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,228,989
<p>That's not how Django works. Do the tutorial, you'll save a lot of time and frustration.</p>
0
2010-02-09T12:36:45Z
[ "python", "django" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,229,018
<blockquote> <p>I have python scripts which provides output and I need to have this output on the web.</p> </blockquote> <p>What is Django for? Use either CGI script on python (probably you already have one) or WSGI application (which is a bit harder to deploy)</p>
0
2010-02-09T12:40:45Z
[ "python", "django" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,229,044
<p>Django is a frame work. Just use CGI scripts.</p>
0
2010-02-09T12:45:17Z
[ "python", "django" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,229,080
<blockquote> <p>"I have python scripts which provides output and I need to have this output on the web."</p> </blockquote> <p>That is not what Django is for. What you want to do can be achieved with something as simple as this:</p> <pre><code>from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class ...
4
2010-02-09T12:51:23Z
[ "python", "django" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,229,101
<p>Everyone is right. This is the wrong way to use django. However, if you need a stop-gap measure while you convert your script to the proper idiom:</p> <pre><code>import sys from django.http import HttpResponse def cgi_view(request, my_module): __import__(my_module) mod = sys.modules[my_module] text =...
1
2010-02-09T12:54:16Z
[ "python", "django" ]
Python Django simple site
2,228,966
<p>I'm trying to create site using Django framework. I looked on tutorial on Django project site but contains much information which I don't need. I have python scripts which provides output and I need to have this output on the web. My question is how simply manage Django to have link which start the script and provid...
4
2010-02-09T12:30:13Z
2,229,608
<p>Use mod_wsgi plugin to Apache.</p> <p>You can do this to see how an existing script might be transformed into a WSGI application. This is a starting point, to show how the WSGI interface works.</p> <pre><code>import sys def myWSGIApp( environ, start_response ): with file( "temp", "w" ) as output: sys....
1
2010-02-09T14:08:55Z
[ "python", "django" ]
Python CDROM Production
2,228,988
<p>I have been using Macromedia / Adobe Director &amp; Lingo since 1998. I am extremely familiar with using this software to create CDROMs and DVDs and also have a good knowledge of design elements and their integration such as flash videos, images &amp; audio etc.</p> <p>I am always keen to explore other technologies...
0
2010-02-09T12:36:03Z
2,228,998
<p>It sounds like you're not asking so much for mass-copying of CDs/DVDs (which is what I assumed from reading the title), but for a Python-based replacement for Adobe Director? I don't think anything like that presently exists.</p> <p>However, Python could certainly help you out with the scripting and control of vari...
0
2010-02-09T12:38:27Z
[ "python", "adobe", "media", "dvd", "cd-rom" ]
Python CDROM Production
2,228,988
<p>I have been using Macromedia / Adobe Director &amp; Lingo since 1998. I am extremely familiar with using this software to create CDROMs and DVDs and also have a good knowledge of design elements and their integration such as flash videos, images &amp; audio etc.</p> <p>I am always keen to explore other technologies...
0
2010-02-09T12:36:03Z
2,229,000
<p><strong>sounds grim to me</strong> </p> <p>I presume you mean an auto-run executable for Windows that runs when a CDROM is inserted, to provide some sort of flashy popup experience thing.</p> <p>I would stick with flash. You <a href="http://www.py2exe.org/" rel="nofollow">can make Python executables</a>, and you ...
1
2010-02-09T12:38:36Z
[ "python", "adobe", "media", "dvd", "cd-rom" ]
Python CDROM Production
2,228,988
<p>I have been using Macromedia / Adobe Director &amp; Lingo since 1998. I am extremely familiar with using this software to create CDROMs and DVDs and also have a good knowledge of design elements and their integration such as flash videos, images &amp; audio etc.</p> <p>I am always keen to explore other technologies...
0
2010-02-09T12:36:03Z
2,229,023
<p>Python isn't the tool you are looking for... [waves hand across in front of Mindblip's face]</p> <p>Stick with Director or try Flash with either MPlayer or Zinc.</p>
1
2010-02-09T12:42:32Z
[ "python", "adobe", "media", "dvd", "cd-rom" ]
Django ModelForm with extra fields that are not in the model
2,229,039
<p>I have done a ModelForm adding some extra fields that <strong>are not</strong> in the model. I use these fields for some calcualtions when saving the form.</p> <p>The extra fields appear on the form and they are sent in the POST request when uploading the form. The problem is they are not added to the <code>cleaned...
12
2010-02-09T12:44:41Z
2,229,319
<p>Ok I have resolved it. It seems that accessing the extra fields with cleaned_data['field_name'] raises a KeyError but using cleaned_data.get('field_name') works. That's weird because normal fields for the model can be accessed via cleaned_data['field_name'].</p> <p><strong>Update:</strong> No, it doesn't work. With...
1
2010-02-09T13:27:24Z
[ "python", "django", "forms" ]
Django ModelForm with extra fields that are not in the model
2,229,039
<p>I have done a ModelForm adding some extra fields that <strong>are not</strong> in the model. I use these fields for some calcualtions when saving the form.</p> <p>The extra fields appear on the form and they are sent in the POST request when uploading the form. The problem is they are not added to the <code>cleaned...
12
2010-02-09T12:44:41Z
2,230,669
<p>First, you shouldn't have artist_id and artist fields. They are build from the model. If you need some artist name, add artist_name field, that is <strong>CharField</strong>.</p> <p>Furthermore, you are trying to retrieve something from cleaned_data inside clean value. There might not be data you need - you should ...
5
2010-02-09T16:28:45Z
[ "python", "django", "forms" ]
Django ModelForm with extra fields that are not in the model
2,229,039
<p>I have done a ModelForm adding some extra fields that <strong>are not</strong> in the model. I use these fields for some calcualtions when saving the form.</p> <p>The extra fields appear on the form and they are sent in the POST request when uploading the form. The problem is they are not added to the <code>cleaned...
12
2010-02-09T12:44:41Z
23,353,332
<p>It's possible to extend Django <code>ModelForm</code> with extra fields. Imagine you have a custom User model and this <code>ModelForm</code>:</p> <pre><code>class ProfileForm(forms.ModelForm): class Meta: model = User fields = ['username', 'country', 'website', 'biography'] </code></pre> <p>N...
5
2014-04-29T00:13:52Z
[ "python", "django", "forms" ]
Django ModelForm with extra fields that are not in the model
2,229,039
<p>I have done a ModelForm adding some extra fields that <strong>are not</strong> in the model. I use these fields for some calcualtions when saving the form.</p> <p>The extra fields appear on the form and they are sent in the POST request when uploading the form. The problem is they are not added to the <code>cleaned...
12
2010-02-09T12:44:41Z
29,380,296
<p>This answer may be too late for the original poster, but I thought it might help others. I had the same problem and I did notice that self.cleaned_data('artist_id') can be accessed in the clean() method, but not in the clean_artist(). </p> <p>When I added the extra fields in the 'fields' declaration of Meta, then ...
3
2015-03-31T23:29:52Z
[ "python", "django", "forms" ]
Is there an alternative to the threading.Condition variables in python that better support timeouts without polling?
2,229,086
<p>I'm using condition variables in threads that require a timeout. I didn't notice until I saw the CPU usage when having a lot of threads running, that the condition variable provided in the threading module doesn't actually sleep, but polls when a timeout is provided as an argument.</p> <p>Is there an alternative to...
3
2010-02-09T12:52:43Z
2,229,350
<p>I'm not familiar with Python, but if you are able to block on a condition variable (without a timeout), you could implement the timeout yourself. Let the blocking thread store the time it began blocking and set a timer to signal it. When it wakes, check the time elapsed for a timeout. This isn't a very good way to d...
1
2010-02-09T13:31:13Z
[ "python", "multithreading", "condition-variable" ]
Is there an alternative to the threading.Condition variables in python that better support timeouts without polling?
2,229,086
<p>I'm using condition variables in threads that require a timeout. I didn't notice until I saw the CPU usage when having a lot of threads running, that the condition variable provided in the threading module doesn't actually sleep, but polls when a timeout is provided as an argument.</p> <p>Is there an alternative to...
3
2010-02-09T12:52:43Z
2,231,023
<p>This seems tricky to do in Python, but here is a one solution. It relies on spawning additional threads but doesn't use polling AND ensures that the original thread is woken up as soon as the timeout expires or as soon as the original wait() returns.</p> <p>Note: The following code includes a test case which tests...
3
2010-02-09T17:22:01Z
[ "python", "multithreading", "condition-variable" ]
Python MD5 not matching md5 in terminal
2,229,298
<p>Hey guys, am getting MD5 of several files using python function </p> <pre><code>filehash = hashlib.md5(file) print "FILE HASH: " + filehash.hexdigest() </code></pre> <p>though when I go to the terminal and do a </p> <pre><code>md5 file </code></pre> <p>the result I'm getting is not the same my python script is o...
3
2010-02-09T13:22:54Z
2,229,309
<p>hashlib.md5() takes the contents of the file not its name.</p> <p>See <a href="http://docs.python.org/library/hashlib.html">http://docs.python.org/library/hashlib.html</a></p> <p>You need to open the file, and read its contents before hashing it.</p> <pre><code>f = open(filename,'rb') m = hashlib.md5() while True...
21
2010-02-09T13:25:23Z
[ "python", "hash", "md5" ]
Python MD5 not matching md5 in terminal
2,229,298
<p>Hey guys, am getting MD5 of several files using python function </p> <pre><code>filehash = hashlib.md5(file) print "FILE HASH: " + filehash.hexdigest() </code></pre> <p>though when I go to the terminal and do a </p> <pre><code>md5 file </code></pre> <p>the result I'm getting is not the same my python script is o...
3
2010-02-09T13:22:54Z
2,229,313
<p>what is <code>file</code>? it should equal to <code>open(filename, 'rb').read()</code>. is it?</p>
1
2010-02-09T13:25:42Z
[ "python", "hash", "md5" ]
Python MD5 not matching md5 in terminal
2,229,298
<p>Hey guys, am getting MD5 of several files using python function </p> <pre><code>filehash = hashlib.md5(file) print "FILE HASH: " + filehash.hexdigest() </code></pre> <p>though when I go to the terminal and do a </p> <pre><code>md5 file </code></pre> <p>the result I'm getting is not the same my python script is o...
3
2010-02-09T13:22:54Z
2,229,320
<p>Try this</p> <pre><code>filehash = hashlib.md5(open('filename','rb').read()) print "FILE HASH: " + filehash.hexdigest() </code></pre>
3
2010-02-09T13:27:29Z
[ "python", "hash", "md5" ]
Python MD5 not matching md5 in terminal
2,229,298
<p>Hey guys, am getting MD5 of several files using python function </p> <pre><code>filehash = hashlib.md5(file) print "FILE HASH: " + filehash.hexdigest() </code></pre> <p>though when I go to the terminal and do a </p> <pre><code>md5 file </code></pre> <p>the result I'm getting is not the same my python script is o...
3
2010-02-09T13:22:54Z
2,229,345
<pre><code>$ md5 test.py MD5 (test.py) = 04523172fa400cb2d45652d818103ac3 $ python Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import hashlib &gt;&gt;&gt; s = open('test.py','rb').read...
6
2010-02-09T13:30:52Z
[ "python", "hash", "md5" ]
Dynamic form requirements in Django
2,229,427
<p>I am about to start a large Django project at work. And the key features are form handling. There is going to be a lot of forms that the users of the app is going to use. And one requirement is that it should be possible to edit the forms in the admin interface of the application.</p> <p>That is, it is not a requi...
3
2010-02-09T13:41:41Z
2,229,553
<p>You should use certain models for this. For every form that might be customised this way, a new database entry must be created. I guess, it should look like this:</p> <pre><code>class FormSettings(Model): form = CharField(..) class FormAttrib(Model): form_settings = ForeignKey(FormSettings) field = CharField...
2
2010-02-09T13:59:55Z
[ "python", "django", "forms" ]
Dynamic form requirements in Django
2,229,427
<p>I am about to start a large Django project at work. And the key features are form handling. There is going to be a lot of forms that the users of the app is going to use. And one requirement is that it should be possible to edit the forms in the admin interface of the application.</p> <p>That is, it is not a requi...
3
2010-02-09T13:41:41Z
2,230,358
<p>This isn't an exact answer to your problem, but I did something similar which I thought might be of use to you. I created an entirely customizable form, so that the form can be customized by end users.</p> <p>I ended up with 2 models, a <code>BuiltForm</code> and a <code>BuiltFormField</code>:</p> <pre><code>clas...
2
2010-02-09T15:53:12Z
[ "python", "django", "forms" ]
What algorithm does buildbot use to assign builders to slaves?
2,229,481
<p>I have a buildbot with some builders and two slave machines.</p> <p>Some of the builders can run on one slave, and some of them can run on both machines.</p> <p>What algorithm will buildbot use to schedule the builds? Will it notice that some builders can run on just one slave and that it should assign those that ...
6
2010-02-09T13:50:11Z
2,323,336
<p>First it gets a list of all the slaves attached to that builder. Then it picks one <em>at random</em>. If the slave is already running more than <code>slave.max_builds</code> builds, it picks another.</p> <p>You can override the <code>nextSlave</code> method on the <code>Builder</code> to change the way slaves are ...
9
2010-02-24T02:49:18Z
[ "python", "project-management", "build-process", "build-automation", "buildbot" ]
Giving 'hints' problem
2,229,618
<p>I have a simple word jumble game. I made the jumble already, but now I want to add a 'hint' system. I don't know how to have 1 item from tuples show up. I have 2 tuples, and I want to pull from the 2nd tuple based on the what the first tuple is. I have a <code>WORD=("x", "y", "z")</code> and <code>HINT=("x", "y", "z...
3
2010-02-09T14:10:12Z
2,229,634
<p>Create a dictionary:</p> <pre><code> hints = dict(zip(WORD, HINT)) </code></pre> <p>and then:</p> <pre><code> if guess=='hint': print hints[current_word] </code></pre> <p>Simple <code>if</code> is not enough?</p> <pre><code>if guess != 'hint': print "Sorry, that's not the answer." </code></pre>
3
2010-02-09T14:12:46Z
[ "python", "tuples" ]
Django: Setting one page as the main page
2,229,640
<p>I'm a newbie at Django and I want to do something that I'm not sure how to do.</p> <p>I have a model SimplePage, which simply stands for a webpage that is visible on the website and whose contents can be edited in the admin. (I think this is similar to FlatPage.)</p> <p>So I have a bunch of SimplePages for my site...
0
2010-02-09T14:13:16Z
2,229,654
<p>Create MAIN_PAGE setting inside settings.py with primary key. Then create view main_page nad retrieve the main_page object from the database using the setting.</p> <p><strong>EDIT:</strong></p> <p>You can also do it like this: add a model, which will reference a SimplePage and point to the main page. In main page ...
1
2010-02-09T14:15:52Z
[ "python", "django" ]
Django: Setting one page as the main page
2,229,640
<p>I'm a newbie at Django and I want to do something that I'm not sure how to do.</p> <p>I have a model SimplePage, which simply stands for a webpage that is visible on the website and whose contents can be edited in the admin. (I think this is similar to FlatPage.)</p> <p>So I have a bunch of SimplePages for my site...
0
2010-02-09T14:13:16Z
2,230,170
<p>Easiest way to do this would be to create the boolean value, as you suggested and use the <code>pre_save</code> signal to remove the boolean value from everything else in the database.</p> <pre><code>from django.db.models import signals def simple_page_pre_save(sender, instance, **kwargs): if instance.is_main_p...
0
2010-02-09T15:28:15Z
[ "python", "django" ]
Django urlsafe base64 decoding with decryption
2,229,827
<p>I'm writing my own captcha system for user registration. So I need to create a suitable URL for receiving generated captcha pictures. Generation looks like this:</p> <pre><code>_cipher = cipher.new(settings.CAPTCHA_SECRET_KEY, cipher.MODE_ECB) _encrypt_block = lambda block: _cipher.encrypt(block + ' ' * (_cipher.bl...
14
2010-02-09T14:39:17Z
2,230,623
<p>The problem is that b64decode quite explicitly can only take bytes (a string), not unicode.</p> <pre><code>&gt;&gt;&gt; import base64 &gt;&gt;&gt; test = "Hi, I'm a string" &gt;&gt;&gt; enc = base64.urlsafe_b64encode(test) &gt;&gt;&gt; enc 'SGksIEknbSBhIHN0cmluZw==' &gt;&gt;&gt; uenc = unicode(enc) &gt;&gt;&gt; bas...
29
2010-02-09T16:23:04Z
[ "python", "django", "encryption", "encoding", "base64" ]
Django urlsafe base64 decoding with decryption
2,229,827
<p>I'm writing my own captcha system for user registration. So I need to create a suitable URL for receiving generated captcha pictures. Generation looks like this:</p> <pre><code>_cipher = cipher.new(settings.CAPTCHA_SECRET_KEY, cipher.MODE_ECB) _encrypt_block = lambda block: _cipher.encrypt(block + ' ' * (_cipher.bl...
14
2010-02-09T14:39:17Z
2,230,689
<p>I solved the problem! </p> <pre><code>deserialized = pickle.loads(captcha_decrypt(urlsafe_b64decode(key.encode('ascii')))) return HttpResponse(str(deserialized)) </code></pre> <p>But still I don't understand, why it didn't work first time.</p>
2
2010-02-09T16:31:19Z
[ "python", "django", "encryption", "encoding", "base64" ]
How to fetch an email body using imaplib in python?
2,230,037
<p>I'd like to fetch the whole message from IMAP4 server. In python docs if found this bit of code that works:</p> <pre><code>&gt;&gt;&gt; t, data = M.fetch('1', '(RFC822)') &gt;&gt;&gt; body = data[0][1] </code></pre> <p>I'm wondering if I can always trust that data[0][1] returns the body of the message. When I've r...
10
2010-02-09T15:10:14Z
2,230,571
<p>No... <code>imaplib</code> is a pretty good library, it's imap that's so unintelligible.</p> <p>You may wish to check that <code>t == 'OK'</code>, but <code>data[0][1]</code> works as expected for as much as I've used it.</p> <p>Here's a quick example I use to extract signed certificates I've received by email, no...
11
2010-02-09T16:16:54Z
[ "python", "imaplib" ]
How to fetch an email body using imaplib in python?
2,230,037
<p>I'd like to fetch the whole message from IMAP4 server. In python docs if found this bit of code that works:</p> <pre><code>&gt;&gt;&gt; t, data = M.fetch('1', '(RFC822)') &gt;&gt;&gt; body = data[0][1] </code></pre> <p>I'm wondering if I can always trust that data[0][1] returns the body of the message. When I've r...
10
2010-02-09T15:10:14Z
2,231,047
<p>The <a href="http://pypi.python.org/pypi/IMAPClient/" rel="nofollow">IMAPClient</a> package is a fair bit easier to work with. From the description:</p> <blockquote> <p>Easy-to-use, Pythonic and complete IMAP client library.</p> </blockquote>
7
2010-02-09T17:27:38Z
[ "python", "imaplib" ]
How to fetch an email body using imaplib in python?
2,230,037
<p>I'd like to fetch the whole message from IMAP4 server. In python docs if found this bit of code that works:</p> <pre><code>&gt;&gt;&gt; t, data = M.fetch('1', '(RFC822)') &gt;&gt;&gt; body = data[0][1] </code></pre> <p>I'm wondering if I can always trust that data[0][1] returns the body of the message. When I've r...
10
2010-02-09T15:10:14Z
38,744,340
<p>This was my solution to extract the useful bits of information. It's been reliable so far:</p> <pre><code>import datetime import email import imaplib import mailbox EMAIL_ACCOUNT = "your@gmail.com" PASSWORD = "your password" mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login(EMAIL_ACCOUNT, PASSWORD) mail.lis...
0
2016-08-03T12:56:53Z
[ "python", "imaplib" ]
Python, next iteration of the loop over a loop
2,230,244
<p>I need to get the next item of the first loop given certain condition, but the condition is in the inner loop. Is there a shorter way to do it than this? (test code)</p> <pre><code> ok = 0 for x in range(0,10): if ok == 1: ok = 0 continue for y in range(0,20): ...
10
2010-02-09T15:38:58Z
2,230,285
<p>You can always transform into a while loop:</p> <pre><code>flag = False for x in range(0, 10): if x == 4: flag = True continue </code></pre> <p>becomes</p> <pre><code>x = 0 while (x != 4) and x &lt; 10: x += 1 flag = x &lt; 10 </code></pre> <p>Not necessary simpler, but nicer imho.</p>
2
2010-02-09T15:44:36Z
[ "python" ]
Python, next iteration of the loop over a loop
2,230,244
<p>I need to get the next item of the first loop given certain condition, but the condition is in the inner loop. Is there a shorter way to do it than this? (test code)</p> <pre><code> ok = 0 for x in range(0,10): if ok == 1: ok = 0 continue for y in range(0,20): ...
10
2010-02-09T15:38:58Z
2,230,304
<p>Replace the <code>continue</code> in the inner loop with a <code>break</code>. What you want to do is to actually break out of the inner loop, so a <code>continue</code> there does the opposite of what you want.</p> <pre><code>ok = 0 for x in range(0,10): print "x=",x if ok == 1: ok = 0 cont...
6
2010-02-09T15:47:55Z
[ "python" ]
Python, next iteration of the loop over a loop
2,230,244
<p>I need to get the next item of the first loop given certain condition, but the condition is in the inner loop. Is there a shorter way to do it than this? (test code)</p> <pre><code> ok = 0 for x in range(0,10): if ok == 1: ok = 0 continue for y in range(0,20): ...
10
2010-02-09T15:38:58Z
2,230,496
<p>Your example code is equivalent to (that doesn't seem what you want):</p> <pre><code>for x in range(0, 10, 2): for y in range(20): if y == 5: continue </code></pre> <p>To skip to the next item without using <code>continue</code> in the outer loop:</p> <pre><code>it = iter(range(10)) for x ...
2
2010-02-09T16:09:21Z
[ "python" ]
Python, next iteration of the loop over a loop
2,230,244
<p>I need to get the next item of the first loop given certain condition, but the condition is in the inner loop. Is there a shorter way to do it than this? (test code)</p> <pre><code> ok = 0 for x in range(0,10): if ok == 1: ok = 0 continue for y in range(0,20): ...
10
2010-02-09T15:38:58Z
2,230,724
<p>So you're not after something like this? I'm assuming that you're looping through the keys to a dictionary, rather than the values, going by your example.</p> <pre><code>for i in range(len(object1.__dict__)): attribute1 = objects1.__dict__.keys()[i] object2 = self.getobject() # Huh? if object2 is not None: ...
0
2010-02-09T16:37:14Z
[ "python" ]
Python, next iteration of the loop over a loop
2,230,244
<p>I need to get the next item of the first loop given certain condition, but the condition is in the inner loop. Is there a shorter way to do it than this? (test code)</p> <pre><code> ok = 0 for x in range(0,10): if ok == 1: ok = 0 continue for y in range(0,20): ...
10
2010-02-09T15:38:58Z
2,230,877
<p>It's not completely clear to me what you want, but if you're testing something for each item produced in the inner loop, <code>any</code> might be what you want (<a href="http://docs.python.org/library/functions.html#any" rel="nofollow">docs</a>)</p> <pre><code>&gt;&gt;&gt; def f(n): return n % 2 ... &gt;&gt;&gt;...
0
2010-02-09T16:59:16Z
[ "python" ]
Mako thinks my template has a 'pass' after an if statement, even though the traceback shows there isn't one
2,230,455
<p>I have Mako taking a template from a preprocessor, and now thinks there is a 'pass' after my if statement.</p> <p>Here is the complete traceback</p> <pre><code>Error ! SyntaxException: (SyntaxError) invalid syntax (, line 1) (u"if ${session['anonymous']}:pass") in file '/.../site/templates/shpaml/views/index.html'...
1
2010-02-09T16:04:43Z
2,231,805
<p>Well, this is one of those embarrassing cases that took days of agony to figure out something so simple:</p> <p>It needed to be </p> <pre><code>if session['anonymous']: </code></pre>
1
2010-02-09T19:20:23Z
[ "python", "syntax-error", "mako" ]
How to get the system library path on Unix (Linux, FreeBSD)
2,230,467
<p>I need a more-or-less portable programmatic way for querying the the dynamic library path list. For Linux, I can concatenate the <code>$LD_LIBRARY_PATH</code> and the contents of <code>/etc/ld.so.conf</code> (processing the <code>include</code> directives as needed and possibly filtering by architecture), but that d...
7
2010-02-09T16:05:41Z
2,230,541
<p>For both Linux and FreeBSD you can try working through the output of <code>ldconfig(8)</code>. The options for listing the libraries are different though (<code>-p</code> on <a href="http://linux.die.net/man/8/ldconfig" rel="nofollow">Linux</a>, <code>-r</code> on <a href="http://www.freebsd.org/cgi/man.cgi?query=ld...
6
2010-02-09T16:13:41Z
[ "python", "linux", "unix", "freebsd", "library-path" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,700
<p>Use <a href="http://docs.python.org/library/xml.sax.html" rel="nofollow">xml.sax</a> module. Build your own handler and inside <a href="http://docs.python.org/library/xml.sax.handler.html#xml.sax.handler.ContentHandler.startElement" rel="nofollow">startElement</a> you should check, whether name is AssetType. This wa...
2
2010-02-09T16:32:42Z
[ "python", "xml" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,705
<p>You could use xpath, something like "//AssetType[longname='characters']/xyz".</p> <p>For XPath libs in Python see <a href="http://www.somebits.com/weblog/tech/python/xpath.html" rel="nofollow">http://www.somebits.com/weblog/tech/python/xpath.html</a></p>
1
2010-02-09T16:34:05Z
[ "python", "xml" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,755
<p>If you don't mind loading the whole document into memory:</p> <pre><code>from lxml import etree data = etree.parse(fname) result = [node.text.strip() for node in data.xpath("//AssetType[@longname='characters']/type")] </code></pre> <p>You may need to remove the spaces at the beginning of your tags to make thi...
2
2010-02-09T16:42:35Z
[ "python", "xml" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,807
<p>You could use the <a href="http://docs.python.org/library/xml.dom.pulldom.html" rel="nofollow">pulldom API</a> to handle parsing a large file, without loading it all into memory at once. This provides a more convenient interface than using SAX with only a slight loss of performance.</p> <p>It basically lets you st...
2
2010-02-09T16:50:11Z
[ "python", "xml" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,854
<p>Similar to eswald's solution, again stripping whitespace, again loading the document into memory, but returning the three text items at a time</p> <pre><code>from lxml import etree data = """&lt;AssetType longname="characters" shortname="chr" shortnames="chrs" &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; ...
1
2010-02-09T16:56:06Z
[ "python", "xml" ]
how to get specific nodes in xml file with python
2,230,677
<p>hello <br> im searching for a way to get a specific tags .. from a very big xml document with python dom built in module <br> for example :<br></p> <pre><code>&lt;AssetType longname="characters" shortname="chr" shortnames="chrs"&gt; &lt;type&gt; pub &lt;/type&gt; &lt;type&gt; geo &lt;/type&gt; &l...
4
2010-02-09T16:29:55Z
2,230,872
<p>Assuming your document is called <code>assets.xml</code> and has the following structure:</p> <pre><code>&lt;assets&gt; &lt;AssetType&gt; ... &lt;/AssetType&gt; &lt;AssetType&gt; ... &lt;/AssetType&gt; &lt;/assets&gt; </code></pre> <p>Then you can do the following:</p> <pre><code>f...
3
2010-02-09T16:58:52Z
[ "python", "xml" ]
How can I detect errors programatically when building an egg with setuptools?
2,230,843
<p>If I have a script that builds eggs, basically by running</p> <pre><code>python setup.py bdist_egg --exclude-source-files </code></pre> <p>for a number of setup.py files that use <code>setuptools</code> to define how eggs are built, is there an easy way to determine if there were any errors in building the egg?</p...
5
2010-02-09T16:54:37Z
2,240,549
<p><code>distutils</code> use the <code>py_compile.compile()</code> function to compile source files. This function takes a <code>doraise</code> argument, that when set to <code>True</code> raises an exception on compilation errors (the default is to print the errors to stderr). <code>distutils</code> don't call <code>...
5
2010-02-10T21:39:31Z
[ "python", "error-handling", "compiler-errors", "setuptools" ]