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
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
26,781,741
<p>Here's another one that I've just had: Check your test files are not executable. My virtualbox auto-mounted them as executable so the test discover missed them completely. I had to add them into the relevant <code>__init__.py</code> files before someone told me what the issue was as a work around, but now they are r...
1
2014-11-06T14:20:36Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
34,772,304
<p>The solution was silly in my case, I typed <code>def</code> instead of <code>class</code>.</p>
2
2016-01-13T16:45:13Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
35,566,512
<p>I can run test for specific apps e.g.</p> <pre><code>python project/manage.py test app_name </code></pre> <p>but when I run</p> <pre><code>python project/manage.py test </code></pre> <p>0 tests was found</p> <p>Figure out I need to run this in the same directory as manage.py</p> <p>so the solution would be, cd...
0
2016-02-23T00:18:28Z
[ "python", "django", "unit-testing" ]
Flaky file deletion under Windows 7?
2,037,376
<p>I have a Python test suite that creates and deletes many temporary files. Under Windows 7, the shutil.rmtree operations sometimes fail (&lt;1% of the time). The failure is apparently random, not always on the same files, not always in the same way, but it's always on rmtree operations. It seems to be some kind of...
4
2010-01-10T15:01:48Z
2,037,387
<p>My guess is that you should check up on the code that creates the file, and make SURE they are closed explicitly before moving on to delete it. If nothing is obvious there in the code, download a copy of <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645" rel="nofollow">Process Monitor</a> and watch ...
1
2010-01-10T15:04:49Z
[ "python", "windows-7" ]
Flaky file deletion under Windows 7?
2,037,376
<p>I have a Python test suite that creates and deletes many temporary files. Under Windows 7, the shutil.rmtree operations sometimes fail (&lt;1% of the time). The failure is apparently random, not always on the same files, not always in the same way, but it's always on rmtree operations. It seems to be some kind of...
4
2010-01-10T15:01:48Z
2,037,408
<p>We had similar problems with shutil.rmtree on Windows, particularly looking like your first stack trace. We solved it by using an exception handler with rmtree. See <a href="http://stackoverflow.com/questions/1213706/what-user-do-python-scripts-run-as-in-windows/1214935#1214935">this answer</a> for details.</p>
1
2010-01-10T15:13:41Z
[ "python", "windows-7" ]
Flaky file deletion under Windows 7?
2,037,376
<p>I have a Python test suite that creates and deletes many temporary files. Under Windows 7, the shutil.rmtree operations sometimes fail (&lt;1% of the time). The failure is apparently random, not always on the same files, not always in the same way, but it's always on rmtree operations. It seems to be some kind of...
4
2010-01-10T15:01:48Z
2,037,477
<p>It's a long shot, but are you running anything that scans directories in the background? I'm thinking antivirus/backup (maybe Windows 7 has something like that built in? I don't know). I have experienced occasional glitches when deleting/moving files from the TSVNCache.exe process that TortoiseSVN starts -- seems...
5
2010-01-10T15:37:38Z
[ "python", "windows-7" ]
Flaky file deletion under Windows 7?
2,037,376
<p>I have a Python test suite that creates and deletes many temporary files. Under Windows 7, the shutil.rmtree operations sometimes fail (&lt;1% of the time). The failure is apparently random, not always on the same files, not always in the same way, but it's always on rmtree operations. It seems to be some kind of...
4
2010-01-10T15:01:48Z
2,037,540
<p>Just a thought, but if the test behavior (creating and deleting lots of temp files) isn't typical of what the app actually does, maybe you could move those test file operations to (c)StringIO, and keep a suite of function tests that exercises your app's actual file creation/deletion behavior. </p> <p>That way, you ...
1
2010-01-10T16:03:58Z
[ "python", "windows-7" ]
Flaky file deletion under Windows 7?
2,037,376
<p>I have a Python test suite that creates and deletes many temporary files. Under Windows 7, the shutil.rmtree operations sometimes fail (&lt;1% of the time). The failure is apparently random, not always on the same files, not always in the same way, but it's always on rmtree operations. It seems to be some kind of...
4
2010-01-10T15:01:48Z
18,543,622
<p>That "The system cannot find the path specified:" error will appear intermittently if the path is too long for Windows (260 chars). Automated tasks often create folder hierarchies using relative references that produce fully qualified paths longer than 260 characters. Any script that attempts to delete those folde...
0
2013-08-31T01:34:43Z
[ "python", "windows-7" ]
How to create Form from a Model which has a ListProperty
2,037,591
<p>I am currently using Django forms with the Google App Engine and I have a model which is as follows:</p> <pre><code>class Menu(db.Model): name = db.StringProperty(required=True) is_special = db.BooleanProperty() menu_items = db.ListProperty(MenuItem) </code></pre> <p>I have a MenuForm which is the fol...
2
2010-01-10T16:19:05Z
2,037,789
<p>Your problem comes well before the "create a form" task begins: <code>ListProperty</code> does <em>not</em> allow a list of model entities (although I can't find this clearly documented in the app engine docs, I'm still looking in the docs for a good, clear, unambiguous statement about that). Try changing it into (...
5
2010-01-10T17:17:34Z
[ "python", "django", "google-app-engine" ]
How to find the namespace of a class easily in Python without using an IDE?
2,038,002
<p>Normally, I use IntelliJ for python programming. But sometimes I don't have access to it or just to make a quick edit I open a Python file in a text editor. </p> <p>At those times, it is really difficult to find the namespace of a class. I am googling it. But it takes time. Is there a better way to do this?</p> <p...
1
2010-01-10T18:21:12Z
2,038,175
<p>You can check the <a href="http://www.python.org/doc/" rel="nofollow">online documentation</a>, or the documentation installed with Python. If you search for a function or class, you'll get all the relevant information (I assume you meant the package or module of a class or of a function, in the Python standard libr...
0
2010-01-10T19:06:05Z
[ "python" ]
How to find the namespace of a class easily in Python without using an IDE?
2,038,002
<p>Normally, I use IntelliJ for python programming. But sometimes I don't have access to it or just to make a quick edit I open a Python file in a text editor. </p> <p>At those times, it is really difficult to find the namespace of a class. I am googling it. But it takes time. Is there a better way to do this?</p> <p...
1
2010-01-10T18:21:12Z
2,038,259
<p>The special attribute __module__ is the module name in which a class was defined. It will be '__main__' if defined in the top-level script.</p>
0
2010-01-10T19:28:40Z
[ "python" ]
How to find the namespace of a class easily in Python without using an IDE?
2,038,002
<p>Normally, I use IntelliJ for python programming. But sometimes I don't have access to it or just to make a quick edit I open a Python file in a text editor. </p> <p>At those times, it is really difficult to find the namespace of a class. I am googling it. But it takes time. Is there a better way to do this?</p> <p...
1
2010-01-10T18:21:12Z
2,038,353
<p>Let us not forget about <code>dir()</code>, which is heavily used by those of us who use vim as our IDE. </p>
2
2010-01-10T19:54:51Z
[ "python" ]
How to find the namespace of a class easily in Python without using an IDE?
2,038,002
<p>Normally, I use IntelliJ for python programming. But sometimes I don't have access to it or just to make a quick edit I open a Python file in a text editor. </p> <p>At those times, it is really difficult to find the namespace of a class. I am googling it. But it takes time. Is there a better way to do this?</p> <p...
1
2010-01-10T18:21:12Z
2,039,014
<p>Try <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a>.getmodule:</p> <pre><code>&gt;&gt;&gt; import inspect &gt;&gt;&gt; class Foo: pass &gt;&gt;&gt; inspect.getmodule(Foo) &lt;module '__main__' (built-in)&gt; </code></pre> <p>Lots of other cool stuff in there, too.</p>
0
2010-01-10T22:59:18Z
[ "python" ]
How to find the namespace of a class easily in Python without using an IDE?
2,038,002
<p>Normally, I use IntelliJ for python programming. But sometimes I don't have access to it or just to make a quick edit I open a Python file in a text editor. </p> <p>At those times, it is really difficult to find the namespace of a class. I am googling it. But it takes time. Is there a better way to do this?</p> <p...
1
2010-01-10T18:21:12Z
2,041,020
<p>I use <a href="http://ctags.sourceforge.net/" rel="nofollow">ctags</a> and I've got my <code>site-packages</code> as well as other folders indexed in advance. There are a number of <a href="http://ctags.sourceforge.net/tools.html" rel="nofollow">GUI and command line tools</a> that will integrate with ctags to do wh...
1
2010-01-11T09:58:27Z
[ "python" ]
Sets of instances
2,038,010
<p>I'm trying to build a set of instances of an object, however adding instances of certain objects results in a <code>TypeError: unhashable instance</code>. Here is a minimal example:</p> <pre><code>from sets import Set import random from UserDict import DictMixin class Item1(object): pass class Item2(DictMixin...
1
2010-01-10T18:22:38Z
2,038,019
<p>In order to put things into a set, they should be hashable. Tuples for example are hashable whereas lists are not. You can make your object hashable by giving it a <code>__hash__</code> method that will generate a hash key (a unique identifier for that instance of the class dependent on the data it's holding) for it...
5
2010-01-10T18:26:09Z
[ "python" ]
Sets of instances
2,038,010
<p>I'm trying to build a set of instances of an object, however adding instances of certain objects results in a <code>TypeError: unhashable instance</code>. Here is a minimal example:</p> <pre><code>from sets import Set import random from UserDict import DictMixin class Item1(object): pass class Item2(DictMixin...
1
2010-01-10T18:22:38Z
2,038,341
<p>Your classes can, if you want, define <code>__hash__</code> and comparison methods (most importantly <code>__eq__</code>) to be consistent with each other and "stable" -- i.e., the equality of two objects must not vary over the objects' lifetimes, and of course neither must each object's hash value vary over the obj...
4
2010-01-10T19:52:24Z
[ "python" ]
jquery.autocomplete.js - how does autocomplete work?
2,038,031
<p>I call the autocomplete jquery with the result of a GET request. The autocomplete function call looks like this:</p> <pre><code>$('#id_project_owner_externally').autocomplete('/pm/contact_autocomplete'); </code></pre> <p>The url /pm/contact_autocomplete returns a list of tuples. The first part of the tuple is the...
2
2010-01-10T18:29:43Z
2,038,041
<p>You need to look into the jquery.autocomplete.js source code, what your python code does is simply return the id and name separated by a hash char, one record per line. The autocomplete javascript handles that output, thus that is the part of the code you need to modify to put the ids into your hidden fields.</p>
2
2010-01-10T18:33:44Z
[ "jquery", "python", "django" ]
jquery.autocomplete.js - how does autocomplete work?
2,038,031
<p>I call the autocomplete jquery with the result of a GET request. The autocomplete function call looks like this:</p> <pre><code>$('#id_project_owner_externally').autocomplete('/pm/contact_autocomplete'); </code></pre> <p>The url /pm/contact_autocomplete returns a list of tuples. The first part of the tuple is the...
2
2010-01-10T18:29:43Z
2,038,197
<p>The <a href="http://docs.jquery.com/Plugins/Autocomplete#Search_Page_Replacement" rel="nofollow">plugin docs</a> have this example:</p> <pre><code>var data = [ {text:'Link A', url:'/page1'}, {text:'Link B', url: '/page2'} ]; $("...").autocomplete(data, { formatItem: function(item) { return item.text; } }).r...
3
2010-01-10T19:13:33Z
[ "jquery", "python", "django" ]
How to use Python and Google's Protocol Buffers to deserialize data sent over TCP
2,038,083
<p>I'm trying to write an application which uses Google's protocol buffers to deserialize data (sent from another application using protocol buffers) over a TCP connection. The problem is that it looks as if protocol buffers in Python can only deserialize data from a string. Since TCP doesn't have well-defined messag...
16
2010-01-10T18:45:29Z
2,038,176
<p>Don't just write the serialized data to the socket. First send a fixed-size field containing the length of the serialized object. </p> <p>The sending side is roughly:</p> <pre><code>socket.write(struct.pack("H", len(data)) #send a two-byte size field socket.write(data) </code></pre> <p>And the recv'ing side b...
36
2010-01-10T19:06:16Z
[ "python", "tcp", "protocol-buffers" ]
How to use Python and Google's Protocol Buffers to deserialize data sent over TCP
2,038,083
<p>I'm trying to write an application which uses Google's protocol buffers to deserialize data (sent from another application using protocol buffers) over a TCP connection. The problem is that it looks as if protocol buffers in Python can only deserialize data from a string. Since TCP doesn't have well-defined messag...
16
2010-01-10T18:45:29Z
2,042,733
<p>to expand on J.J.'s (entirely correct) answer, the protobuf library has <strong>no way</strong> to work out how long messages are on their own, or to work out what type of protobuf object is being sent*. So the other application that's sending you data must already be doing something like this.</p> <p>When I had t...
4
2010-01-11T15:26:30Z
[ "python", "tcp", "protocol-buffers" ]
How to use Python and Google's Protocol Buffers to deserialize data sent over TCP
2,038,083
<p>I'm trying to write an application which uses Google's protocol buffers to deserialize data (sent from another application using protocol buffers) over a TCP connection. The problem is that it looks as if protocol buffers in Python can only deserialize data from a string. Since TCP doesn't have well-defined messag...
16
2010-01-10T18:45:29Z
19,623,743
<p>Another aspect to consider (albeit for a simpler case) is where you use a single TCP connection for a single message. In this case, as long as you know what the expected message is (or use <a href="https://developers.google.com/protocol-buffers/docs/techniques#union%20Union%20Types" rel="nofollow">Union Types</a> to...
0
2013-10-27T21:22:13Z
[ "python", "tcp", "protocol-buffers" ]
Getting output from server side python script
2,038,085
<p>Hey, I'm doing this project where we are supposed to connect a javascript client side application/web page on server A with a python server side script on server B.</p> <p>I need to get the output from the python script and store it into a variable but am running into some problems. I was trying to use XMLHttpReque...
0
2010-01-10T18:45:57Z
2,038,203
<p>It sounds like your XMLHttpRequest is failing because you're trying to do a cross-domain request. You could use a cross-domain solution like <a href="http://www.west-wind.com/Weblog/posts/107136.aspx" rel="nofollow">JSONP</a> instead.</p> <p>In general, tools like <a href="http://getfirebug.com/net.html" rel="nofol...
4
2010-01-10T19:15:12Z
[ "javascript", "python", "scripting", "xmlhttprequest" ]
SymPy: How to return an expression in terms of other expression(s)?
2,038,100
<p>I'm fairly new to <a href="http://en.wikipedia.org/wiki/SymPy" rel="nofollow">SymPy</a> and have what might be a basic question. Or I might simply be misinterpreting how SymPy is supposed to be used.</p> <p>Is there a way to create an expression that is not represented by atoms, but by a combination of other expre...
3
2010-01-10T18:49:01Z
2,040,955
<p>In sympy units you convert from expr1 to expr2 by dividing:</p> <pre><code>In [120]: import sympy.physics.units as units In [121]: expr1 = units.m / units.s In [122]: expr2 = units.miles / units.hour In [123]: a = (1397/3125) * expr1 / expr2 In [124]: a Out[124]: 1 </code></pre> <p>The only issue is that you e...
1
2010-01-11T09:43:51Z
[ "python", "sympy" ]
SymPy: How to return an expression in terms of other expression(s)?
2,038,100
<p>I'm fairly new to <a href="http://en.wikipedia.org/wiki/SymPy" rel="nofollow">SymPy</a> and have what might be a basic question. Or I might simply be misinterpreting how SymPy is supposed to be used.</p> <p>Is there a way to create an expression that is not represented by atoms, but by a combination of other expre...
3
2010-01-10T18:49:01Z
2,041,416
<p>Checking the source for <a href="http://docs.sympy.org/dev/modules/physics/units.html" rel="nofollow">sympy.physics.units</a> you can see that all units are defined in terms of meters, kilograms, seconds, amperes, kelvins, moles and candelas. These are the base units.</p> <p>Then a mile is defined as 5280 feet, and...
2
2010-01-11T11:16:48Z
[ "python", "sympy" ]
SymPy: How to return an expression in terms of other expression(s)?
2,038,100
<p>I'm fairly new to <a href="http://en.wikipedia.org/wiki/SymPy" rel="nofollow">SymPy</a> and have what might be a basic question. Or I might simply be misinterpreting how SymPy is supposed to be used.</p> <p>Is there a way to create an expression that is not represented by atoms, but by a combination of other expre...
3
2010-01-10T18:49:01Z
2,044,508
<p>there's also <a href="http://packages.python.org/quantities/" rel="nofollow">quantities</a>:</p> <pre><code>In [1]: from quantities import * In [2]: v = 1397*m / (3125*s) In [3]: v Out[3]: array(0.44704) * m/s In [8]: v.units = mile/hour In [9]: v Out[9]: array(1.0) * mi/h </code></pre>
1
2010-01-11T19:55:09Z
[ "python", "sympy" ]
How to get module variable in function from another module?
2,038,160
<p>I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g.</p> <pre><code># mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var </code></pre> <p>The problem is - I can't reference variable ...
3
2010-01-10T19:00:15Z
2,038,167
<p>If you <em>really</em> want to do that then you'll need to import mod1 in either the other module or directly in the function, and then modify it off that import. But don't do that; seasoned programmers will point and laugh.</p>
0
2010-01-10T19:03:23Z
[ "python", "django" ]
How to get module variable in function from another module?
2,038,160
<p>I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g.</p> <pre><code># mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var </code></pre> <p>The problem is - I can't reference variable ...
3
2010-01-10T19:00:15Z
2,038,171
<p>What you want to do sounds like too much magic. Pass in urlpatterns and be done with it. Explicit is better than implicit.</p>
4
2010-01-10T19:05:45Z
[ "python", "django" ]
How to get module variable in function from another module?
2,038,160
<p>I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g.</p> <pre><code># mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var </code></pre> <p>The problem is - I can't reference variable ...
3
2010-01-10T19:00:15Z
2,038,210
<p>OK, here's the magic, but again, I recommend not using it:</p> <pre><code>import sys def modify_var(): """Mysteriously change `mod_var` in the caller's context.""" f = sys._getframe(1) f.f_locals['mod_var'] += " (modified)" mod_var = "Hello" modify_var() print mod_var </code></pre> <p>prints:</p> <p...
2
2010-01-10T19:16:35Z
[ "python", "django" ]
How to get module variable in function from another module?
2,038,160
<p>I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g.</p> <pre><code># mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var </code></pre> <p>The problem is - I can't reference variable ...
3
2010-01-10T19:00:15Z
2,038,310
<p>It's a truly bad, horrible, and awful idea, which will lead to future maintenance nightmares. However, Python does offer "enough rope to shoot yourself in the foot", if you truly insist: introspection and metaprogramming tools which are mostly intended for debugging purposes, but can be abused to perform the ill-con...
4
2010-01-10T19:42:30Z
[ "python", "django" ]
Integration of Python console into a GUI C++ application
2,038,247
<p>I'm going to add a python console widget (into a C++ GUI) below some other controls: <img src="http://img-fotki.yandex.ru/get/4012/goodrone.0/0_2f2ae_b37ea156_orig" alt="Python Console screenshot"></p> <p>Many classes are going to be exposed to the python code, including some access to GUI (maybe I'll consider PyQt...
24
2010-01-10T19:26:09Z
2,038,319
<p>Since you're apparently wanting to embed a Python interpreter to use Python as a scripting language in a what seems to be a Qt application, I suggest you have a look at <a href="http://pythonqt.sourceforge.net/">PythonQt</a>.</p> <p>With the PythonQt module, Python scripts will be able to interact with the GUI of y...
11
2010-01-10T19:45:22Z
[ "c++", "python", "multithreading", "user-interface", "integration" ]
Handling an "Inventory" (complex associations) with django + appengine
2,038,290
<p>I'm writing a web application to manage a "game". Here are the models:</p> <pre><code>class Character(db.Model): # Bio name = db.StringProperty() player = db.StringProperty() level = db.IntegerProperty() class Item(db.Model): name = db.StringProperty() description = db.StringProperty() ...
0
2010-01-10T19:36:07Z
2,039,288
<p>you will want to look at inline formsets. <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets</a></p>
0
2010-01-11T00:33:52Z
[ "python", "django" ]
Handling an "Inventory" (complex associations) with django + appengine
2,038,290
<p>I'm writing a web application to manage a "game". Here are the models:</p> <pre><code>class Character(db.Model): # Bio name = db.StringProperty() player = db.StringProperty() level = db.IntegerProperty() class Item(db.Model): name = db.StringProperty() description = db.StringProperty() ...
0
2010-01-10T19:36:07Z
2,039,305
<p>Not sure if I understand you correctly, but if you want to show the Inventory of a Character in a form and place the form of the Character at the same page, you should check out inline formsets <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets" rel="nofollow">the doc</a></p> <p>...
1
2010-01-11T00:39:22Z
[ "python", "django" ]
What optimizations does Python do without the -O flags?
2,038,481
<p>I had always assumed that the Python interpreter did no optimizations without a <code>-O</code> flag, but the following is a bit strange:</p> <pre><code>&gt;&gt;&gt; def foo(): ... print '%s' % 'Hello world' ... &gt;&gt;&gt; from dis import dis &gt;&gt;&gt; dis(foo) 2 0 LOAD_CONST 3 (...
4
2010-01-10T20:26:27Z
2,038,502
<p>Yep, it does do constant folding, here's a simpler example:</p> <pre><code>&gt;&gt;&gt; def f(): return 23+100 ... &gt;&gt;&gt; dis.dis(f) 1 0 LOAD_CONST 3 (123) 3 RETURN_VALUE &gt;&gt;&gt; </code></pre> <p>No way to block this (except by changing sources) AFAIK.</...
9
2010-01-10T20:31:52Z
[ "python", "optimization", "bytecode" ]
What optimizations does Python do without the -O flags?
2,038,481
<p>I had always assumed that the Python interpreter did no optimizations without a <code>-O</code> flag, but the following is a bit strange:</p> <pre><code>&gt;&gt;&gt; def foo(): ... print '%s' % 'Hello world' ... &gt;&gt;&gt; from dis import dis &gt;&gt;&gt; dis(foo) 2 0 LOAD_CONST 3 (...
4
2010-01-10T20:26:27Z
22,896,746
<p>Here's a way to walk around constant folding:</p> <pre><code>&gt;&gt;&gt; dis.dis(lambda: (3,)[0]+(4,)[0]) 1 0 LOAD_CONST 5 (3) 3 LOAD_CONST 7 (4) 6 BINARY_ADD 7 RETURN_VALUE </code></pre> <p>Watch out for the extra...
0
2014-04-06T16:26:53Z
[ "python", "optimization", "bytecode" ]
Python's subprocess.Popen() and source
2,038,575
<p>A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is:</p> <pre><code> proc = subprocess.Popen( "ls &amp;&amp; source houdini_setup", shell = True, executable = "/bin/bash", ) </code></pre> <p>The...
4
2010-01-10T20:55:03Z
2,038,603
<p><code>source</code> uses <code>$PATH</code> to find what you pass to it, if you don't specify a directory. Try <code>source ./houdini_setup</code>.</p>
7
2010-01-10T21:03:19Z
[ "python", "bash" ]
Python's subprocess.Popen() and source
2,038,575
<p>A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is:</p> <pre><code> proc = subprocess.Popen( "ls &amp;&amp; source houdini_setup", shell = True, executable = "/bin/bash", ) </code></pre> <p>The...
4
2010-01-10T20:55:03Z
2,038,756
<p>You can use <code>strace</code> to help diagnose problems like this. In this case running it with the <code>-ff</code> flag to follow subprocess would have revealed that your code was looking for "houdini_setup" in the wrong place:</p> <pre><code>stat64("/usr/local/bin/houdini_setup", 0xbf989e60) = -1 ENOENT (No su...
2
2010-01-10T21:43:12Z
[ "python", "bash" ]
Python's subprocess.Popen() and source
2,038,575
<p>A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is:</p> <pre><code> proc = subprocess.Popen( "ls &amp;&amp; source houdini_setup", shell = True, executable = "/bin/bash", ) </code></pre> <p>The...
4
2010-01-10T20:55:03Z
13,753,953
<p>Maybe you can just use bash itself to do the job, if it's available on your system:</p> <pre><code>os.popen("/bin/bash -l -c 'source $HOME/.yourfiletobesourced'") </code></pre>
0
2012-12-06T22:42:10Z
[ "python", "bash" ]
Model form is crashing on a foreign key in django
2,038,621
<p>So I'm trying to create a new feed within the Admin page and its crashing with the error IntegrityError: lifestream_feed.lifestream_id may not be NULL, form['lifestream'] is set but form.instance.lifestream is not. </p> <p>form.fields even shows that lifestream is a django.forms.models.ModelChoiceField</p> <p>Her...
2
2010-01-10T21:07:41Z
2,038,900
<p>I believe the problem is in your <code>clean()</code> method.</p> <p>The general <code>clean()</code> method (as opposed to field specific clean methods like <code>clean_domain()</code>) must return the <code>cleaned_data</code> dictionary (minus any fields which do not validate), and you have at least 3 returns in...
0
2010-01-10T22:27:02Z
[ "python", "django", "django-models", "django-forms" ]
Model form is crashing on a foreign key in django
2,038,621
<p>So I'm trying to create a new feed within the Admin page and its crashing with the error IntegrityError: lifestream_feed.lifestream_id may not be NULL, form['lifestream'] is set but form.instance.lifestream is not. </p> <p>form.fields even shows that lifestream is a django.forms.models.ModelChoiceField</p> <p>Her...
2
2010-01-10T21:07:41Z
2,039,999
<p>Turns out this is a bug in HEAD of django</p>
0
2010-01-11T05:01:21Z
[ "python", "django", "django-models", "django-forms" ]
scipy linregress function erroneous standard error return?
2,038,667
<p>I have a weird situation with scipy.stats.linregress seems to be returning an incorrect standard error:</p> <pre><code>from scipy import stats x = [5.05, 6.75, 3.21, 2.66] y = [1.65, 26.5, -5.93, 7.96] gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y) &gt;&gt;&gt; gradient 5.3935773611970186 &g...
5
2010-01-10T21:19:07Z
2,038,870
<p>I've just been informed by the SciPy user group that the std_err here represents the standard error of the gradient line, not the standard error of the predicted y's, as per Excel. Nevertheless users of this function should be careful, because this was not always the behaviour of this library - it used to output ex...
8
2010-01-10T22:15:07Z
[ "python", "scipy", "regression" ]
scipy linregress function erroneous standard error return?
2,038,667
<p>I have a weird situation with scipy.stats.linregress seems to be returning an incorrect standard error:</p> <pre><code>from scipy import stats x = [5.05, 6.75, 3.21, 2.66] y = [1.65, 26.5, -5.93, 7.96] gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y) &gt;&gt;&gt; gradient 5.3935773611970186 &g...
5
2010-01-10T21:19:07Z
2,040,099
<p>You could try the <a href="http://statsmodels.sourceforge.net/" rel="nofollow">statsmodels</a> package:</p> <pre><code>In [37]: import statsmodels.api as sm In [38]: x = [5.05, 6.75, 3.21, 2.66] In [39]: y = [1.65, 26.5, -5.93, 7.96] In [40]: X = sm.add_constant(x) # intercept In [41]: model = sm.OLS(y, X) In ...
4
2010-01-11T05:36:16Z
[ "python", "scipy", "regression" ]
Access scanner from Java or Python (or something else if it's technically motivated) in Linux (but Windows would be nice)
2,038,700
<p>I want to write a system for handling important documents in my home. This is the user story for getting a new document:</p> <ol> <li>I "Add new document" and am prompted to scan it using my combined printer/scanner.</li> <li>I view the scanned copy to see it's of good enough quality. Which it has.</li> <li>The sys...
1
2010-01-10T21:26:49Z
2,038,740
<p>The standard interface for scanners is <a href="http://en.wikipedia.org/wiki/TWAIN" rel="nofollow">TWAIN</a>. If you google for "java twain" or "python twain", you get plenty of useful-looking stuff, e.g.</p> <ul> <li><a href="http://www.programmersheaven.com/2/Java-Twain-image-acquisition" rel="nofollow">http://ww...
1
2010-01-10T21:39:12Z
[ "java", "python", "image-scanner" ]
Access scanner from Java or Python (or something else if it's technically motivated) in Linux (but Windows would be nice)
2,038,700
<p>I want to write a system for handling important documents in my home. This is the user story for getting a new document:</p> <ol> <li>I "Add new document" and am prompted to scan it using my combined printer/scanner.</li> <li>I view the scanned copy to see it's of good enough quality. Which it has.</li> <li>The sys...
1
2010-01-10T21:26:49Z
2,038,744
<p>Under Linux, the common interface to scanners is <a href="http://www.sane-project.org/" rel="nofollow">SANE</a>.</p>
3
2010-01-10T21:41:06Z
[ "java", "python", "image-scanner" ]
Python ctypes addressof CFuncType
2,038,839
<p>Related to my <a href="http://stackoverflow.com/questions/2032470/python-ctypes-callback-function-to-swig">other question</a></p> <p>How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address.</p> <p>C code:</p> <pre><code>extern "C" _declspec(dllex...
3
2010-01-10T22:04:29Z
2,038,956
<p><code>cast(f, c_void_p)</code> gets the correct address from within python</p>
5
2010-01-10T22:43:55Z
[ "python", "ctypes" ]
How should I convert this long and complex PHP style URL query string to a Django url?
2,039,054
<p>I'm converting a small PHP application to Django.</p> <p>One section has a long query string, indicating how a widget is to be displayed. There are a few required parameters and several optional ones.</p> <p>The current urls read like:</p> <pre><code>app.php?id=102030&amp;size=large&amp;auto=0&amp;bw=1&amp;extra=...
2
2010-01-10T23:09:43Z
2,039,079
<p>If you consider that "URL" stands for Uniform <em>Resource</em> Locator, the URL should only indicate the resource being displayed, and any 'configuration' options should be passed as parameters. So, I think your first idea is fine.</p>
9
2010-01-10T23:18:57Z
[ "python", "django", "url", "url-routing" ]
How do I make these Perl regexs Python compatible?
2,039,100
<p>I have these two lines in an old Perl script. When I write the Python equivalent I get all sorts of errors like valueerror: invalid <code>\x</code> escape, and stuff about encoding.</p> <pre><code>$line =~ s/[^\x{8}-\x{7B}]/ /ig; $line =~ s/(Û|²|°|±|É|¹|Í)/ /g; </code></pre> <p>What do I need to do to get t...
0
2010-01-10T23:26:52Z
2,039,146
<p>I'm not too great with Perl regex but I think I may have solved it:</p> <pre><code>invalid_range = re.compile(r'[^\x08-\x7B]', re.I) invalid_unicode = re.compile(ur'(Û|²|°|±|É|¹|Í)') line = re.sub(invalid_range , '', line) line = re.sub(invalid_unicode, '', line) </code></pre>
1
2010-01-10T23:45:01Z
[ "python", "regex", "perl" ]
How do I make these Perl regexs Python compatible?
2,039,100
<p>I have these two lines in an old Perl script. When I write the Python equivalent I get all sorts of errors like valueerror: invalid <code>\x</code> escape, and stuff about encoding.</p> <pre><code>$line =~ s/[^\x{8}-\x{7B}]/ /ig; $line =~ s/(Û|²|°|±|É|¹|Í)/ /g; </code></pre> <p>What do I need to do to get t...
0
2010-01-10T23:26:52Z
2,039,692
<p>For encoding issues, if you want to put Unicode characters in your source directly, you'll need to make sure the Python interpreter knows what your file encoding is. See:</p> <ul> <li><a href="http://docs.python.org/reference/lexical_analysis.html#encoding-declarations" rel="nofollow">Python docs—Encoding Declara...
0
2010-01-11T03:06:28Z
[ "python", "regex", "perl" ]
python-re: How do I match an alpha character
2,039,140
<p>How can I match an alpha character with a regular expression. I want a character that is in <code>\w</code> but is not in <code>\d</code>. I want it unicode compatible that's why I cannot use <code>[a-zA-Z]</code>.</p>
14
2010-01-10T23:43:19Z
2,039,149
<p>What about:</p> <pre><code>\p{L} </code></pre> <p>You can to use this document as reference: <a href="http://www.regular-expressions.info/unicode.html" rel="nofollow">Unicode Regular Expressions</a></p> <p><strong>EDIT:</strong> Seems <a href="http://www.regular-expressions.info/python.html" rel="nofollow">Python...
1
2010-01-10T23:45:56Z
[ "python", "regex", "unicode", "regex-negation" ]
python-re: How do I match an alpha character
2,039,140
<p>How can I match an alpha character with a regular expression. I want a character that is in <code>\w</code> but is not in <code>\d</code>. I want it unicode compatible that's why I cannot use <code>[a-zA-Z]</code>.</p>
14
2010-01-10T23:43:19Z
2,039,476
<p>Your first two sentences contradict each other. "in <code>\w</code> but is not in <code>\d</code>" includes underscore. I'm assuming from your third sentence that you don't want underscore. </p> <p>Using a Venn diagram on the back of an envelope helps. Let's look at what we DON'T want:</p> <p>(1) characters that a...
36
2010-01-11T01:41:48Z
[ "python", "regex", "unicode", "regex-negation" ]
python-re: How do I match an alpha character
2,039,140
<p>How can I match an alpha character with a regular expression. I want a character that is in <code>\w</code> but is not in <code>\d</code>. I want it unicode compatible that's why I cannot use <code>[a-zA-Z]</code>.</p>
14
2010-01-10T23:43:19Z
35,777,105
<p>You can use one of the following expressions to match a single letter:</p> <pre><code>(?![\d_])\w </code></pre> <p>or</p> <pre><code>\w(?&lt;![\d_]) </code></pre> <p>Here I match for <code>\w</code>, but check that <code>[\d_]</code> is not matched before/after that.</p> <p>From the docs:</p> <pre><code>(?!......
0
2016-03-03T16:04:41Z
[ "python", "regex", "unicode", "regex-negation" ]
Fractions with decimal precision
2,039,154
<p>Is there a pure python implementation of <code>fractions.Fraction</code> that supports <code>long</code>s as numerator and denominator? Unfortunately, exponentiation appears to be coded in to return a float (ack!!!), which should at least support using <code>decimal.Decimal</code>.</p> <p>If there isn't, I suppose ...
6
2010-01-10T23:47:04Z
2,039,213
<p>You can write your own "pow" function for fractions that doesn't use floating-point exponentiation. Is that what you're trying to do?</p> <p>This will raise a fraction to an integer power with falling back to float.</p> <pre><code>def pow( fract, exp ): if exp == 0: return fract elif exp % 2 == 0...
0
2010-01-11T00:09:28Z
[ "python", "decimal", "long-integer", "arbitrary-precision" ]
Fractions with decimal precision
2,039,154
<p>Is there a pure python implementation of <code>fractions.Fraction</code> that supports <code>long</code>s as numerator and denominator? Unfortunately, exponentiation appears to be coded in to return a float (ack!!!), which should at least support using <code>decimal.Decimal</code>.</p> <p>If there isn't, I suppose ...
6
2010-01-10T23:47:04Z
2,039,312
<p>"Raise to a power" is not a closed operation over the rationals (differently from the usual four arithmetic operations): there is no rational number <code>r</code> such that <code>r == 2 ** 0.5</code>. Legend has it that Pythagoras (from whose theorem this fact so simply follows) had his disciple Hippasus killed fo...
6
2010-01-11T00:42:29Z
[ "python", "decimal", "long-integer", "arbitrary-precision" ]
PyQt + shortcut to trigger a button
2,039,241
<p>How do I configure keyboard shortcuts to click specific buttons in a PyQT app? Eg: <kbd>Ctrl</kbd> + <kbd>1</kbd> to click one button while <kbd>Ctrl</kbd> + <kbd>2</kbd> to click the other?</p>
3
2010-01-11T00:16:52Z
2,039,329
<p>Use <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qshortcut.html">QtGui.QShortcut</a>: you build it with a <code>QKeySequence</code>, and it emits the <code>activated()</code> signal when that key sequence is typed while the shortcut's parent widget has focus (of course, you connect those signa...
5
2010-01-11T00:49:28Z
[ "python", "button", "keyboard-shortcuts", "pyqt" ]
why 'setprofile' print this
2,039,336
<pre><code>import sys def a(): print 'aaa' def profiler(frame, event, arg): print event, frame.f_code.co_name, frame.f_lineno, "-&gt;", arg # profiler is activated on the next call, return, or exception sys.setprofile(profiler) a() </code></pre> <p>print </p> <pre><code>call a 5 -&gt; None#what is it aaa ret...
0
2010-01-11T00:52:15Z
2,039,375
<p>It seems like maybe you're wondering why arg is None. <code>arg</code> has different meanings for each event. For "return", <code>arg</code> is the value to be returned. For "exception", it's a triple of exception information. See <a href="http://docs.python.org/library/sys.html#sys.settrace" rel="nofollow">http...
0
2010-01-11T01:08:09Z
[ "python", "sys" ]
why 'setprofile' print this
2,039,336
<pre><code>import sys def a(): print 'aaa' def profiler(frame, event, arg): print event, frame.f_code.co_name, frame.f_lineno, "-&gt;", arg # profiler is activated on the next call, return, or exception sys.setprofile(profiler) a() </code></pre> <p>print </p> <pre><code>call a 5 -&gt; None#what is it aaa ret...
0
2010-01-11T00:52:15Z
2,039,377
<p>The <code>profiler</code> function gets called at each profiling event because you called <code>sys.setprofile</code> on it.</p> <p>Each time it's called, it prints a line, because you put an unconditional <code>print</code> statement as its body. <strong>Why</strong> you did that, is hard for us to tell you, maki...
3
2010-01-11T01:08:43Z
[ "python", "sys" ]
How to trigger Google Analytics events from Python?
2,039,583
<p>I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire <code>webbrowser</code> component just to send a javascript request?</p>
21
2010-01-11T02:18:17Z
2,082,745
<p>There's a question for this in SO, <a href="http://stackoverflow.com/questions/1027660/generate-google-analytics-events-utm-gif-requests-serverside">Generate Google Analytics events (__utm.gif requests) serverside</a>.</p> <p>The problem is:</p> <blockquote> <p>it seems like it's a little old and there's no do...
6
2010-01-17T21:33:03Z
[ "python", "events", "google-analytics", "tracking" ]
How to trigger Google Analytics events from Python?
2,039,583
<p>I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire <code>webbrowser</code> component just to send a javascript request?</p>
21
2010-01-11T02:18:17Z
2,100,975
<p>There is an open source implementation of Google-Analytics for Mobile in python available here: <a href="http://github.com/b1tr0t/Google-Analytics-for-Mobile--python-">http://github.com/b1tr0t/Google-Analytics-for-Mobile--python-</a></p> <blockquote> <p>You can probably integrate this into your own setup by imp...
11
2010-01-20T11:30:39Z
[ "python", "events", "google-analytics", "tracking" ]
How to trigger Google Analytics events from Python?
2,039,583
<p>I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire <code>webbrowser</code> component just to send a javascript request?</p>
21
2010-01-11T02:18:17Z
12,973,600
<p><a href="https://github.com/kra3/py-ga-mob" rel="nofollow">This project</a> called PyGA is much better. Unlike "Google-Analytics for Mobile" project on github it is well documentated and has rich API.</p>
12
2012-10-19T11:47:01Z
[ "python", "events", "google-analytics", "tracking" ]
How to trigger Google Analytics events from Python?
2,039,583
<p>I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire <code>webbrowser</code> component just to send a javascript request?</p>
21
2010-01-11T02:18:17Z
17,288,918
<p>Basically it boils down to: <a href="https://gist.github.com/canburak/1593381" rel="nofollow">https://gist.github.com/canburak/1593381</a></p> <p>For more information about the parameters etc: <a href="https://medium.com/python-programming-language/80eb9691d61f" rel="nofollow">https://medium.com/python-programming-...
0
2013-06-25T03:57:44Z
[ "python", "events", "google-analytics", "tracking" ]
How to trigger Google Analytics events from Python?
2,039,583
<p>I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire <code>webbrowser</code> component just to send a javascript request?</p>
21
2010-01-11T02:18:17Z
38,489,757
<p>All other answers are for the outdated <code>ga.js</code> protocol, this library seems to implement the newer <code>universal.js</code> (I didn't try it yet):</p> <p><a href="https://github.com/analytics-pros/universal-analytics-python" rel="nofollow">https://github.com/analytics-pros/universal-analytics-python</a>...
0
2016-07-20T19:58:40Z
[ "python", "events", "google-analytics", "tracking" ]
How to upload images using an API Key that gives you permission to upload? [Python source code included]
2,039,602
<p>The documentation of the API shows source code on how to accomplish this in Python:</p> <pre><code>#!/usr/bin/python import pycurl c = pycurl.Curl() values = [ ("key", "YOUR_API_KEY"), ("image", (c.FORM_FILE, "file.png"))] # OR: ("image", "http://example.com/example.jpg"))] c.setopt(c.URL...
0
2010-01-11T02:25:32Z
2,039,633
<p>You just need to perform an HTTP POST, e.g. <a href="http://en.csharp-online.net/HTTP_Post" rel="nofollow">this code</a> with a "parameters" string of <code>key=YOUR_API_KEY&amp;image=http://example.com/example.jpg</code> or the like.</p>
1
2010-01-11T02:39:20Z
[ "c#", "python", "api", "imgur" ]
How do I regex search for weird non-ASCII characters in Python?
2,039,650
<p>I'm using the following regular expression basically to search for and delete these characters.</p> <pre><code>invalid_unicode = re.compile(ur'(Û|²|°|±|É|¹|Í)') </code></pre> <p>My source code in <a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> encoded, and whenever I try to run the scr...
2
2010-01-11T02:48:04Z
2,039,656
<p>After telling Python that your source file uses UTF-8 encoding, did you actually make sure that your editor is <em>saving</em> the file using UTF-8 encoding? The error you get indicates that your editor is probably not using UTF-8.</p> <p>What text editor are you using?</p>
1
2010-01-11T02:51:10Z
[ "python", "regex", "unicode", "ascii" ]
How do I regex search for weird non-ASCII characters in Python?
2,039,650
<p>I'm using the following regular expression basically to search for and delete these characters.</p> <pre><code>invalid_unicode = re.compile(ur'(Û|²|°|±|É|¹|Í)') </code></pre> <p>My source code in <a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> encoded, and whenever I try to run the scr...
2
2010-01-11T02:48:04Z
2,039,659
<pre><code>\x{c0de} </code></pre> <p>In a regex will match the Unicode character at code point <code>c0de</code>.</p> <p>Python uses PCRE, right? (If it doesn't, it's probably <code>\uC0DE</code> instead...)</p>
0
2010-01-11T02:51:32Z
[ "python", "regex", "unicode", "ascii" ]
How do I regex search for weird non-ASCII characters in Python?
2,039,650
<p>I'm using the following regular expression basically to search for and delete these characters.</p> <pre><code>invalid_unicode = re.compile(ur'(Û|²|°|±|É|¹|Í)') </code></pre> <p>My source code in <a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> encoded, and whenever I try to run the scr...
2
2010-01-11T02:48:04Z
2,039,663
<p>You need to find out what encoding your editor is using, and set that per PEP263; or, make things more stable and portable (though alas perhaps a bit less readable) and use escape sequences in your string literal, i.e., use <code>u'(\xdb|\xb2|\xb0|\xb1|\xc9|\xb9|\xcd)'</code> as the parameter to the <code>re.compile...
3
2010-01-11T02:52:49Z
[ "python", "regex", "unicode", "ascii" ]
How do I get PyFacebook working with the Google App Engine Patch?
2,039,653
<p>I've tried to follow the advice of this question: <a href="http://stackoverflow.com/questions/984071/facebook-django-and-google-app-engine">http://stackoverflow.com/questions/984071/facebook-django-and-google-app-engine</a>, however I've run into a number of problems. The first is that <code>from facebook.djangofb ...
0
2010-01-11T02:49:37Z
2,041,603
<p>For your first question:</p> <blockquote> <p><code>from facebook.djangofb import facebook</code> doesn't work because when I try to use the decorator @facebook.require_login(), it complains that the facebook module doesn't have that method. If I change it to <code>import facebook.djangofb</code> and <code>@facebo...
4
2010-01-11T11:53:06Z
[ "python", "django", "google-app-engine", "facebook", "app-engine-patch" ]
Python: Why can't I get my decorator to work?
2,039,699
<p>This works now for those new to this question:</p> <pre><code>class ensureparams(object): """ Used as a decorator with an iterable passed in, this will look for each item in the iterable given as a key in the params argument of the function being decorated. It was built for a series of PayPal metho...
2
2010-01-11T03:08:03Z
2,039,710
<p><code>def wrapper(params):</code> means you're only going to accept one argument -- and so of course calls with <code>(self, params)</code> just won't work. You need to be able to accept either one or two arguments, e.g., at the very least (if you don't need to support calls w/named args):</p> <pre><code>def wrapp...
2
2010-01-11T03:14:22Z
[ "python", "decorator" ]
Python: Why can't I get my decorator to work?
2,039,699
<p>This works now for those new to this question:</p> <pre><code>class ensureparams(object): """ Used as a decorator with an iterable passed in, this will look for each item in the iterable given as a key in the params argument of the function being decorated. It was built for a series of PayPal metho...
2
2010-01-11T03:08:03Z
2,039,761
<p>Decorators normally look like this:</p> <pre><code>def wrapper(*args, **kargs): # Pull what you need out of the argument lists and do stuff with it func(*args, **kargs) </code></pre> <p>Then they work with any function passed to them, not just functions with a specific number of arguments or with specific ...
2
2010-01-11T03:32:16Z
[ "python", "decorator" ]
Python: Why can't I get my decorator to work?
2,039,699
<p>This works now for those new to this question:</p> <pre><code>class ensureparams(object): """ Used as a decorator with an iterable passed in, this will look for each item in the iterable given as a key in the params argument of the function being decorated. It was built for a series of PayPal metho...
2
2010-01-11T03:08:03Z
2,039,827
<p>What I did was add *args, **kwargs, and just check for the keys that are required within the 'params' argument via kwargs['params'] after checking that kwargs params exists.</p> <p>Here's the new version (which works perfectly):</p> <pre><code>class requiresparams(object): """ Used as a decorator with an ...
0
2010-01-11T03:56:02Z
[ "python", "decorator" ]
Implementing USZipCodeField and USStateField in django
2,039,762
<p>I'm looking to implement a zipcode field in django using the form objects from <a href="http://docs.djangoproject.com/en/1.1/ref/contrib/localflavor/#united-states-of-america-us" rel="nofollow">localflavor</a>, but not quite getting them to work. I want to have a zipcode field in a form (or ModelForm in my case), b...
0
2010-01-11T03:33:07Z
2,040,445
<p>Using <code>widgets</code> declaratively has literally only just been added to the trunk SVN version in the last day or so. If you're using an older checkout, or a released version, it won't work - you'll need to go back to the old way of doing it, by overriding the field declarations at the top level of the form.</...
1
2010-01-11T07:20:06Z
[ "python", "django", "django-models", "localization", "django-forms" ]
Python "from xxx.yyy import xxx" error
2,039,823
<p>I'm working with the PyFacebook package in Python, and I've seen a number of times people mention that you can write an import statement as follows:</p> <pre><code>from facebook.djangofb import facebook </code></pre> <p>which will alias the "djangofb" module as "facebook." I'm trying to run this from the Python C...
3
2010-01-11T03:54:27Z
2,039,832
<p>This is the proper way to alias a module via import:</p> <pre><code>import facebook.djangofb as facebook </code></pre>
11
2010-01-11T03:57:27Z
[ "python" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
2,039,959
<p>Do you have the media context processor in your settings?</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.media', ) </code></pre> <p>You might also try putting the following in your settings to see if the debug messages reveal anything:</p> <pre><code>TEMPLATE_DEBUG = True </cod...
6
2010-01-11T04:46:44Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
2,039,965
<p>You can either pass it to the template manually as others have suggested or ensure that you are using a <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#id1">RequestContext</a> instead of plain Context. RequestContext will automatically populate the context with certain variables including MEDIA_URL...
13
2010-01-11T04:49:51Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
2,040,027
<p>It looks like ars has answered your <em>real</em> question… But you'll run into another problem: <code>MEDIA_URL</code> must be <em>different</em> from <code>ADMIN_MEDIA_PREFIX</code>. If they aren't, the <code>ADMIN_MEDIA_PREFIX</code> will take precedence. I usually fix this by changing <code>ADMIN_MEDIA_PREFIX<...
7
2010-01-11T05:11:02Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
2,040,098
<p>It looks like your are using the debug server (your url is <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a>...) . Did you install the static serve in your urls.py? </p> <pre><code>if settings.DEBUG: urlpatterns += patterns('', (r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'doc...
21
2010-01-11T05:35:44Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
5,877,275
<p>Thanks a lot for your help everyone. I was able to solve it as</p> <p><strong>settings.py --></strong></p> <pre><code>MEDIA_ROOT = '/home/patrick/Documents/code/projects/test/media/' MEDIA_URL = 'http://localhost:8000/media/' </code></pre> <p><strong>urls.py --></strong></p> <pre><code>(r'^media/(?P&lt;path&gt;,...
3
2011-05-04T00:36:08Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
16,302,966
<p>Please read the official Django DOC carefully and you will find the most fit answer.</p> <p>The best and easist way to solve this is like below.</p> <pre><code>from django.conf import settings from django.conf.urls.static import static urlpatterns = patterns('', # ... the rest of your URLconf goes here ... ) ...
4
2013-04-30T14:58:00Z
[ "python", "django", "tinymce" ]
Django not recognizing the MEDIA_URL path?
2,039,889
<p>So I'm trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/media/js/tiny_mce/tiny_mce.js. I believe that /media/js/tiny_mce/tiny_mce.js is correct, as the development server has no access to files abov...
8
2010-01-11T04:18:13Z
30,350,783
<p>I had a similar problem, I have a one-page-app and Apparently I had a newbie mistake that made django miss my media path i had this:</p> <pre><code>url(r'^', home, name="home"), </code></pre> <p>instead of this:</p> <pre><code>url(r'^$', home, name="home"), </code></pre> <p>the missing <code>$</code> made my url...
0
2015-05-20T13:14:15Z
[ "python", "django", "tinymce" ]
Django One-To-Many Models
2,039,958
<p>The following models describe a vulnerability and the URLs out on the internet that reference that vulnerability. Assume that each URL only ever talks about 1 vulnerability, and that many URLs will discuss that vulnerability. Is this the correct way to lay out the model?</p> <pre><code>class Vuln(models.Model): p...
11
2010-01-11T04:46:32Z
2,039,971
<p>It should be more like this:</p> <pre><code>class Vuln(models.Model): pub_date = models.DateTimeField("Publication Date") short_description = models.CharField("Description", max_length=70) vendor = models.ForeignKey(Vendor, verbose_name="Vendor") class Url(models.Model): url = models.URLField("URL", ma...
22
2010-01-11T04:51:49Z
[ "python", "django", "model", "one-to-many" ]
Sorting datetime objects while ignoring the year?
2,040,038
<p>I have a list of birthdays stored in <a href="http://docs.python.org/library/datetime.html#datetime-objects" rel="nofollow"><code>datetime</code></a> objects. How would one go about sorting these in Python using only the <code>month</code> and <code>day</code> arguments?</p> <p>For example,</p> <pre><code>[ da...
7
2010-01-11T05:13:53Z
2,040,058
<pre><code>l.sort(key = lambda x: x.timetuple()[1:3]) </code></pre>
7
2010-01-11T05:19:41Z
[ "python", "datetime", "sorting" ]
Sorting datetime objects while ignoring the year?
2,040,038
<p>I have a list of birthdays stored in <a href="http://docs.python.org/library/datetime.html#datetime-objects" rel="nofollow"><code>datetime</code></a> objects. How would one go about sorting these in Python using only the <code>month</code> and <code>day</code> arguments?</p> <p>For example,</p> <pre><code>[ da...
7
2010-01-11T05:13:53Z
2,040,062
<p>You can use <code>month</code> and <code>day</code> to create a value that can be used for sorting:</p> <pre><code>birthdays.sort(key = lambda d: (d.month, d.day)) </code></pre>
10
2010-01-11T05:22:11Z
[ "python", "datetime", "sorting" ]
Sorting datetime objects while ignoring the year?
2,040,038
<p>I have a list of birthdays stored in <a href="http://docs.python.org/library/datetime.html#datetime-objects" rel="nofollow"><code>datetime</code></a> objects. How would one go about sorting these in Python using only the <code>month</code> and <code>day</code> arguments?</p> <p>For example,</p> <pre><code>[ da...
7
2010-01-11T05:13:53Z
2,040,125
<p>If the dates are stored as strings—you say they aren't, although it looks like they are—you might use <a href="http://labix.org/python-dateutil" rel="nofollow">dateutil</a>'s parser:</p> <pre><code>&gt;&gt;&gt; from dateutil.parser import parse &gt;&gt;&gt; from pprint import pprint &gt;&gt;&gt; bd = ['February...
3
2010-01-11T05:44:42Z
[ "python", "datetime", "sorting" ]
Using object id as a hash for objects in Python
2,040,101
<p>Is it wise to use the object <code>id</code> as a hash key (via. the <code>__hash__</code>) to be able to hash an otherwise mutable object for a single instance of a program? Using the object attributes would be nicer but they're all mutable and can change. </p> <p>This occurred to me while looking at <a href="http...
7
2010-01-11T05:36:30Z
2,040,110
<p>Yes, as long as you also define <code>__eq__</code> (and presumably <code>__ne__</code>!-) consistently with that. IOW, it's fine, as long as you're fine with <code>a==b</code> meaning exactly the same as <code>a is b</code>!-)</p>
12
2010-01-11T05:39:50Z
[ "python", "hash" ]
Using object id as a hash for objects in Python
2,040,101
<p>Is it wise to use the object <code>id</code> as a hash key (via. the <code>__hash__</code>) to be able to hash an otherwise mutable object for a single instance of a program? Using the object attributes would be nicer but they're all mutable and can change. </p> <p>This occurred to me while looking at <a href="http...
7
2010-01-11T05:36:30Z
2,040,974
<p>For most Python classes this is the default behaviour. The unhashable ones are unhashable for a good reason: they are mutable collections. </p> <p>For collections it is practical to have the equality relation (as defined by <code>__eq__()</code>) based on equality of their contents. This, and the requirement for <c...
5
2010-01-11T09:47:29Z
[ "python", "hash" ]
Python JPype integration
2,040,104
<p>I am using JPype The following is the code i am trying to use </p> <pre><code>from jpype import * startJVM("C:\Program Files\Java\jdk1.6.0_14\jre\bin\client\jvm.dll","-ea") java.lang.System.out.println("hai") shutdownJVM() </code></pre> <p>It is giving error in the execution of the println statement</p> <pre><c...
-1
2010-01-11T05:37:31Z
2,040,196
<p>Looks like you might just be missing a semicolon (<code>;</code>)</p>
-2
2010-01-11T06:04:33Z
[ "java", "python", "jpype" ]
Python JPype integration
2,040,104
<p>I am using JPype The following is the code i am trying to use </p> <pre><code>from jpype import * startJVM("C:\Program Files\Java\jdk1.6.0_14\jre\bin\client\jvm.dll","-ea") java.lang.System.out.println("hai") shutdownJVM() </code></pre> <p>It is giving error in the execution of the println statement</p> <pre><c...
-1
2010-01-11T05:37:31Z
2,040,270
<p>Firstly, are all the dependencies setup correctly? Java, Python, JPype etc?</p> <p>You are trying to execute one of the first examples in the documentation.</p> <p>The sample they provide in the docs are:</p> <pre><code>from jpype import * startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea") java.lang.Syste...
-1
2010-01-11T06:25:09Z
[ "java", "python", "jpype" ]
Index of item in list when only part of the item is known
2,040,298
<p>This is a follow-up on a previous question of mine regarding <a href="http://stackoverflow.com/questions/1156087/python-search-in-lists-of-lists">searching in lists of lists</a></p> <p>I have a list with pairs of values as lists in it. </p> <blockquote> <p>[['a',5], ['b',3], ['c',2] ]</p> </blockquote> <p>I kno...
0
2010-01-11T06:32:22Z
2,040,316
<pre><code>[x[0] for x in list].index('a') </code></pre> <p>But if you are running this code several times, you might want to save the list of x[0]'s.</p>
5
2010-01-11T06:37:14Z
[ "python", "search", "indexing", "list" ]
Index of item in list when only part of the item is known
2,040,298
<p>This is a follow-up on a previous question of mine regarding <a href="http://stackoverflow.com/questions/1156087/python-search-in-lists-of-lists">searching in lists of lists</a></p> <p>I have a list with pairs of values as lists in it. </p> <blockquote> <p>[['a',5], ['b',3], ['c',2] ]</p> </blockquote> <p>I kno...
0
2010-01-11T06:32:22Z
2,040,345
<p>A simple, flexible one line version:</p> <pre><code>[i for (i, item) in enumerate([('a', 1), ('b', 3), ('a', 5)]) if item[0] == 'a'] # returns [0, 2] [i for (i, item) in enumerate([('a', 1), ('b', 3), ('a', 5)]) if item[0] == 'a'][0] # returns 0 </code></pre> <p>You could wrap it in a function, replace <code>item...
2
2010-01-11T06:44:35Z
[ "python", "search", "indexing", "list" ]
Index of item in list when only part of the item is known
2,040,298
<p>This is a follow-up on a previous question of mine regarding <a href="http://stackoverflow.com/questions/1156087/python-search-in-lists-of-lists">searching in lists of lists</a></p> <p>I have a list with pairs of values as lists in it. </p> <blockquote> <p>[['a',5], ['b',3], ['c',2] ]</p> </blockquote> <p>I kno...
0
2010-01-11T06:32:22Z
2,040,392
<p>You already have the original list from which you know the first elements. List call it orig_list. Get the element's index from the original list and use that index in the new list to retrieve.</p> <pre><code>&gt;&gt;&gt; orig_list = ['a','b','c'] &gt;&gt;&gt; calc_list = [['a',5], ['b',3], ['c',2] ] &gt;&gt;&gt; ...
2
2010-01-11T07:03:23Z
[ "python", "search", "indexing", "list" ]
Index of item in list when only part of the item is known
2,040,298
<p>This is a follow-up on a previous question of mine regarding <a href="http://stackoverflow.com/questions/1156087/python-search-in-lists-of-lists">searching in lists of lists</a></p> <p>I have a list with pairs of values as lists in it. </p> <blockquote> <p>[['a',5], ['b',3], ['c',2] ]</p> </blockquote> <p>I kno...
0
2010-01-11T06:32:22Z
2,040,480
<p>There's a similar solution to that of Ofris</p> <pre><code>D = dict([ [x[1][0], x[0] ] for x in list(enumerate(L)) ]) D['a'] #returns 0 </code></pre> <p>But another nice feature is that if you tweak this a little you can pull out your original values</p> <pre><code>D = dict([ [x[1][0], (x[0], x[1][1] ) ] for x ...
4
2010-01-11T07:36:24Z
[ "python", "search", "indexing", "list" ]
Index of item in list when only part of the item is known
2,040,298
<p>This is a follow-up on a previous question of mine regarding <a href="http://stackoverflow.com/questions/1156087/python-search-in-lists-of-lists">searching in lists of lists</a></p> <p>I have a list with pairs of values as lists in it. </p> <blockquote> <p>[['a',5], ['b',3], ['c',2] ]</p> </blockquote> <p>I kno...
0
2010-01-11T06:32:22Z
2,040,720
<p>The code below will get the indexes of all items in the list that match the pattern <code>['a', ?]</code>:</p> <pre><code>&gt;&gt;&gt; l = [['a',5], ['b',3], ['c',2], ['a',8]] &gt;&gt;&gt; indexes = [l.index(x) for x in l if x[0] == 'a'] &gt;&gt;&gt; print indexes [0, 3] </code></pre>
1
2010-01-11T08:52:20Z
[ "python", "search", "indexing", "list" ]
Python library needed
2,040,531
<p>I am trying to run a python script which has the following statements:</p> <pre><code>import random as RD import pylab as PL import scipy as SP import networkx as NX </code></pre> <p>Where can I download these packages?</p> <p>I have installed these packages and I get the following error when I run my code</p> <...
1
2010-01-11T07:58:23Z
2,040,540
<ol> <li>'random' is shipped with the standard library</li> <li>pylab and scipy are part of <a href="http://www.scipy.org/SciPy" rel="nofollow">SciPy</a></li> <li>Networkx <a href="http://networkx.lanl.gov/" rel="nofollow">is available here</a></li> </ol>
2
2010-01-11T08:00:42Z
[ "python", "random", "scipy", "matplotlib", "networkx" ]
Python library needed
2,040,531
<p>I am trying to run a python script which has the following statements:</p> <pre><code>import random as RD import pylab as PL import scipy as SP import networkx as NX </code></pre> <p>Where can I download these packages?</p> <p>I have installed these packages and I get the following error when I run my code</p> <...
1
2010-01-11T07:58:23Z
2,040,542
<p>Here's a link to the non standard libraries. random is part of the standard library.</p> <p><a href="http://matplotlib.sourceforge.net/" rel="nofollow">matplotlib</a></p> <p><a href="http://scipy.org/" rel="nofollow">scipy</a></p> <p><a href="http://networkx.lanl.gov/" rel="nofollow">networkX</a></p> <p><a href...
2
2010-01-11T08:01:10Z
[ "python", "random", "scipy", "matplotlib", "networkx" ]
Python library needed
2,040,531
<p>I am trying to run a python script which has the following statements:</p> <pre><code>import random as RD import pylab as PL import scipy as SP import networkx as NX </code></pre> <p>Where can I download these packages?</p> <p>I have installed these packages and I get the following error when I run my code</p> <...
1
2010-01-11T07:58:23Z
2,040,554
<p><a href="http://docs.python.org/library/random.html" rel="nofollow">random</a> is a standard python library module, no need to install that.</p> <p>pylab and scipy can be found on the <a href="http://www.scipy.org/SciPy" rel="nofollow">SciPy</a> site</p> <p>networkx also has a <a href="http://networkx.lanl.gov/" r...
2
2010-01-11T08:04:47Z
[ "python", "random", "scipy", "matplotlib", "networkx" ]
Python library needed
2,040,531
<p>I am trying to run a python script which has the following statements:</p> <pre><code>import random as RD import pylab as PL import scipy as SP import networkx as NX </code></pre> <p>Where can I download these packages?</p> <p>I have installed these packages and I get the following error when I run my code</p> <...
1
2010-01-11T07:58:23Z
2,042,419
<p>When installing Scipy, you also need to install numpy which it depends on. See <a href="http://scipy.org/Download" rel="nofollow">here</a>. You are getting the error because numpy is not installed on your system.</p>
1
2010-01-11T14:33:43Z
[ "python", "random", "scipy", "matplotlib", "networkx" ]
Sets module deprecated warning
2,040,616
<p>When I run my python script I get the following warning</p> <pre><code>DeprecationWarning: the sets module is deprecated </code></pre> <p>How do I fix this?</p>
23
2010-01-11T08:25:12Z
2,040,629
<p>You don't need to import the <code>sets</code> module to use them, they're in the builtin namespace.</p>
2
2010-01-11T08:29:59Z
[ "python" ]
Sets module deprecated warning
2,040,616
<p>When I run my python script I get the following warning</p> <pre><code>DeprecationWarning: the sets module is deprecated </code></pre> <p>How do I fix this?</p>
23
2010-01-11T08:25:12Z
2,040,630
<p>Stop using the <code>sets</code> module, or switch to an older version of python where it's not deprecated.</p> <p>According to <a href="http://www.python.org/dev/peps/pep-0004/">pep-004</a>, <code>sets</code> is deprecated as of v2.6, replaced by the built-in <a href="http://docs.python.org/library/stdtypes.html#s...
30
2010-01-11T08:30:10Z
[ "python" ]
Sets module deprecated warning
2,040,616
<p>When I run my python script I get the following warning</p> <pre><code>DeprecationWarning: the sets module is deprecated </code></pre> <p>How do I fix this?</p>
23
2010-01-11T08:25:12Z
2,040,634
<p>Use the builting <code>set</code> instead of importing sets module</p> <p>From <a href="http://docs.python.org/whatsnew/2.6.html" rel="nofollow">documentation</a>:</p> <blockquote> <p>The sets module has been deprecated; it’s better to use the built-in set and frozenset types.</p> </blockquote>
4
2010-01-11T08:30:55Z
[ "python" ]
Sets module deprecated warning
2,040,616
<p>When I run my python script I get the following warning</p> <pre><code>DeprecationWarning: the sets module is deprecated </code></pre> <p>How do I fix this?</p>
23
2010-01-11T08:25:12Z
2,040,746
<p>History:</p> <p>Before Python 2.3: no set functionality<br> Python 2.3: <code>sets</code> module arrived<br> Python 2.4: <code>set</code> and <code>frozenset</code> built-ins introduced<br> Python 2.6: <code>sets</code> module deprecated </p> <p>You should change your code to use <code>set</code> instead of <code...
25
2010-01-11T08:58:44Z
[ "python" ]
Sets module deprecated warning
2,040,616
<p>When I run my python script I get the following warning</p> <pre><code>DeprecationWarning: the sets module is deprecated </code></pre> <p>How do I fix this?</p>
23
2010-01-11T08:25:12Z
2,047,600
<p>If you want to fix it James definitely has the right answer, but in case you want to just turn off deprecation warnings, you can run python like so:</p> <pre><code>$ python -Wignore::DeprecationWarning Python 2.6.2 (r262:71600, Sep 20 2009, 20:47:22) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "cop...
5
2010-01-12T08:27:25Z
[ "python" ]
Is there a better library than urlgrabber for fetching remote urls in python?
2,040,628
<p>I'm writing a spider that needs a <code>load_url</code> function that performs the following for me:</p> <ol> <li>Retry the URL if there is a temporary error, without leaking exceptions.</li> <li>Not leak memory or file handles</li> <li>Use HTTP-KeepAlive for speed (optional)</li> </ol> <p><a href="http://linux.du...
2
2010-01-11T08:29:37Z
2,040,640
<p>Screen-scraping? Check out <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a></p>
0
2010-01-11T08:33:06Z
[ "python", "screen-scraping" ]