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
Using web.py as non blocking http-server
500,935
<p>while learning some basic programming with python, i found web.py. i got stuck with a stupid problem:</p> <p>i wrote a simple console app with a main loop that proccesses items from a queue in seperate threads. my goal is to use web.py to add items to my queue and report status of the queue via web request. i got t...
14
2009-02-01T14:47:24Z
501,570
<p>Wouldn't is be simpler to re-write your main-loop code to be a function that you call over and over again, and then call that from the function that you pass to <code>runsimple</code>...</p> <p>It's guaranteed not to fully satisfy your requirements, but if you're in a rush, it might be easiest.</p>
1
2009-02-01T21:01:21Z
[ "python", "multithreading", "web-services", "web.py" ]
Using web.py as non blocking http-server
500,935
<p>while learning some basic programming with python, i found web.py. i got stuck with a stupid problem:</p> <p>i wrote a simple console app with a main loop that proccesses items from a queue in seperate threads. my goal is to use web.py to add items to my queue and report status of the queue via web request. i got t...
14
2009-02-01T14:47:24Z
1,872,235
<p>or just use Tornado, a non-blocking webserver for Python that has an API similar to webpy - <a href="http://www.tornadoweb.org/" rel="nofollow">http://www.tornadoweb.org/</a></p>
1
2009-12-09T07:39:09Z
[ "python", "multithreading", "web-services", "web.py" ]
Using web.py as non blocking http-server
500,935
<p>while learning some basic programming with python, i found web.py. i got stuck with a stupid problem:</p> <p>i wrote a simple console app with a main loop that proccesses items from a queue in seperate threads. my goal is to use web.py to add items to my queue and report status of the queue via web request. i got t...
14
2009-02-01T14:47:24Z
3,949,776
<p>I found a working solution. In a seperate module i create my webserver:</p> <pre><code>import web import threading class MyWebserver(threading.Thread): def run (self): urls = ('/', 'MyWebserver') app = web.application(urls, globals()) app.run() def POST ... </code></pre> <p>In the...
6
2010-10-16T16:42:00Z
[ "python", "multithreading", "web-services", "web.py" ]
Using web.py as non blocking http-server
500,935
<p>while learning some basic programming with python, i found web.py. i got stuck with a stupid problem:</p> <p>i wrote a simple console app with a main loop that proccesses items from a queue in seperate threads. my goal is to use web.py to add items to my queue and report status of the queue via web request. i got t...
14
2009-02-01T14:47:24Z
4,382,828
<p>I have also recently used <a href="http://kr.github.com/beanstalkd/" rel="nofollow">Beanstalkd</a> to queue up tasks that will run in a separate thread. Your web.py handler just drops a job into a pipe and a completely separate script executes it. You could have any number of these, and you get the benefits of adv...
0
2010-12-07T23:39:22Z
[ "python", "multithreading", "web-services", "web.py" ]
Python + SQLite query to find entries that sit in a specified time slot
501,021
<p>I want to store a row in an SQLite 3 table for each booking in my diary.</p> <p>Each row will have a 'start time' and a 'end time'.</p> <p>Does any one know how I can query the table for an event at a given time?</p> <p>E.g. Return any rows that happen at say 10:30am</p> <p>Thanks </p>
1
2009-02-01T15:45:53Z
501,037
<p>SQLite3 doesn't have a datetime type, though it does have <a href="http://www.sqlite.org/lang_datefunc.html" rel="nofollow">date and time functions</a>.</p> <p>Typically you store dates and times in your database in something like ISO 8601 format: <code>YYYY-MM-DD HH:MM:SS</code>. Then datetimes sort lexicographica...
2
2009-02-01T15:53:22Z
[ "python", "sql", "sqlite" ]
list named with a function argument in python
501,027
<p>I get the feeling this is probably something I should know but I can't think of it right now. I'm trying to get a function to build a list where the name of the list is an argument given in the function;</p> <p>e.g.</p> <pre><code>def make_hand(deck, handname): handname = [] for c in range(5): hand...
1
2009-02-01T15:48:34Z
501,041
<p>You can keep a dictionary where the keys are the name of the hand and the values are the list. </p> <p>Then you can just say dictionary[handname] to access a particular hand. Along the lines of:</p> <pre><code>hands = {} # Create a new dictionary to hold the hands. hands["flush"] = make_hand(deck) # Generate some ...
6
2009-02-01T15:55:08Z
[ "python", "list", "arguments" ]
list named with a function argument in python
501,027
<p>I get the feeling this is probably something I should know but I can't think of it right now. I'm trying to get a function to build a list where the name of the list is an argument given in the function;</p> <p>e.g.</p> <pre><code>def make_hand(deck, handname): handname = [] for c in range(5): hand...
1
2009-02-01T15:48:34Z
501,061
<p>While you can create variables with arbitrary names at runtime, using <code>exec</code> (as sykora suggested), or by meddlings with <code>locals</code>, <code>globals</code> or <code>setattr</code> on objects, your question is somewhat moot.</p> <p>An object (just about anything, from integers to classes with 1000 ...
2
2009-02-01T16:05:21Z
[ "python", "list", "arguments" ]
XMP image tagging and Python
501,087
<p>If I were to tag a bunch of images via XMP, in Python, what would be the best way? I've used Perl's <strong>Image::ExifTool</strong> and I am very much used to its reliability. I mean the thing never bricked on tens of thousands of images.</p> <p>I found <a href="http://code.google.com/p/python-xmp-toolkit/" rel="n...
2
2009-02-01T16:28:14Z
501,120
<p>Well, they website says that the python-xmp-toolkit uses Exempi, which is based on the Adobe XMP toolkit, via ctypes. What I'm trying to say is that you're not likely to create a better wrapping of the C++ code yourself. If it's unstable (i.e. buggy), it's most likely still cheaper for you to create patches than doi...
4
2009-02-01T16:44:56Z
[ "python", "xmp" ]
XMP image tagging and Python
501,087
<p>If I were to tag a bunch of images via XMP, in Python, what would be the best way? I've used Perl's <strong>Image::ExifTool</strong> and I am very much used to its reliability. I mean the thing never bricked on tens of thousands of images.</p> <p>I found <a href="http://code.google.com/p/python-xmp-toolkit/" rel="n...
2
2009-02-01T16:28:14Z
510,053
<p>You can use ImageMagic <a href="http://www.imagemagick.org/www/convert.html" rel="nofollow">convert</a>, IIRC there's a Python module to it as well.</p>
0
2009-02-04T04:21:00Z
[ "python", "xmp" ]
XMP image tagging and Python
501,087
<p>If I were to tag a bunch of images via XMP, in Python, what would be the best way? I've used Perl's <strong>Image::ExifTool</strong> and I am very much used to its reliability. I mean the thing never bricked on tens of thousands of images.</p> <p>I found <a href="http://code.google.com/p/python-xmp-toolkit/" rel="n...
2
2009-02-01T16:28:14Z
3,698,634
<p>I struggled for several hours with python-xmp-toolkit, and eventually gave up and just wrapped calls to <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/" rel="nofollow">ExifTool</a>.</p> <p>There is <a href="http://miniexiftool.rubyforge.org/" rel="nofollow">a Ruby library</a> that wraps ExifTool as well (alb...
4
2010-09-13T07:52:36Z
[ "python", "xmp" ]
"EOL while scanning single-quoted string"? (backslash in string)
501,187
<pre><code>import os xp1 = "\Documents and Settings\" xp2 = os.getenv("USERNAME") print xp1+xp2 </code></pre> <p>Gives me error</p> <pre><code> File "1.py", line 2 xp1 = "\Documents and Settings\" ^ SyntaxError: EOL while scannning single-quoted string </code></pre> <p>Can you help me...
1
2009-02-01T17:20:02Z
501,197
<p>The backslash character is interpreted as an escape. Use double backslashes for windows paths:</p> <pre><code>&gt;&gt;&gt; xp1 = "\\Documents and Settings\\" &gt;&gt;&gt; xp1 '\\Documents and Settings\\' &gt;&gt;&gt; print xp1 \Documents and Settings\ &gt;&gt;&gt; </code></pre>
19
2009-02-01T17:25:09Z
[ "python", "syntax-error" ]
"EOL while scanning single-quoted string"? (backslash in string)
501,187
<pre><code>import os xp1 = "\Documents and Settings\" xp2 = os.getenv("USERNAME") print xp1+xp2 </code></pre> <p>Gives me error</p> <pre><code> File "1.py", line 2 xp1 = "\Documents and Settings\" ^ SyntaxError: EOL while scannning single-quoted string </code></pre> <p>Can you help me...
1
2009-02-01T17:20:02Z
501,202
<p>Additionally to the blackslash problem, don't join paths with the "+" operator -- use <code>os.path.join</code> instead.</p> <p>Also, construct the path to a user's home directory like that is likely to fail on new versions of Windows. There are API functions for that in pywin32.</p>
10
2009-02-01T17:26:31Z
[ "python", "syntax-error" ]
"EOL while scanning single-quoted string"? (backslash in string)
501,187
<pre><code>import os xp1 = "\Documents and Settings\" xp2 = os.getenv("USERNAME") print xp1+xp2 </code></pre> <p>Gives me error</p> <pre><code> File "1.py", line 2 xp1 = "\Documents and Settings\" ^ SyntaxError: EOL while scannning single-quoted string </code></pre> <p>Can you help me...
1
2009-02-01T17:20:02Z
501,225
<p>You can use the <code>os.path.expanduser</code> function to get the path to a users home-directory. It doesn't even have to be an existing user.</p> <pre><code>&gt;&gt;&gt; import os.path &gt;&gt;&gt; os.path.expanduser('~foo') 'C:\\Documents and Settings\\foo' &gt;&gt;&gt; print os.path.expanduser('~foo') C:\Docum...
7
2009-02-01T17:39:28Z
[ "python", "syntax-error" ]
"EOL while scanning single-quoted string"? (backslash in string)
501,187
<pre><code>import os xp1 = "\Documents and Settings\" xp2 = os.getenv("USERNAME") print xp1+xp2 </code></pre> <p>Gives me error</p> <pre><code> File "1.py", line 2 xp1 = "\Documents and Settings\" ^ SyntaxError: EOL while scannning single-quoted string </code></pre> <p>Can you help me...
1
2009-02-01T17:20:02Z
501,251
<p>Python, as many other languages, uses the backslash as an escape character (the double-quotes at the end of your xp1=... line are therefore considered as part of the string, not as the delimiter of the string).</p> <p>This is actually pretty basic stuff, so I strongly recommend you read the <a href="http://docs.pyt...
5
2009-02-01T17:53:46Z
[ "python", "syntax-error" ]
"EOL while scanning single-quoted string"? (backslash in string)
501,187
<pre><code>import os xp1 = "\Documents and Settings\" xp2 = os.getenv("USERNAME") print xp1+xp2 </code></pre> <p>Gives me error</p> <pre><code> File "1.py", line 2 xp1 = "\Documents and Settings\" ^ SyntaxError: EOL while scannning single-quoted string </code></pre> <p>Can you help me...
1
2009-02-01T17:20:02Z
8,442,196
<p><code>\"</code> is interpreted as "insert a double-quote into the string, so you are missing a terminating quote for the string literal. Note that a raw string <code>r"\"</code> can't help either.</p> <p>Quote from the <a href="http://docs.python.org/reference/lexical_analysis.html#string-literals" rel="nofollow">...
1
2011-12-09T07:09:22Z
[ "python", "syntax-error" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
501,318
<p><code>[e[1] * e[0] for e in elt]</code> is a list comprehension, which evaluates to a list itself by looping through another list, in this case <code>elt</code>. Each element in the new list is <code>e[1]*e[0]</code>, where <code>e</code> is the corresponding element in <code>elt</code>.</p>
4
2009-02-01T18:28:03Z
[ "python", "list-comprehension" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
501,320
<p>join() is a string method, that works on a separator in new string</p> <pre><code>&gt;&gt;&gt; ':'.join(['ab', 'cd']) &gt;&gt;&gt; 'ab:cd' </code></pre> <p>and list comprehension is not necessary there, generator would suffice</p>
1
2009-02-01T18:33:19Z
[ "python", "list-comprehension" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
501,321
<p>Firstly, you need to put http:// in front of the URL, ie: handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p")</p> <p>An expression [e for e in aList] is a <a href="http://en.wikipedia.org/wiki/List_comprehension" rel="nofollow">list comprehension</a> which generates a list of values.</p> <p>W...
6
2009-02-01T18:34:12Z
[ "python", "list-comprehension" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
501,323
<p>Maybe best explained with an example:</p> <pre><code>print "".join([e[1] * e[0] for e in elt]) </code></pre> <p>is the short form of</p> <pre><code>x = [] for e in elt: x.append(e[1] * e[0]) print "".join(x) </code></pre> <p>List comprehensions are simply syntactic sugar for <code>for</code> loops, which make ...
18
2009-02-01T18:34:33Z
[ "python", "list-comprehension" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
501,402
<p>Andy's is a great answer!</p> <p>If you want to see every step of the loop (with line-breaks) try this out:</p> <pre><code>for elt in data: for e in elt: print "e[0] == %s, e[1] == %d, which gives us: '%s'" % (e[0], e[1], ''.join(e[1] * e[0])) </code></pre>
1
2009-02-01T19:15:46Z
[ "python", "list-comprehension" ]
Problem in understanding Python list comprehensions
501,308
<p>What does the last line mean in the following code?</p> <pre><code>import pickle, urllib handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p") ...
4
2009-02-01T18:22:26Z
508,898
<p>The question itself has already been fully answered but I'd like to add that a list comprehension also supports filtering. Your original line</p> <pre><code>print "".join([e[1] * e[0] for e in elt]) </code></pre> <p>could, as an example, become</p> <pre><code>print "".join([e[1] * e[0] for e in elt if len(e) =...
2
2009-02-03T21:06:38Z
[ "python", "list-comprehension" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
501,606
<p>From your example, it appears as though you want to execute a Python script and have the output of the script appear in the current Vim buffer. If that's correct, then you can do the following at the command line in Vim:</p> <pre><code>%!python -c "for i in xrange(25): print 6*i" </code></pre> <p>The <code>-c</cod...
5
2009-02-01T21:21:47Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
501,619
<p>I think you't just missing the <code>-c</code> flag. For example:</p> <pre><code>:.!python -c "print 'hello'" </code></pre> <p>You should not that the script that you provide acts as a filter on the line selection. That is, your script can read from <code>stdin</code> to operate directly on the lines given (<code>...
1
2009-02-01T21:27:04Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
501,698
<p>In any of your vim windows, type something like this:</p> <pre><code>for x in range(1,10): print '-&gt; %d' % x </code></pre> <p>Visually select both of those lines (V to start visual mode), and type the following:</p> <pre><code>:!python </code></pre> <p>Because you pressed ':' in visual mode, that will end...
155
2009-02-01T22:17:12Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
501,790
<blockquote> <p>Can someone elaborate this point: "your script can read from stdin to operate directly on the lines given (., %, ...)."</p> </blockquote> <p>One common use is to sort lines of text using the 'sort' command available in your shell. For example, you can sort the whole file using this command:</p> <pre...
6
2009-02-01T23:00:46Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
501,812
<blockquote> <p>If I want to print 'Hello' to lines 4,5, 6 and 7, what is wrong:</p> </blockquote> <p>If you want to do something in randomly chosen places throughout your file, you're better of recording keystrokes and replaying them. Go to the first line you want to change, and hit <code>qz</code> to starting reco...
0
2009-02-01T23:17:23Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
506,938
<p>If you want to do some python calls without compiling vim with the python interpreter (that would allow you to write plug-ins in Python, and it's also needed for Omnicomplete anyway) you can try as this:</p> <pre><code>:.!python -c "import os; print os.getcwd()" </code></pre> <p>That would tell you where you are i...
0
2009-02-03T12:41:55Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
513,634
<p>I think what you really want is explained <a href="http://vim.wikia.com/wiki/Execute_Python_from_within_current_file" rel="nofollow">here</a>. </p>
0
2009-02-04T22:18:09Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
1,275,093
<p>I am unsure of their usefulness, perhaps for further reading:</p> <ul> <li><a href="http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html" rel="nofollow">Python and vim: Two great tastes that go great together by Sean Reifschneider (Advanced)</a></li> <li><a href="http://dancingpenguinsoflight.co...
2
2009-08-13T22:55:18Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
4,660,124
<p>You can execute the code, read the output on the cursor and finish with <code>u</code>, supposing you are executing python code. Simple and quick.</p> <pre><code>:r !python % u </code></pre> <p>I like it over mapping and selecting-in-visual-mode, like with <a href="http://stackoverflow.com/questions/501585/how-ca...
0
2011-01-11T16:46:02Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
15,468,245
<p>I just wrote the following module that lets you edit a temporary buffer in vim directly in the Python interpreter.</p> <p><a href="http://philipbjorge.github.com/EditREPL/" rel="nofollow">http://philipbjorge.github.com/EditREPL/</a></p>
1
2013-03-18T01:01:46Z
[ "python", "vim" ]
How can you use Python in Vim?
501,585
<p>I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:</p> <blockquote> <p>%!python for i in xrange(25); print 6*i \n </p> </blockquote> <p>How can you do such tweaks direcly in Vim? <strong>[Solved]</strong></p> ...
50
2009-02-01T21:10:02Z
18,146,697
<p>On Windows, if you are editing the python script, just do:</p> <pre><code>!start python my... </code></pre> <p>and press <code>tab</code> to cycle along the available file names, until you find your match:</p> <pre><code>!start python myscript.py </code></pre> <p>It will run in a new <code>cmd</code> window. Per...
0
2013-08-09T12:28:55Z
[ "python", "vim" ]
How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?
501,597
<p>Currently I'm using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more "pythonic".</p> <p>My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's ...
8
2009-02-01T21:18:01Z
501,624
<p>In general, yes - everything is better than autotools when building Python projects.</p> <p>I have good experiences with setuptools so far. However, installing files into fixed locations is not a strength of setuptools - after all, it's not something to build installaters for Python apps, but distribute Python libr...
1
2009-02-01T21:31:36Z
[ "python", "packaging", "setuptools", "gnome", "distutils2" ]
How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?
501,597
<p>Currently I'm using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more "pythonic".</p> <p>My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's ...
8
2009-02-01T21:18:01Z
2,291,791
<p>You can try to use <a href="https://launchpad.net/python-distutils-extra" rel="nofollow">python-distutils-extra</a>. The <code>DistUtilsExtra.auto</code> module automatically <a href="http://bazaar.launchpad.net/~python-distutils-extra-hackers/python-distutils-extra/debian/annotate/head:/doc/README" rel="nofollow">...
1
2010-02-18T20:02:37Z
[ "python", "packaging", "setuptools", "gnome", "distutils2" ]
How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?
501,597
<p>Currently I'm using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more "pythonic".</p> <p>My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's ...
8
2009-02-01T21:18:01Z
24,116,911
<p><strong>I managed to get this to work, but it kinda feels to me more like a <em>workaround</em>.</strong> </p> <p>Don't know what's the preferred way to handle this...</p> <p>I used the following <code>setup.py</code> file (full version is <a href="https://gist.github.com/brutus/e4bdb1d2c1705558b2ff" rel="nofollow...
4
2014-06-09T09:03:00Z
[ "python", "packaging", "setuptools", "gnome", "distutils2" ]
How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?
501,597
<p>Currently I'm using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more "pythonic".</p> <p>My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's ...
8
2009-02-01T21:18:01Z
28,157,740
<p>I've created <a href="https://pypi.python.org/pypi/install-freedesktop" rel="nofollow">https://pypi.python.org/pypi/install-freedesktop</a>. It creates .desktop files automatically for the gui_scripts entry points, which can be customized through a setup argument, and supports <code>--user</code> as well as system-w...
1
2015-01-26T19:57:46Z
[ "python", "packaging", "setuptools", "gnome", "distutils2" ]
Both Python 2 and 3 in Emacs
501,626
<p>I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.</p> <p>Here is how the different versions are set up in /usr/bin:</p> <pre><code>python -&gt; python2.6* python2 -&gt; python2.6* python2.6* python3 -&gt; python3.0...
16
2009-02-01T21:32:47Z
502,304
<p>The answer is yes. If you can distinguish Python 2 from Python 3, then it is a Simple Matter Of Programming to get emacs to do what you want.</p> <pre><code>(define run-python (&amp;optional buffer) (with-current-buffer (or buffer (current-buffer)) (if (is-python3-p) (run-python3) ...
4
2009-02-02T05:49:42Z
[ "python", "emacs", "python-3.x" ]
Both Python 2 and 3 in Emacs
501,626
<p>I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.</p> <p>Here is how the different versions are set up in /usr/bin:</p> <pre><code>python -&gt; python2.6* python2 -&gt; python2.6* python2.6* python3 -&gt; python3.0...
16
2009-02-01T21:32:47Z
502,422
<p>If you are using python-mode.el you can try to change <code>py-which-shell</code>. In order to do this on a per-file basis you can put</p> <pre><code># -*- py-which-shell: "python3"; -*- </code></pre> <p>at the first line of your file - or at the second line if the first line starts with <code>#!</code>. Another c...
10
2009-02-02T07:14:45Z
[ "python", "emacs", "python-3.x" ]
Both Python 2 and 3 in Emacs
501,626
<p>I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.</p> <p>Here is how the different versions are set up in /usr/bin:</p> <pre><code>python -&gt; python2.6* python2 -&gt; python2.6* python2.6* python3 -&gt; python3.0...
16
2009-02-01T21:32:47Z
1,460,880
<p>My comment on <a href="http://stackoverflow.com/questions/501626/both-python-2-and-3-in-emacs/502422#502422">this answer</a>. </p> <p>I wrote /t/min.py which will run fine in python3 but not in python2 (dictionary comprehension works in python3)</p> <p>Contents of /t/min.py</p> <pre><code>#!/usr/bin/python3 # -*-...
3
2009-09-22T15:42:25Z
[ "python", "emacs", "python-3.x" ]
Both Python 2 and 3 in Emacs
501,626
<p>I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.</p> <p>Here is how the different versions are set up in /usr/bin:</p> <pre><code>python -&gt; python2.6* python2 -&gt; python2.6* python2.6* python3 -&gt; python3.0...
16
2009-02-01T21:32:47Z
6,006,909
<p>regarding jrockway's comment:</p> <pre><code>(defun is-python3-p () "Check whether we're running python 2 or 3." (setq mystr (first (split-string (buffer-string) "\n" t))) (with-temp-buffer (insert mystr) (goto-char 0) (search-forward "python3" nil t))) (defun run-python () "Call the python interpre...
2
2011-05-15T06:39:38Z
[ "python", "emacs", "python-3.x" ]
Both Python 2 and 3 in Emacs
501,626
<p>I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.</p> <p>Here is how the different versions are set up in /usr/bin:</p> <pre><code>python -&gt; python2.6* python2 -&gt; python2.6* python2.6* python3 -&gt; python3.0...
16
2009-02-01T21:32:47Z
11,674,725
<p>With current <code>python-mode.el</code> shebang is honored.</p> <p>Interactively open a Python shell just with</p> <pre><code>M-x pythonVERSION M-x python </code></pre> <p>will call the installed default.</p> <p><a href="http://launchpad.net/python-mode" rel="nofollow">http://launchpad.net/python-mode</a></...
0
2012-07-26T17:27:19Z
[ "python", "emacs", "python-3.x" ]
How can I execute Python code without Komodo -ide?
501,817
<p>I do that without the IDE: </p> <pre><code>$ ipython $ edit file.py $ :x (save and close) </code></pre> <p>It executes Python code, but not the one, where I use Pygame. It gives:</p> <blockquote> <p>WARNING: Failure executing file: </p> </blockquote> <p>In the IDE, my code executes.</p>
-1
2009-02-01T23:19:44Z
501,882
<p>If something doesn't work in <code>ipython</code>, try the real Python interpreter (just <code>python</code>); <code>ipython</code> has known bugs, and not infrequently code known to work in the real interpreter fails there.</p> <p>On UNIXlike platforms, your script should start with a shebang -- that is, a line li...
1
2009-02-02T00:09:58Z
[ "python", "ide", "executable" ]
Simple simulations for Physics in Python?
501,940
<p>I would like to know similar, concrete simulations, as the simulation about watering a field <a href="http://stackoverflow.com/questions/494184/simulation-problem-with-mouse-in-pygame">here</a>.</p> <p>What is your favorite library/internet page for such simulations in Python?</p> <p>I know little Simpy, Numpy and...
7
2009-02-02T00:55:03Z
502,377
<p>Here is some simple <a href="http://www.astro.sunysb.edu/mzingale/software/astro/" rel="nofollow">astronomy related python</a>. And here is a <a href="http://www.astro.sunysb.edu/mzingale/pyro/" rel="nofollow">hardcore code</a> from the same guy.</p> <p>And <a href="http://kingkong.amath.washington.edu/claw/exampl...
3
2009-02-02T06:35:35Z
[ "python", "modeling", "simulation" ]
Simple simulations for Physics in Python?
501,940
<p>I would like to know similar, concrete simulations, as the simulation about watering a field <a href="http://stackoverflow.com/questions/494184/simulation-problem-with-mouse-in-pygame">here</a>.</p> <p>What is your favorite library/internet page for such simulations in Python?</p> <p>I know little Simpy, Numpy and...
7
2009-02-02T00:55:03Z
502,627
<p>If you are looking for some <em>game</em> physics (collisions, deformations, gravity, etc.) which <em>looks</em> real and is reasonably <em>fast</em> consider re-using some <em>physics engine</em> libraries.</p> <p>As a first reference, you may want to look into <a href="http://www.pymunk.org/" rel="nofollow">pymun...
10
2009-02-02T09:06:01Z
[ "python", "modeling", "simulation" ]
Simple simulations for Physics in Python?
501,940
<p>I would like to know similar, concrete simulations, as the simulation about watering a field <a href="http://stackoverflow.com/questions/494184/simulation-problem-with-mouse-in-pygame">here</a>.</p> <p>What is your favorite library/internet page for such simulations in Python?</p> <p>I know little Simpy, Numpy and...
7
2009-02-02T00:55:03Z
503,010
<p>Maybe <a href="http://pyode.sourceforge.net/" rel="nofollow">PyODE</a>?</p>
2
2009-02-02T12:15:30Z
[ "python", "modeling", "simulation" ]
Simple simulations for Physics in Python?
501,940
<p>I would like to know similar, concrete simulations, as the simulation about watering a field <a href="http://stackoverflow.com/questions/494184/simulation-problem-with-mouse-in-pygame">here</a>.</p> <p>What is your favorite library/internet page for such simulations in Python?</p> <p>I know little Simpy, Numpy and...
7
2009-02-02T00:55:03Z
505,002
<p>I've heard of <a href="http://www.box2d.org/wiki/index.php?title=PyBox2D" rel="nofollow">PyBox2D</a>, which is a port of the really nice Box2D. To quote the site:</p> <blockquote> <p>Box2D is a feature rich 2d rigid body physics engine, written in C++ by Erin Catto. It has been used in many games, including Cray...
1
2009-02-02T21:24:26Z
[ "python", "modeling", "simulation" ]
How to modularize a Python application
501,945
<p>I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come...
5
2009-02-02T00:59:26Z
501,958
<p>You can set the <code>PYTHONPATH</code> environment variable to the directory where your library files are located. This adds that path to the library search path and you can use a normal <code>import</code> to import them.</p>
4
2009-02-02T01:13:15Z
[ "python" ]
How to modularize a Python application
501,945
<p>I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come...
5
2009-02-02T00:59:26Z
501,960
<p>Another alternative to manually adding the path to <code>sys.path</code> is to use the environment variable <a href="http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH" rel="nofollow"><code>PYTHONPATH</code></a>.</p> <p>Also, <a href="http://docs.python.org/install/index.html" rel="nofollow"><code>distutil...
1
2009-02-02T01:13:51Z
[ "python" ]
How to modularize a Python application
501,945
<p>I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come...
5
2009-02-02T00:59:26Z
501,966
<p>I've used the third approach (add the directories to <code>sys.path</code>) for more than one project, and I think it's a valid approach.</p>
1
2009-02-02T01:17:31Z
[ "python" ]
How to modularize a Python application
501,945
<p>I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come...
5
2009-02-02T00:59:26Z
502,008
<p>If you have multiple environments which have various combinations of dependencies, a good solution is to use <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> to create sandboxed Python environments, each with their own set of installed packages. Each environment will function in the sa...
3
2009-02-02T01:53:36Z
[ "python" ]
How to modularize a Python application
501,945
<p>I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come...
5
2009-02-02T00:59:26Z
502,014
<p>Adding to sys.path (usually using site.addsitedir) is quite common and not particularly frowned upon. Certainly you will want your common working shared stuff to be in modules somewhere convenient.</p> <p>If you are using Python 2.6+ there's already a user-level modules folder you can use without having to add to s...
8
2009-02-02T02:00:33Z
[ "python" ]
Finding the workspace size (screen size less the taskbar) using GTK
502,282
<p>How do you create a main window that fills the entire desktop <strong>without covering (or being covered by) the task bar</strong> and <strong>without being maximized</strong>? I can find the entire screen size with and set the main window accordingly with this:</p> <pre><code>window = gtk.Window() screen = window....
5
2009-02-02T05:38:09Z
508,251
<p>You are totally at the mercy of your window manager for this, and the key issue here is:</p> <blockquote> <p><strong>without being maximized</strong></p> </blockquote> <p>So we are left with a number of hacks, because basically maximization and resizing are two separate things, in order that you might be able to...
9
2009-02-03T18:09:21Z
[ "python", "gtk", "pygtk" ]
Finding the workspace size (screen size less the taskbar) using GTK
502,282
<p>How do you create a main window that fills the entire desktop <strong>without covering (or being covered by) the task bar</strong> and <strong>without being maximized</strong>? I can find the entire screen size with and set the main window accordingly with this:</p> <pre><code>window = gtk.Window() screen = window....
5
2009-02-02T05:38:09Z
6,521,588
<p>Do you mean making the window <em>fullscreen</em>?</p> <p>Gtk has functions for making windows fullscreen and back, see <a href="http://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-fullscreen" rel="nofollow"><code>gtk_window_fullscreen()</code></a> and <a href="http://developer.gnome.org/gtk3/stable/Gt...
1
2011-06-29T13:41:20Z
[ "python", "gtk", "pygtk" ]
Running SimpleXMLRPCServer in separate thread and shutting down
502,610
<p>I have a class that I wish to test via SimpleXMLRPCServer in python. The way I have my unit test set up is that I create a new thread, and start SimpleXMLRPCServer in that. Then I run all the test, and finally shut down.</p> <p>This is my ServerThread:</p> <pre><code>class ServerThread(Thread): running = True ...
2
2009-02-02T08:59:40Z
502,956
<p>Two suggestions.</p> <p>Suggestion One is to use a separate process instead of a separate thread.</p> <ul> <li><p>Create a stand-alone XMLRPC server program.</p></li> <li><p>Start it with <code>subprocess.Popen()</code>. </p></li> <li><p>Kill it when the test is done. In standard OS's (not Windows) the kill works...
1
2009-02-02T11:54:29Z
[ "python", "multithreading", "simplexmlrpcserver" ]
Running SimpleXMLRPCServer in separate thread and shutting down
502,610
<p>I have a class that I wish to test via SimpleXMLRPCServer in python. The way I have my unit test set up is that I create a new thread, and start SimpleXMLRPCServer in that. Then I run all the test, and finally shut down.</p> <p>This is my ServerThread:</p> <pre><code>class ServerThread(Thread): running = True ...
2
2009-02-02T08:59:40Z
29,421,095
<p>I had the same problem and after hours of research i solved it by switching from using my own <strong>handle_request()</strong> loop to <strong>serve_forever()</strong> to start the server. </p> <p><strong>serve_forever()</strong> starts an internal loop like yours. This loop can be stopped by calling <strong>shutd...
1
2015-04-02T19:38:11Z
[ "python", "multithreading", "simplexmlrpcserver" ]
Converting date between DD/MM/YYYY and YYYY-MM-DD?
502,726
<p>Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database.</p> <p>This almost works, but fails because I don't provide time:</p> <pre><code>from datetime import datetime lastconnection = datetime.strptime("21/1...
12
2009-02-02T10:01:49Z
502,737
<p>you first would need to convert string into datetime tuple, and then convert that datetime tuple to string, it would go like this:</p> <pre><code>lastconnection = datetime.strptime("21/12/2008", "%d/%m/%Y").strftime('%Y-%m-%d') </code></pre>
8
2009-02-02T10:07:57Z
[ "python", "date" ]
Converting date between DD/MM/YYYY and YYYY-MM-DD?
502,726
<p>Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database.</p> <p>This almost works, but fails because I don't provide time:</p> <pre><code>from datetime import datetime lastconnection = datetime.strptime("21/1...
12
2009-02-02T10:01:49Z
502,738
<p>Your example code is wrong. This works:</p> <pre><code>import datetime datetime.datetime.strptime("21/12/2008", "%d/%m/%Y").strftime("%Y-%m-%d") </code></pre> <p>The call to strptime() parses the first argument according to the format specified in the second, so those two need to match. Then you can call strftime...
33
2009-02-02T10:09:22Z
[ "python", "date" ]
Converting date between DD/MM/YYYY and YYYY-MM-DD?
502,726
<p>Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database.</p> <p>This almost works, but fails because I don't provide time:</p> <pre><code>from datetime import datetime lastconnection = datetime.strptime("21/1...
12
2009-02-02T10:01:49Z
502,833
<p>Does anyone else else think it's a waste to convert these strings to date/time objects for what is, in the end, a simple text transformation? If you're certain the incoming dates will be valid, you can just use:</p> <pre><code>&gt;&gt;&gt; ddmmyyyy = "21/12/2008" &gt;&gt;&gt; yyyymmdd = ddmmyyyy[6:] + "-" + ddmmyyy...
1
2009-02-02T10:53:43Z
[ "python", "date" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
503,435
<p>You can put your tests in a <code>tests/</code> subdirectory of the app (rather than a <code>tests.py</code> file), and include a <code>tests/models.py</code> with the test-only models.</p> <p>Then provide a test-running script (<a href="https://github.com/carljm/django-model-utils/blob/master/runtests.py">example<...
39
2009-02-02T14:49:31Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
1,827,272
<p>This solution works only for earlier versions of <code>django</code> (before <code>1.7</code>). You can check your version easily:</p> <pre><code>import django django.VERSION &lt; (1, 7) </code></pre> <p>Original response:</p> <p>It's quite strange but form me works very simple pattern:</p> <ol> <li>add tests.py...
10
2009-12-01T16:24:59Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
2,672,444
<p>@paluh's answer requires adding unwanted code to a non-test file and in my experience, @carl's solution does not work with django.test.TestCase which is needed to use fixtures. If you want to use django.test.TestCase, you need to make sure you call syncdb before the fixtures get loaded. This requires overriding th...
17
2010-04-20T04:00:49Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
8,719,352
<p>I chose a slightly different, albeit more coupled, approach to dynamically creating models just for testing. </p> <p>I keep all my tests in a <code>tests</code> subdirectory that lives in my <code>files</code> app. The <code>models.py</code> file in the <code>tests</code> subdirectory contains my test-only models. ...
6
2012-01-03T22:10:32Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
10,218,628
<p>Here's the pattern that I'm using to do this. </p> <p>I've written this method that I use on a subclassed version of TestCase. It goes as follows:</p> <pre><code>@classmethod def create_models_from_app(cls, app_name): """ Manually create Models (used only for testing) from the specified string app name. ...
2
2012-04-18T21:55:11Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
10,657,706
<p>Combining your answers, specially @slacy's, I did this:</p> <pre><code>class TestCase(test.TestCase): initiated = False @classmethod def setUpClass(cls, *args, **kwargs): if not TestCase.initiated: TestCase.create_models_from_app('myapp.tests') TestCase.initiated = True ...
2
2012-05-18T18:13:06Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
15,460,736
<p>Quoting from <a href="http://stackoverflow.com/a/6960879/2179211">a related answer</a>:</p> <blockquote> <p>If you want models defined for testing only then you should check out <a href="https://code.djangoproject.com/ticket/7835">Django ticket #7835</a> in particular <a href="https://code.djangoproject.com/tic...
8
2013-03-17T12:34:18Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
24,907,652
<p>If you are writing a reusable django-app, <strong>create a minimal test-dedicated app for it</strong>!</p> <pre><code>$ django-admin.py startproject test_myapp_project $ django-admin.py startapp test_myapp </code></pre> <p>add both <code>myapp</code> and <code>test_myapp</code> to the <code>INSTALLED_APPS</code>, ...
0
2014-07-23T10:10:49Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
32,825,308
<p>I shared my <a href="https://github.com/erm0l0v/django-fake-model" rel="nofollow">solution</a> that I use in my projects. Maybe it helps someone.</p> <p><code>pip install django-fake-model</code></p> <p>Two simple steps to create fake model:</p> <p>1) Define model in any file (I usualy define model in test file n...
2
2015-09-28T14:17:53Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Django: How to create a model dynamically just for testing
502,916
<p>I have a Django app that requires a <code>settings</code> attribute in the form of:</p> <pre><code>RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) </code></pre> <p>Then hooks their post_save signal to ...
41
2009-02-02T11:35:52Z
34,900,947
<p>I've figured out a way for test-only models for django 1.7+.</p> <p>The basic idea is, make your <code>tests</code> an app, and add your <code>tests</code> to <code>INSTALLED_APPS</code>.</p> <p>Here's an example:</p> <pre><code>$ ls common __init__.py admin.py apps.py fixtures models.py pag...
0
2016-01-20T13:08:48Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
503,532
<p>Don't know nagios and its config file, but the structure seems pretty simple:</p> <pre><code># comment identifier { attribute= attribute=value } </code></pre> <p>which can simply be translated to</p> <pre><code>&lt;identifier&gt; &lt;attribute name="attribute-name"&gt;attribute-value&lt;/attribute&gt; &lt...
2
2009-02-02T15:12:37Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
503,862
<p>You can do something like this:</p> <pre><code>def parseConf(filename): conf = [] with open(filename, 'r') as f: for i in f.readlines(): if i[0] == '#': continue matchID = re.search(r"([\w]+) {", i) matchAttr = re.search(r"[ ]*([\w]+)=([\w\d]*)", i) ma...
2
2009-02-02T16:45:17Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
576,497
<p>Nagiosity does exactly what you want:</p> <p><a href="http://code.google.com/p/nagiosity/">http://code.google.com/p/nagiosity/</a></p>
5
2009-02-23T04:11:04Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
2,570,062
<p>Pfft, get yerself mk_livestatus. <a href="http://mathias-kettner.de/checkmk_livestatus.html" rel="nofollow">http://mathias-kettner.de/checkmk_livestatus.html</a></p>
9
2010-04-03T02:46:05Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
2,977,812
<p>If you slightly tweak Andrea's solution you can use that code to parse both the status.dat as well as the objects.cache</p> <pre><code>def parseConf(source): conf = [] for line in source.splitlines(): line=line.strip() matchID = re.match(r"(?:\s*define)?\s*(\w+)\s+{", line) matchAttr = re.match(r"\s*(\w...
2
2010-06-04T21:08:35Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
9,318,153
<p>For the last several months I've written and released a tool that that parses the Nagios status.dat and objects.cache and builds a model that allows for some really useful manipulation of Nagios data. We use it to drive an internal operations dashboard that is a simplified 'mini' Nagios. Its under continual develo...
2
2012-02-16T19:55:52Z
[ "python", "parsing", "nagios" ]
How to parse nagios status.dat file?
503,148
<p>I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise?<br /> I only ...
4
2009-02-02T13:11:09Z
35,311,918
<p>Having shamelessly stolen from the above examples, Here's a version build for Python 2.4 that returns a dict containing arrays of nagios sections.</p> <pre><code>def parseConf(source): conf = {} patID=re.compile(r"(?:\s*define)?\s*(\w+)\s+{") patAttr=re.compile(r"\s*(\w+)(?:=|\s+)(.*)") patEndID=re....
1
2016-02-10T09:57:58Z
[ "python", "parsing", "nagios" ]
Query distinct list of choices for Django form with App Engine Datastore
503,295
<p>I've been trying to figure this out for hours across a couple of days, and can not get it to work. I've been everywhere. I'll continue trying to figure it out, but was hoping for a quicker solution. I'm using App Engine datastore + Django.</p> <p>Using a query in a view and custom forms, I was able to get a list to...
1
2009-02-02T14:02:55Z
504,227
<p>I'm not familiar with App Engine Datastore, but I'm guessing you probably want to do something along these lines:</p> <pre><code>class InfoForm(djangoforms.ModelForm): def __init__(self, *args, **kwargs): super(InfoForm, self).__init__(*args, **kwargs) choices = [(r.id, r.info) for r in Info.obj...
1
2009-02-02T18:15:45Z
[ "python", "django", "google-app-engine" ]
django facebook connect missing libs?
503,462
<p>I'm trying to integrate some photo related functionality with my site and facebook. I checked out facebook connect and it seems like the way to go for this (since I don't want to make an app, just have users authenticate and then grab some content from facebook to integrate into our site)</p> <p>First of all, if yo...
0
2009-02-02T14:57:05Z
512,919
<p>the solution proposeed by van gale (removing the lines which reference the signals.py file) work well enough. I think I may end up needing to write my own signals.py eventually... I keep you updated.</p> <p>Anyway here's is the answer:</p> <p><b><s>Remove the functionality and all uses of it, provided by the signa...
0
2009-02-04T19:28:55Z
[ "python", "django", "facebook", "integration", "fbconnect" ]
django facebook connect missing libs?
503,462
<p>I'm trying to integrate some photo related functionality with my site and facebook. I checked out facebook connect and it seems like the way to go for this (since I don't want to make an app, just have users authenticate and then grab some content from facebook to integrate into our site)</p> <p>First of all, if yo...
0
2009-02-02T14:57:05Z
519,805
<p>I've just added the missing file folks. Sorry for the inconveniences. :/</p>
2
2009-02-06T10:31:00Z
[ "python", "django", "facebook", "integration", "fbconnect" ]
Why is IronPython faster than the Official Python Interpreter
504,716
<p>According to this: </p> <p><a href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance">http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance</a></p> <p>IronPython (Python for .Net) is fas...
8
2009-02-02T20:21:28Z
504,725
<p>Python code doesn't get compiled to C, Python itself is written in C and interprets Python bytecode. CIL gets compiled to machine code, which is why you see better performance when using IronPython.</p>
37
2009-02-02T20:23:27Z
[ "python", "performance", "ironpython" ]
Why is IronPython faster than the Official Python Interpreter
504,716
<p>According to this: </p> <p><a href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance">http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance</a></p> <p>IronPython (Python for .Net) is fas...
8
2009-02-02T20:21:28Z
504,740
<p>Could it be explained by this notation on the page you linked to:</p> <blockquote> <p>Due to site caching in the Dynamic Language Runtime, IronPython performs better with more PyStone passes than the default value</p> </blockquote>
3
2009-02-02T20:26:06Z
[ "python", "performance", "ironpython" ]
Why is IronPython faster than the Official Python Interpreter
504,716
<p>According to this: </p> <p><a href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance">http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance</a></p> <p>IronPython (Python for .Net) is fas...
8
2009-02-02T20:21:28Z
506,956
<p>You're right, C is a lot faster. That's why in those results CPython is twice as fast when it comes to dictionaries, which are almost pure C. On the other hand, Python code is not compiled, it's interpreted. Function calls in CPython are terribly slow. But on the other hand: </p> <pre><code>TryRaiseExcept: +4478....
8
2009-02-03T12:49:08Z
[ "python", "performance", "ironpython" ]
Why is IronPython faster than the Official Python Interpreter
504,716
<p>According to this: </p> <p><a href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance">http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance</a></p> <p>IronPython (Python for .Net) is fas...
8
2009-02-02T20:21:28Z
620,976
<p>I'm not sure exactly how you're drawing the conclusion that IronPython is faster than CPython. The link that you post seems to indicate that they're good at different things (like exceptions as has been pointed out).</p>
5
2009-03-07T00:21:05Z
[ "python", "performance", "ironpython" ]
Why is IronPython faster than the Official Python Interpreter
504,716
<p>According to this: </p> <p><a href="http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance">http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&amp;referringTitle=IronPython%20Performance</a></p> <p>IronPython (Python for .Net) is fas...
8
2009-02-02T20:21:28Z
830,892
<p>Wandering off your question "Why?", to "Oh, really?" The "good at different things" (Jason Baker) is right on. For example, cpython beats IronPython hands down start up time. </p> <pre><code>c:\Python26\python.exe Hello.py c:\IronPython\ipy.exe Hello.py </code></pre> <p>Cpython executes a basic hello world nearly ...
5
2009-05-06T17:59:51Z
[ "python", "performance", "ironpython" ]
Py2exe for Python 3.0
505,230
<p>I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.</p> <p>Any ideas?</p>
28
2009-02-02T22:28:40Z
506,005
<p>The <code>py2exe</code> and <code>2to3</code> programs serve completely different purposes, so I'm not sure what your ultimate goal is.</p> <p>If you want to build an executable from a working Python program, use the version of <code>py2exe</code> that is suitable for whichever Python you are using (version 2 or ve...
7
2009-02-03T04:24:49Z
[ "python", "python-3.x", "py2exe" ]
Py2exe for Python 3.0
505,230
<p>I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.</p> <p>Any ideas?</p>
28
2009-02-02T22:28:40Z
633,648
<h3>Update 2014-05-15</h3> <p>py2exe for Python 3.x is now released! <a href="https://pypi.python.org/pypi/py2exe">Get it on PyPI</a>.</p> <h3>Old information</h3> <p>Have a look at the py2exe SourceForge project SVN repository at:</p> <p><a href="http://py2exe.svn.sourceforge.net/">http://py2exe.svn.sourceforge.ne...
27
2009-03-11T07:33:42Z
[ "python", "python-3.x", "py2exe" ]
Py2exe for Python 3.0
505,230
<p>I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.</p> <p>Any ideas?</p>
28
2009-02-02T22:28:40Z
1,263,200
<p>Did you check out <a href="http://cx-freeze.sourceforge.net/">cx_Freeze</a>? It seems to create standalone executables from your Python scripts, including support for Python 3.0 and 3.1</p>
27
2009-08-11T22:00:16Z
[ "python", "python-3.x", "py2exe" ]
Py2exe for Python 3.0
505,230
<p>I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.</p> <p>Any ideas?</p>
28
2009-02-02T22:28:40Z
23,638,686
<h1>py2exe for Python3 is out!</h1> <p>Here is the original bug report:<br> <a href="http://sourceforge.net/projects/py2exe/">http://sourceforge.net/projects/py2exe/</a></p> <p>Here is the comment mentioning the release:<br> <a href="http://sourceforge.net/projects/py2exe/">http://sourceforge.net/projects/py2exe/</a>...
8
2014-05-13T18:15:48Z
[ "python", "python-3.x", "py2exe" ]
Py2exe for Python 3.0
505,230
<p>I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.</p> <p>Any ideas?</p>
28
2009-02-02T22:28:40Z
35,556,519
<p>If you have easy setup installed, type <code>pip install py2exe</code> in a shell to install.</p>
0
2016-02-22T14:44:21Z
[ "python", "python-3.x", "py2exe" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
505,594
<p>You want to put <code>global get</code> at the beginning of <em>every</em> function (except <code>get</code> itself).</p> <p>the <code>def get</code> is an assignment to the name <code>get</code>, so you want get to be declared global before that.</p> <p>Putting <code>global get</code> in mfun and vset makes them ...
0
2009-02-03T00:24:59Z
[ "python", "closures", "lexical-scope" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
505,596
<p>The problem is in your scoping, not in your closures. If you're up for some heavy reading, then you can try <a href="http://www.python.org/dev/peps/pep-3104/">http://www.python.org/dev/peps/pep-3104/</a>.</p> <p>If that's not the case, here's the simple explanation:</p> <p>The problem is in the statement <code>glo...
7
2009-02-03T00:26:25Z
[ "python", "closures", "lexical-scope" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
505,598
<p>Probably because you want the <em>global</em> get while it isn't a global? By the way, apply is deprecated, use fn(*args) instead.</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): def newget(ky): if key==ky: return (True, value) ret...
0
2009-02-03T00:27:20Z
[ "python", "closures", "lexical-scope" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
505,663
<pre><code>def memoize(fn): get = [lambda key: (False, None)] def vset(args): value = fn(*args) oldget = get[0] def newget(key): if args == key: return (True, value) return oldget(key) get[0] = newget return value def mfun(*args): found, value = get[0](args) if fo...
7
2009-02-03T00:57:24Z
[ "python", "closures", "lexical-scope" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
505,669
<p><code>Get</code> is not global, but local to the surrounding function, that's why the <code>global</code> declaration fails.</p> <p>If you remove the <code>global</code>, it still fails, because you can't assign to the captured variable name. To work around that, you can use an object as the variable captured by yo...
1
2009-02-03T00:58:45Z
[ "python", "closures", "lexical-scope" ]
Closures in Python
505,559
<p>I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:</p> <pre><code>def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky...
6
2009-02-03T00:13:06Z
1,380,012
<p>I think the best way would be:</p> <pre><code>class Memoized(object): def __init__(self,func): self.cache = {} self.func = func def __call__(self,*args): if args in self.cache: return cache[args] else: self.cache[args] = self.func(*args) return self.ca...
0
2009-09-04T15:39:47Z
[ "python", "closures", "lexical-scope" ]
How to chain views in Django?
505,703
<p>I'm implementing <a href="http://www.b-list.org/about/" rel="nofollow">James Bennett</a>'s excellent <a href="http://code.google.com/p/django-contact-form/" rel="nofollow">django-contact-form</a> but have hit a snag. My contact page not only contains the form, but also additional flat page information. </p> <p>Wi...
4
2009-02-03T01:13:26Z
505,712
<p>There's a context processor that may do what you want.</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/templates/api/" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/templates/api/</a></p> <p>You can probably add your various pieces of "flat page information" to the context.</p>
2
2009-02-03T01:18:19Z
[ "python", "django", "extension-methods", "django-views", "wrapping" ]
How to chain views in Django?
505,703
<p>I'm implementing <a href="http://www.b-list.org/about/" rel="nofollow">James Bennett</a>'s excellent <a href="http://code.google.com/p/django-contact-form/" rel="nofollow">django-contact-form</a> but have hit a snag. My contact page not only contains the form, but also additional flat page information. </p> <p>Wi...
4
2009-02-03T01:13:26Z
505,930
<p>Context processors are what you're thinking of. And render_to_response is irrelevant. The required piece of information is if the view uses RequestContext or not, as that is what activates context processors.</p> <p>Other than those, there is no way to "chain" views to add to context - you can wrap one view in anot...
1
2009-02-03T03:30:11Z
[ "python", "django", "extension-methods", "django-views", "wrapping" ]
How to chain views in Django?
505,703
<p>I'm implementing <a href="http://www.b-list.org/about/" rel="nofollow">James Bennett</a>'s excellent <a href="http://code.google.com/p/django-contact-form/" rel="nofollow">django-contact-form</a> but have hit a snag. My contact page not only contains the form, but also additional flat page information. </p> <p>Wi...
4
2009-02-03T01:13:26Z
510,371
<ol> <li>Write a wrapper which uses the URL to look up the appropriate flat page object.</li> <li>From your wrapper, call (and return the response from) the contact form view, passing the flat page in the <code>extra_context</code> argument (which is there for, among other things, precisely this sort of use case).</li>...
2
2009-02-04T07:14:23Z
[ "python", "django", "extension-methods", "django-views", "wrapping" ]
Extracting data from MS Word
505,925
<p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p> <p>I want to be able to pull the action items from these meeting minutes into a database so that we can...
5
2009-02-03T03:27:53Z
505,948
<p>I'd say look at the related questions on the right --> The <a href="http://stackoverflow.com/questions/125222/extracting-text-from-ms-word-files-in-python">top one</a> seems to have some good ideas for going the python route.</p>
0
2009-02-03T03:36:56Z
[ "python", "vba", "ms-word", "word-vba", "pywin32" ]
Extracting data from MS Word
505,925
<p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p> <p>I want to be able to pull the action items from these meeting minutes into a database so that we can...
5
2009-02-03T03:27:53Z
505,969
<p>Well, I've never scripted Word, but it's pretty easy to do simple stuff with win32com. Something like:</p> <pre><code>from win32com.client import Dispatch word = Dispatch('Word.Application') doc = word.Open('d:\\stuff\\myfile.doc') doc.SaveAs(FileName='d:\\stuff\\text\\myfile.txt', FileFormat=?) # not sure what t...
1
2009-02-03T03:58:49Z
[ "python", "vba", "ms-word", "word-vba", "pywin32" ]
Extracting data from MS Word
505,925
<p>I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia.</p> <p>I want to be able to pull the action items from these meeting minutes into a database so that we can...
5
2009-02-03T03:27:53Z
506,002
<p>how about saving the file as xml. then using python or something else and pull the data out of word and into the database. </p>
0
2009-02-03T04:23:52Z
[ "python", "vba", "ms-word", "word-vba", "pywin32" ]