title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Bind event to wx.Menu() instead of to the menu item in wxPython
1,191,221
<p>My problem can be easily defined with the following code:</p> <pre><code>self.Bind(wx.EVT_MENU_OPEN, self.OnAbout) </code></pre> <p>This will mean that when I click on any wx.Menu() in the MenuBar, the function 'onAbout()' is called. How do I bind this event to a specific wx.Menu() which is called wx.MenuAbout() ?...
1
2009-07-27T23:39:46Z
27,258,400
<p>This works for me:</p> <pre><code>class myFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "my frame") #give the Frame a menu bar self.frame_menubar = wx.MenuBar() fileMenu = wx.Menu() self.frame_menubar.Append(fileMenu, "File") self.rotMe...
0
2014-12-02T20:32:01Z
[ "python", "wxpython" ]
FormEncode, pylons, and mako example
1,191,265
<p>I'm working in pylons with mako, and I'd like to create forms and validations with FormEncode for several parts of my application. I can't seem to find any good examples of the whole process. My question is twofold:</p> <p>Technical</p> <ul> <li> FancyValidators and Schemas - Their relationship and syntax</li> ...
1
2009-07-27T23:56:40Z
1,197,076
<p>I don't know if you've gone through the pylons book, but I found <a href="http://pylonsbook.com/en/1.0/working-with-forms-and-validators.html" rel="nofollow">chapter 6</a> to be very thorough in regards to forms. </p> <p>As far as best practices go, I'm not exactly sure what you are looking for. A controller method...
1
2009-07-28T22:20:59Z
[ "python", "validation", "pylons", "mako", "formencode" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
1,191,537
<p>If you're on Unix,</p> <pre><code>import signal ... class Alarm(Exception): pass def alarm_handler(signum, frame): raise Alarm signal.signal(signal.SIGALRM, alarm_handler) signal.alarm(5*60) # 5 minutes try: stdoutdata, stderrdata = proc.communicate() signal.alarm(0) # reset the alarm except A...
70
2009-07-28T01:43:16Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
1,557,452
<p>I've used <a href="http://benjamin.smedbergs.us/blog/2006-12-11/killableprocesspy/" rel="nofollow">killableprocess</a> successfully on Windows, Linux and Mac. If you are using Cygwin Python, you'll need <a href="http://svn.osafoundation.org/chandler/trunk/chandler/tools/killableprocess.py" rel="nofollow">OSAF's vers...
1
2009-10-12T23:15:47Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
3,326,559
<p>Here is Alex Martelli's solution as a module with proper process killing. The other approaches do not work because they do not use proc.communicate(). So if you have a process that produces lots of output, it will fill its output buffer and then block until you read something from it.</p> <pre><code>from os import ...
39
2010-07-24T19:29:54Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
4,144,642
<p>Another option is to write to a temporary file to prevent the stdout blocking instead of needing to poll with communicate(). This worked for me where the other answers did not; for example on windows.</p> <pre><code> outFile = tempfile.SpooledTemporaryFile() errFile = tempfile.SpooledTemporaryFile() ...
9
2010-11-10T12:51:15Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
4,825,933
<p>I don't know much about the low level details; but, given that in python 2.6 the API offers the ability to wait for threads and terminate processes, what about running the process in a separate thread?</p> <pre><code>import subprocess, threading class Command(object): def __init__(self, cmd): self.cmd ...
165
2011-01-28T07:39:08Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
4,878,500
<p>I've implemented what I could gather from a few of these. This works in Windows, and since this is a community wiki, I figure I would share my code as well:</p> <pre><code>class Command(threading.Thread): def __init__(self, cmd, outFile, errFile, timeout): threading.Thread.__init__(self) self.cm...
2
2011-02-02T18:47:14Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
5,611,718
<p>I added the solution with threading from <code>jcollado</code> to my Python module <a href="http://code.activestate.com/pypm/easyprocess/" rel="nofollow">easyprocess</a>.</p> <p>Install:</p> <pre><code>pip install easyprocess </code></pre> <p>Example:</p> <pre><code>from easyprocess import Proc # shell is not s...
4
2011-04-10T12:28:02Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
7,169,548
<p>Although I haven't looked at it extensively, this <a href="http://code.activestate.com/recipes/307871-timing-out-function/" rel="nofollow">decorator</a> I found at ActiveState seems to be quite useful for this sort of thing. Along with <code>subprocess.Popen(..., close_fds=True)</code>, at least I'm ready for shell-...
1
2011-08-24T01:42:21Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
8,507,775
<p>The solution I use is to prefix the shell command with <a href="http://devel.ringlet.net/sysutils/timelimit/" rel="nofollow">timelimit</a>. If the comand takes too long, timelimit will stop it and Popen will have a returncode set by timelimit. If it is > 128, it means timelimit killed the process.</p> <p>See also <...
4
2011-12-14T16:14:40Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
10,012,262
<p>jcollado's answer can be simplified using the threading.Timer class:</p> <pre><code>import subprocess, shlex from threading import Timer def run(cmd, timeout_sec): proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) kill_proc = lambda p: p.kill() timer = Timer(timeo...
46
2012-04-04T13:36:49Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
10,552,626
<p>Once you understand full process running machinery in *unix, you will easily find simplier solution:</p> <p>Consider this simple example how to make timeoutable communicate() meth using select.select() (available alsmost everythere on *nix nowadays). This also can be written with epoll/poll/kqueue, but select.selec...
1
2012-05-11T13:46:13Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
10,768,774
<p>I've modified <strong>sussudio</strong> answer. Now function returns: (<code>returncode</code>, <code>stdout</code>, <code>stderr</code>, <code>timeout</code>) - <code>stdout</code> and <code>stderr</code> is decoded to utf-8 string</p> <pre><code>def kill_proc(proc, timeout): timeout["value"] = True proc.kill(...
13
2012-05-26T18:30:19Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
12,677,928
<p>Unfortunately, I'm bound by very strict policies on the disclosure of source code by my employer, so I can't provide actual code. But for my taste the best solution is to create a subclass overriding <code>Popen.wait()</code> to poll instead of wait indefinitely, and <code>Popen.__init__</code> to accept a timeout ...
0
2012-10-01T17:17:49Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
12,698,328
<p>In Python 3.3+:</p> <pre><code>from subprocess import STDOUT, check_output output = check_output(cmd, stderr=STDOUT, timeout=seconds) </code></pre> <p><code>output</code> is a byte string that contains command's merged stdout, stderr data. </p> <p>This code raises <code>CalledProcessError</code> on non-zero exit...
75
2012-10-02T21:06:25Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
21,845,629
<pre><code>import subprocess, optparse, os, sys, re, datetime, threading, time, glob, shutil, xml.dom.minidom, traceback class OutputManager: def __init__(self, filename, mode, console, logonly): self.con = console self.logtoconsole = True self.logtofile = False if filename: ...
-1
2014-02-18T06:09:01Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
22,886,770
<p>Was just trying to write something simpler.</p> <pre><code>#!/usr/bin/python from subprocess import Popen, PIPE import datetime import time popen = Popen(["/bin/sleep", "10"]); pid = popen.pid sttime = time.time(); waittime = 3 print "Start time %s"%(sttime) while True: popen.poll(); time.sleep(1) ...
-1
2014-04-05T21:01:52Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
24,539,984
<p>Here is my solution, I was using Thread and Event:</p> <pre><code>import subprocess from threading import Thread, Event def kill_on_timeout(done, timeout, proc): if not done.wait(timeout): proc.kill() def exec_command(command, timeout): done = Event() proc = subprocess.Popen(command, stdout=s...
4
2014-07-02T19:59:19Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
28,660,503
<p><a href="https://docs.python.org/3/library/subprocess.html#subprocess.call" rel="nofollow"><code>timeout</code> is now supported</a> by <code>call()</code> and <code>communicate()</code> in the subprocess module (as of Python3.3):</p> <pre><code>import subprocess subprocess.call("command", timeout=20, shell=True) ...
4
2015-02-22T16:51:55Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
29,763,091
<p>surprised nobody mentioned using <code>timeout</code></p> <p><code>timeout 5 ping -c 3 somehost</code></p> <p>This won't for work for every use case obviously, but if your dealing with a simple script, this is hard to beat.</p> <p>Also available as gtimeout in coreutils via <code>homebrew</code> for mac users.</p...
9
2015-04-21T04:43:41Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
32,783,644
<p><a href="https://pypi.python.org/pypi/python-subprocess2" rel="nofollow">https://pypi.python.org/pypi/python-subprocess2</a> provides extensions to the subprocess module which allow you to wait up to a certain period of time, otherwise terminate. </p> <p>So, to wait up to 10 seconds for the process to terminate, o...
0
2015-09-25T13:45:41Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
38,391,072
<p>if you are using python 2, give it a try</p> <pre><code>import subprocess32 try: output = subprocess32.check_output(command, shell=True, timeout=3) except subprocess32.TimeoutExpired as e: print e </code></pre>
1
2016-07-15T08:10:19Z
[ "python", "multithreading", "timeout", "subprocess" ]
Using module 'subprocess' with timeout
1,191,374
<p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p> <pre><code>proc = subprocess.Popen( cmd, stderr=subprocess.STDOUT, # Merge stdout and stderr stdout=subprocess.PIPE, shell=True) </code></pre> <p><code>commu...
198
2009-07-28T00:41:23Z
39,108,864
<p>This solution kills the process tree in case of shell=True, passes parameters to the process (or not), has a timeout and gets the stdout, stderr and process output of the call back (it uses psutil for the kill_proc_tree). This was based on several solutions posted in SO including jcollado's. Posting in response to ...
0
2016-08-23T19:04:00Z
[ "python", "multithreading", "timeout", "subprocess" ]
Sorting and indexing into a list in a Django template?
1,191,439
<p>How can you perform complex sorting on an object before passing it to the template? For example, here is my view:</p> <pre><code>@login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_b...
5
2009-07-28T01:07:41Z
1,191,500
<p><strong>"I'd like to do this from within a template:"</strong></p> <p>Don't. Do it in the view function where it belongs.</p> <p>Since the question is incomplete, it's impossible to guess at the data model and provide the exact solution. </p> <pre><code>results= physician.patients.order_by('bed__room__unit', 'be...
4
2009-07-28T01:29:05Z
[ "python", "django", "django-templates" ]
Sorting and indexing into a list in a Django template?
1,191,439
<p>How can you perform complex sorting on an object before passing it to the template? For example, here is my view:</p> <pre><code>@login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_b...
5
2009-07-28T01:07:41Z
1,191,596
<p>You should be able to construct the ordered query set in your view and pass it to your template:</p> <pre><code>def myview(request): patients = Physician.patients.order_by('bed__room__unit', 'bed__room__order', 'bed__order')...
1
2009-07-28T02:05:28Z
[ "python", "django", "django-templates" ]
Sorting and indexing into a list in a Django template?
1,191,439
<p>How can you perform complex sorting on an object before passing it to the template? For example, here is my view:</p> <pre><code>@login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_b...
5
2009-07-28T01:07:41Z
1,216,920
<p>As others have indicated, both of your problems are best solved outside the template -- either in the models, or in the view. One strategy would be to add helper methods to the relevant classes.</p> <p>Getting a sorted list of a physician's patients:</p> <pre><code>class Physician(Model): ... def sorted_pati...
11
2009-08-01T16:17:19Z
[ "python", "django", "django-templates" ]
Sorting and indexing into a list in a Django template?
1,191,439
<p>How can you perform complex sorting on an object before passing it to the template? For example, here is my view:</p> <pre><code>@login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_b...
5
2009-07-28T01:07:41Z
2,558,284
<p>This is one way of doing it, although very ugly :</p> <p><code>{% for note in note_sets|slice:"forloop.counter0"|first %}</code></p>
0
2010-04-01T05:19:31Z
[ "python", "django", "django-templates" ]
imagefield won't validate
1,191,487
<p>I moved a site to a mediatemple server using python 2.3, now ImageField won't work in the admin. Upon saving, validation gives the "not valid image" error. </p> <p>checked:</p> <ul> <li>media_root and media_url are correct</li> <li>PIL contains jpg support</li> <li>upload folders set to 775</li> <li>image is not c...
0
2009-07-28T01:24:20Z
1,663,358
<p>If you read documentation here: <a href="http://docs.djangoproject.com/en/dev/intro/install/" rel="nofollow">http://docs.djangoproject.com/en/dev/intro/install/</a> You will find the answer. </p> <blockquote> <p>It works with any Python version from 2.4 to 2.6!</p> </blockquote> <p>And :</p> <blockquote> <p...
1
2009-11-02T20:02:44Z
[ "python", "django", "django-models" ]
Hello World from cython wiki not working
1,191,600
<p>I'm trying to follow this tutorial from Cython: <a href="http://docs.cython.org/docs/tutorial.html#the-basics-of-cython" rel="nofollow">http://docs.cython.org/docs/tutorial.html#the-basics-of-cython</a> and I'm having a problem. </p> <p>The files are very simple. I have a helloworld.pyx:</p> <pre><code>print "Hell...
2
2009-07-28T02:06:04Z
1,191,622
<p>Oh damn... forget it... </p> <p>I forgot to install the dev packages. </p> <p>Duh. Stupid. Sorry guys.</p>
1
2009-07-28T02:17:09Z
[ "c++", "python", "cython" ]
Hello World from cython wiki not working
1,191,600
<p>I'm trying to follow this tutorial from Cython: <a href="http://docs.cython.org/docs/tutorial.html#the-basics-of-cython" rel="nofollow">http://docs.cython.org/docs/tutorial.html#the-basics-of-cython</a> and I'm having a problem. </p> <p>The files are very simple. I have a helloworld.pyx:</p> <pre><code>print "Hell...
2
2009-07-28T02:06:04Z
1,192,043
<p>Looks like you're missing some package like <code>python_dev</code> or the like -- Debian and derivatives (including Ubuntu) have long preferred to isolate everything that could possibly be of "developer"'s use from the parts of a package that are for "everybody"... a philosophical stance I could debate against (and...
4
2009-07-28T05:17:10Z
[ "c++", "python", "cython" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,191,708
<p>There's OpenBUGS and R helper packages. Check out Gelman's site for his book, which has most of the relevant links:</p> <ul> <li><a href="http://www.stat.columbia.edu/~gelman/software/">http://www.stat.columbia.edu/~gelman/software/</a></li> <li><a href="http://www.stat.columbia.edu/~gelman/bugsR/software.pdf">Exa...
13
2009-07-28T02:55:08Z
[ "python", "statistics" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,192,044
<p>Here are four books on hierarchical modeling and bayesian analysis written with R code throughout the books.</p> <p>Hierarchical Modeling and Analysis for Spatial Data (Monographs on Statistics and Applied Probability) (Hardcover) <a href="http://rads.stackoverflow.com/amzn/click/158488410X">http://www.amazon.com/g...
8
2009-07-28T05:17:52Z
[ "python", "statistics" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,196,932
<p>There are a few hierarchical models in <a href="http://mcmcpack.wustl.edu" rel="nofollow">MCMCpack</a> for R, which to my knowledge is the fastest sampler for many common model types. (I wrote the [hierarchical item response][2] model in it.)</p> <p>[RJAGS][3] does what its name sounds like. Code up a jags-flavored...
3
2009-07-28T21:45:12Z
[ "python", "statistics" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,197,766
<p>The lme4 package, which estimates hierarchical models using frequentist methods, has a function called mcmcsamp that allows you to sample from the posterior distribution of the model using MCMC. This currently works only for linear models, quite unfortunately.</p>
0
2009-07-29T02:19:51Z
[ "python", "statistics" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,830,888
<p>in python, try PyMC. There is an example of multilevel modeling with it here: <a href="http://groups.google.com/group/pymc/browse%5Fthread/thread/c6ce37a80edf7f85/1bfd9138c8db891d" rel="nofollow">http://groups.google.com/group/pymc/browse%5Fthread/thread/c6ce37a80edf7f85/1bfd9138c8db891d</a></p>
2
2009-12-02T05:45:59Z
[ "python", "statistics" ]
Hierarchical Bayes for R or Python
1,191,689
<p>Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is <code>bayesm</code>, which is really a companion to a book (<em>Bayesian Statistics and Marketing</em>, by Rossi, et al.) Am I missing something? Is there a software package for R or Pyth...
11
2009-07-28T02:43:03Z
1,832,314
<p>I apply hierarchical Bayes models in R in combination with JAGS (Linux) or sometimes WinBUGS (Windows, or Wine). Check out the book of Andrew Gelman, as referred to above.</p>
2
2009-12-02T11:22:36Z
[ "python", "statistics" ]
Is it possible to install SSL on Google app engine for iPhone application?
1,191,936
<p>I am using python language for google app engine based iphone application .I want to install/access ssl on python. I am unable to find a way to install/enable it in python file. please guide me how can I make my application to connect to ssl As I want to Apple enable push notification services on my application Its ...
1
2009-07-28T04:27:59Z
1,193,063
<p>See the App Engine Python documentation on setting up <a href="http://code.google.com/appengine/docs/python/config/appconfig.html#Secure%5FURLs" rel="nofollow">secure URLs</a>. Note that this will only work when accessed via your appspot.com domain - it's not possible to have SSL on a custom domain through App Engin...
5
2009-07-28T09:49:23Z
[ "python", "google-app-engine", "ssl" ]
Is it possible to install SSL on Google app engine for iPhone application?
1,191,936
<p>I am using python language for google app engine based iphone application .I want to install/access ssl on python. I am unable to find a way to install/enable it in python file. please guide me how can I make my application to connect to ssl As I want to Apple enable push notification services on my application Its ...
1
2009-07-28T04:27:59Z
2,602,904
<p>Nick Johnson has already provided a link and mentioned that this functionality is not currently available on your domain (only on apps running on Google's hotspot domain).</p> <p>Obviously, most developers need their apps to run on their own domains, so this is a <a href="http://code.google.com/p/googleappengine/is...
0
2010-04-08T19:44:33Z
[ "python", "google-app-engine", "ssl" ]
SQLAlchemy: Operating on results
1,192,269
<p>I'm trying to do something relatively simple, spit out the column names and respective column values, and possibly filter out some columns so they aren't shown.</p> <p>This is what I attempted ( after the initial connection of course ):</p> <pre><code>metadata = MetaData(engine) users_table = Table('fusion_users'...
5
2009-07-28T06:45:37Z
1,192,439
<p>You can use <code>results</code> instantly as an iterator.</p> <pre><code>results = s.execute() for row in results: print row </code></pre> <p>Selecting specific columns is done the following way:</p> <pre><code>from sqlalchemy.sql import select s = select([users_table.c.user_name, users_table.c.user_countr...
8
2009-07-28T07:38:52Z
[ "python", "sql", "sqlalchemy" ]
SQLAlchemy: Operating on results
1,192,269
<p>I'm trying to do something relatively simple, spit out the column names and respective column values, and possibly filter out some columns so they aren't shown.</p> <p>This is what I attempted ( after the initial connection of course ):</p> <pre><code>metadata = MetaData(engine) users_table = Table('fusion_users'...
5
2009-07-28T06:45:37Z
1,194,760
<p>A SQLAlchemy <a href="http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.engine.base.RowProxy">RowProxy</a> object has dict-like methods -- <code>.items()</code> to get all name/value pairs, <code>.keys()</code> to get just the names (e.g. to display them as a header line, then use <c...
8
2009-07-28T15:05:24Z
[ "python", "sql", "sqlalchemy" ]
What's a good way to replace international characters with their base Latin counterparts using Python?
1,192,367
<p>Say I have the string <code>"blöt träbåt"</code> which has a few <code>a</code> and <code>o</code> with umlaut and ring above. I want it to become <code>"blot trabat"</code> as simply as possibly. I've done some digging and found the following method:</p> <pre><code>import unicodedata unicode_string = unicodedat...
5
2009-07-28T07:21:11Z
1,192,471
<p>It would be better if you created an explicit table, and then used the unicode.translate method. The advantage would be that transliteration is more precise, e.g. transliterating "ö" to "oe" and "ß" to "ss", as should be done in German.</p> <p>There are several transliteration packages on PyPI: <a href="http://py...
7
2009-07-28T07:45:57Z
[ "python", "string", "internationalization" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,192,495
<p>Use the <code>list</code> and <code>listchars</code> options, something like this:</p> <pre><code>:set list :set listchars=tab:&gt;- </code></pre>
5
2009-07-28T07:50:15Z
[ "python", "vim" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,192,516
<p>I use something like this:</p> <pre><code>set list listchars=tab:»·,trail:·,precedes:…,extends:…,nbsp:‗ </code></pre> <p>Requires Vim7 and I'm not sure how well this is going to show up in a browser, because it uses some funky Unicode characters. It's good to use some oddball characters so that you can d...
16
2009-07-28T07:55:37Z
[ "python", "vim" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,192,811
<p>If you do the following:</p> <pre><code>:set list </code></pre> <p>then all TAB characters will appear as <code>^I</code> and all trailing spaces will appear as <code>$</code>.</p> <p>Using <code>listchars</code>, you can control what characters to use for any whitespace. So,</p> <pre><code>:set listchars=tab:....
3
2009-07-28T08:55:03Z
[ "python", "vim" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,195,462
<p>Also, when cutting and pasting text around, it's useful to disable the display of tabs and spaces. You can do that with</p> <pre><code>:set list! </code></pre> <p>And you enable it again with repeating the command.</p>
2
2009-07-28T17:09:45Z
[ "python", "vim" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,195,534
<p>Many others have mentioned the 'listchars' and 'list' options, but just to add another interesting alternative:</p> <pre><code>if &amp;expandtab == 0 execute 'syn match MixedIndentationError display "^\([\t]*\)\@&lt;=\( \{'.&amp;ts.'}\)\+"' else execute 'syn match MixedIndentationError display "^\(\( \{' . ...
7
2009-07-28T17:26:06Z
[ "python", "vim" ]
Making tabulation look different than just whitespace
1,192,480
<p>How to make tabulation look different than whitespace in vim (highlighted for example).</p> <p>That would be useful for code in Python.</p>
9
2009-07-28T07:47:21Z
1,214,504
<p><em>glenn jackman</em> asked how to enter the characters (I'm assuming he means characters like "»").</p> <p><em>Brian Carper</em> suggests a method using the character's Unicode index number. Since many of these distinctive-looking characters are digraphs [ :help digraphs ], you can also use the CNTL-k shortcut, ...
2
2009-07-31T19:46:03Z
[ "python", "vim" ]
python stdout flush and tee
1,192,870
<p>The following code ends with broken pipe when piped into tee, but behave correctly when not piped :</p> <pre><code>#!/usr/bin/python import sys def testfun(): while 1: try : s = sys.stdin.readline() except(KeyboardInterrupt) : print('Ctrl-C pressed') sys.stdou...
2
2009-07-28T09:07:35Z
1,192,880
<p>When you hit Ctrl-C, the shell will terminate <em>both</em> processes (<code>python</code> and <code>tee</code>) and tear down the pipe connecting them. </p> <p>So when you handle the Ctrl-C in your <code>python</code> process and flush, it'll find that <code>tee</code> has been terminated and the pipe is no more. ...
2
2009-07-28T09:10:07Z
[ "python", "tee" ]
python stdout flush and tee
1,192,870
<p>The following code ends with broken pipe when piped into tee, but behave correctly when not piped :</p> <pre><code>#!/usr/bin/python import sys def testfun(): while 1: try : s = sys.stdin.readline() except(KeyboardInterrupt) : print('Ctrl-C pressed') sys.stdou...
2
2009-07-28T09:07:35Z
1,192,955
<p>This is not a python problem but a shell problem, as pointed by Brian, hitting Ctrl-C will terminate both process. Workaround is to use named pipes :</p> <pre><code>mknod mypipe p cat mypipe | tee somefile.log &amp; ./bug.py &gt; mypipe </code></pre>
4
2009-07-28T09:25:35Z
[ "python", "tee" ]
python stdout flush and tee
1,192,870
<p>The following code ends with broken pipe when piped into tee, but behave correctly when not piped :</p> <pre><code>#!/usr/bin/python import sys def testfun(): while 1: try : s = sys.stdin.readline() except(KeyboardInterrupt) : print('Ctrl-C pressed') sys.stdou...
2
2009-07-28T09:07:35Z
7,251,469
<p>Nope, hitting Ctrl-C does NOT terminate both processes. It terminates the tee process only, the end of the tee process close the pipe between your script and tee, and hence your script dies with the broken pipe message.</p> <p>To fix that, tee has an option to pass the Ctrl-C to its previous process in the pipe: -i...
8
2011-08-31T00:52:17Z
[ "python", "tee" ]
How to find the longest word with python?
1,192,881
<p>How can I use python to find the longest word from a set of words? I can find the first word like this: </p> <pre><code>'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)] 'a' rfind is another subset 'a aa aaa aa'[:'a aa aaa aa'.rfind(' ',1,10)] 'a aa aaa' </code></pre>
1
2009-07-28T09:10:08Z
1,192,898
<p>If I understand your question correctly:</p> <pre><code>&gt;&gt;&gt; s = "a aa aaa aa" &gt;&gt;&gt; max(s.split(), key=len) 'aaa' </code></pre> <p><code>split()</code> splits the string into words (seperated by whitespace); <code>max()</code> finds the largest element using the builtin <code>len()</code> function,...
31
2009-07-28T09:15:30Z
[ "python", "word", "max" ]
How to find the longest word with python?
1,192,881
<p>How can I use python to find the longest word from a set of words? I can find the first word like this: </p> <pre><code>'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)] 'a' rfind is another subset 'a aa aaa aa'[:'a aa aaa aa'.rfind(' ',1,10)] 'a aa aaa' </code></pre>
1
2009-07-28T09:10:08Z
1,193,087
<p>Here is one from the category "How difficult can you make it", also violating the requirement that there should be no own class involved:</p> <pre><code>class C(object): pass o = C() o.i = 0 ss = 'a aa aaa aa'.split() ([setattr(o,'i',x) for x in range(len(ss)) if len(ss[x]) &gt; len(ss[o.i])], ss[o.i])[1] </code></...
2
2009-07-28T09:53:49Z
[ "python", "word", "max" ]
Can someone explain this Python re.sub() unexpected output?
1,192,918
<p>I am using Python 2.6 and am getting [what I think is] unexpected output from re.sub()</p> <pre><code>&gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat') 'th- c-t s-t -n th- m-t' &gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat', re.IGNORECASE) 'th- c-t sat on the mat' </code></pre> <p>If this...
3
2009-07-28T09:19:45Z
1,192,965
<p>Yes, the fourth parameter is count, not flags. You're telling it to apply the pattern twice (re.IGNORECASE = 2).</p>
7
2009-07-28T09:28:36Z
[ "python", "regex" ]
Can someone explain this Python re.sub() unexpected output?
1,192,918
<p>I am using Python 2.6 and am getting [what I think is] unexpected output from re.sub()</p> <pre><code>&gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat') 'th- c-t s-t -n th- m-t' &gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat', re.IGNORECASE) 'th- c-t sat on the mat' </code></pre> <p>If this...
3
2009-07-28T09:19:45Z
1,192,991
<p>To pass flags you can use re.compile</p> <pre><code>expression = re.compile('[aeiou]', re.IGNORECASE) expression.sub('-', 'the cat sat on the mat') </code></pre>
4
2009-07-28T09:34:14Z
[ "python", "regex" ]
Can someone explain this Python re.sub() unexpected output?
1,192,918
<p>I am using Python 2.6 and am getting [what I think is] unexpected output from re.sub()</p> <pre><code>&gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat') 'th- c-t s-t -n th- m-t' &gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat', re.IGNORECASE) 'th- c-t sat on the mat' </code></pre> <p>If this...
3
2009-07-28T09:19:45Z
27,368,978
<p>In case you've upgraded since asking this question. If you are using Python 2.7+, you don't need to use <code>re.compile</code>. You can call <code>sub</code> and specify <code>flags</code> with a named argument.</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.sub('[aeiou]', '-', 'the cat sat on the mat', fla...
0
2014-12-08T23:33:05Z
[ "python", "regex" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
1,192,992
<p>Thats probably the best way to be honest: you can use <code>glob</code> to go a certain number of layers down, but if you need it to be recursive you have to <code>walk</code>.</p>
2
2009-07-28T09:34:41Z
[ "python" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
1,193,070
<p>What you are doing is perfectly right and I think should be done that way, BUT just for the sake of alternative, here is an attempt</p> <pre><code>import os def getFiles(myFolder): old = os.getcwd() os.chdir(myFolder) fileSet = set() for root, dirs, files in os.walk(""): for f in files: ...
1
2009-07-28T09:51:02Z
[ "python" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
1,193,105
<p>I think os.walk is the right choice here.<br /> maybe <code>root.replace(myFolder, "")</code> should change to <code>root.replace(myFolder, "", 1)</code> to avoid potential sth. you know.<br /> If you already get the files and (sub)folders, <a href="http://docs.python.org/library/os.path.html#os.path.commonprefix" r...
3
2009-07-28T09:57:41Z
[ "python" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
1,193,171
<pre><code>myFolder = "myfolder" fileSet = set() for root, dirs, files in os.walk(myFolder): for fileName in files: fileSet.add( os.path.join( root[len(myFolder):], fileName )) </code></pre>
8
2009-07-28T10:10:39Z
[ "python" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
1,208,379
<p>You can also use <a href="http://docs.python.org/library/os.html#os.listdir" rel="nofollow">os.listdir()</a> if you are just searching for an alternative to your solution.</p> <p>But basically the logic will stay the same: iterate over the files - if directory, iterate through the subdirectory. </p>
1
2009-07-30T18:19:54Z
[ "python" ]
Python - Get relative path of all files and subfolders in a directory
1,192,978
<p>I am searching for a good way to get relative paths of files and (sub)folders within a specific folder. </p> <p>For my current approach I am using <code>os.walk()</code>. It is working but it does not seem "pythonic" to me:</p> <pre><code>myFolder = "myfolder" fileSet = set() # yes, I need a set() for root, dirs,...
22
2009-07-28T09:31:08Z
13,617,120
<p>Use <a href="http://docs.python.org/2/library/os.path.html#os.path.relpath"><code>os.path.relpath()</code></a>. This is exactly its intended use.</p> <pre><code>import os rootDir = "myfolder" fileSet = set() for dir_, _, files in os.walk(rootDir): for fileName in files: relDir = os.path.relpath(dir_, ...
37
2012-11-29T01:00:36Z
[ "python" ]
User in Form-Class
1,193,084
<p>I have a form like this:</p> <pre><code>class MyForm(forms.Form): [...] </code></pre> <p>which is rendered in my view:</p> <pre><code>if request.method == 'GET': form = MyForm(request.GET) </code></pre> <p>Now, i want to add a form field which contains a set of values in a select-field, and the queryset must...
0
2009-07-28T09:53:46Z
1,193,205
<p>Replace your last line of code with this:</p> <pre><code>self.fields['myfield'].choices = [('%s' % d.id, '%s' % d.name) for d in MyModel.objects.filter(owners = user)] </code></pre>
2
2009-07-28T10:20:54Z
[ "python", "django" ]
User in Form-Class
1,193,084
<p>I have a form like this:</p> <pre><code>class MyForm(forms.Form): [...] </code></pre> <p>which is rendered in my view:</p> <pre><code>if request.method == 'GET': form = MyForm(request.GET) </code></pre> <p>Now, i want to add a form field which contains a set of values in a select-field, and the queryset must...
0
2009-07-28T09:53:46Z
1,193,943
<p>I think here's what you're after:</p> <pre><code>class MyForm(forms.Form): def __init__(self, user, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['myfield'] = forms.ModelChoiceField(MyModel.objects.filter(owners=user)) </code></pre> <p>That's assuming that the <...
0
2009-07-28T13:03:06Z
[ "python", "django" ]
What is the multiplatform alternative to subprocess.getstatusoutput (older commands.setstatusoutput() from Python?
1,193,583
<p>The code below is outdated in Python 3.0 by being replaced by <code>subprocess.getstatusoutput()</code>. </p> <pre><code>import commands (ret, out) = commands.getstatusoutput('some command') print ret print out </code></pre> <p>The real question is what's the multiplatform alternative to this command from Python b...
7
2009-07-28T11:47:02Z
1,193,824
<p>I wouldn't really consider this <em>multiplatform</em>, but you can use <code>subprocess.Popen</code>:</p> <pre><code>import subprocess pipe = subprocess.Popen('dir', stdout=subprocess.PIPE, shell=True, universal_newlines=True) output = pipe.stdout.readlines() sts = pipe.wait() print sts print output </code></pre> ...
7
2009-07-28T12:37:16Z
[ "python", "redirect", "process" ]
What is the multiplatform alternative to subprocess.getstatusoutput (older commands.setstatusoutput() from Python?
1,193,583
<p>The code below is outdated in Python 3.0 by being replaced by <code>subprocess.getstatusoutput()</code>. </p> <pre><code>import commands (ret, out) = commands.getstatusoutput('some command') print ret print out </code></pre> <p>The real question is what's the multiplatform alternative to this command from Python b...
7
2009-07-28T11:47:02Z
1,197,469
<p>getstatusoutput docs say it runs the command like so:</p> <p>{ cmd } 2>&amp;1</p> <p>Which obviously doesn't work with cmd.exe (the 2>&amp;1 works fine if you need it though).</p> <p>You can use Popen as above, but also include the parameter 'stderr=subprocess.STDOUT' to get the same behaviour as getstatusoutput....
1
2009-07-29T00:24:43Z
[ "python", "redirect", "process" ]
What is the multiplatform alternative to subprocess.getstatusoutput (older commands.setstatusoutput() from Python?
1,193,583
<p>The code below is outdated in Python 3.0 by being replaced by <code>subprocess.getstatusoutput()</code>. </p> <pre><code>import commands (ret, out) = commands.getstatusoutput('some command') print ret print out </code></pre> <p>The real question is what's the multiplatform alternative to this command from Python b...
7
2009-07-28T11:47:02Z
1,198,935
<p>This would be the multiplatform implementation for getstatusoutput(): </p> <pre><code>def getstatusoutput(cmd): """Return (status, output) of executing cmd in a shell.""" """This new implementation should work on all platforms.""" import subprocess pipe = subprocess.Popen(cmd, stdout=subprocess.PIP...
6
2009-07-29T09:05:20Z
[ "python", "redirect", "process" ]
Is there a standard pythonic way to treat physical units / quantities in python?
1,193,890
<p>Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions as others should be able to easily read my code.</p>
17
2009-07-28T12:51:20Z
1,193,902
<p>The best solution is the <a href="http://home.scarlet.be/be052320/Unum.html">Unum</a> package. a de-facto standard, imho.</p>
9
2009-07-28T12:53:28Z
[ "python", "physics", "units-of-measurement" ]
Is there a standard pythonic way to treat physical units / quantities in python?
1,193,890
<p>Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions as others should be able to easily read my code.</p>
17
2009-07-28T12:51:20Z
1,203,778
<p>I've been looking at the <a href="http://code.enthought.com/projects/files/ETS31%5FAPI/enthought.units.html" rel="nofollow">Enthought Units module</a></p>
2
2009-07-30T00:14:02Z
[ "python", "physics", "units-of-measurement" ]
Is there a standard pythonic way to treat physical units / quantities in python?
1,193,890
<p>Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions as others should be able to easily read my code.</p>
17
2009-07-28T12:51:20Z
1,204,146
<p><a href="https://launchpad.net/python-quantities">quantities</a> seems to be gaining a lot of traction lately.</p>
9
2009-07-30T02:27:36Z
[ "python", "physics", "units-of-measurement" ]
Is there a standard pythonic way to treat physical units / quantities in python?
1,193,890
<p>Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions as others should be able to easily read my code.</p>
17
2009-07-28T12:51:20Z
27,903,335
<p>There is also <a href="http://pint.readthedocs.org/en/0.6/" rel="nofollow" title="pint">pint</a> which in his documentation has a list of other projects in their <a href="http://pint.readthedocs.org/en/0.6/faq.html" rel="nofollow">faq's</a>.</p>
0
2015-01-12T13:40:49Z
[ "python", "physics", "units-of-measurement" ]
How to wait for a child that respawns itself with os.execv() on win32?
1,194,078
<p>I have some code that uses <a href="http://pypi.python.org/pypi/pip" rel="nofollow">pip</a> to bootstrap a Python envionment for out build process: this is a lovely way of ensuring we get proper isolation of the build requirements from the rest of the host system, and helping us get more consistent build results ove...
0
2009-07-28T13:24:02Z
1,429,702
<p>I can't think of any smooth way to handle this. This may sound dirty, but perhaps you could work with dropping flag files onto the filesystem while your script is running, and wait for those files to be cleaned up?</p>
0
2009-09-15T21:25:21Z
[ "python", "windows", "pip", "execv" ]
Python memory footprint vs. heap size
1,194,416
<p>I'm having some memory issues while using a python script to issue a large <strong>solr</strong> query. I'm using the <strong>solrpy</strong> library to interface with the solr server. The query returns approximately 80,000 records. Immediately after issuing the query the python memory footprint as viewed through...
9
2009-07-28T14:19:10Z
1,194,548
<p>Python allocates Unicode objects from the C heap. So when you allocate many of them (along with other malloc blocks), then release most of them except for the very last one, C malloc will not return any memory to the operating system, as the C heap will only shrink on the end (not in the middle). Releasing the last ...
5
2009-07-28T14:36:47Z
[ "python", "memory-leaks", "solr" ]
Python memory footprint vs. heap size
1,194,416
<p>I'm having some memory issues while using a python script to issue a large <strong>solr</strong> query. I'm using the <strong>solrpy</strong> library to interface with the solr server. The query returns approximately 80,000 records. Immediately after issuing the query the python memory footprint as viewed through...
9
2009-07-28T14:19:10Z
1,194,575
<p>What version of python are you using?<br /> I am asking because <a href="http://evanjones.ca/python-memory.html" rel="nofollow">older version of CPython did not release the memory</a> and this was fixed in Python 2.5.</p>
1
2009-07-28T14:41:07Z
[ "python", "memory-leaks", "solr" ]
Python memory footprint vs. heap size
1,194,416
<p>I'm having some memory issues while using a python script to issue a large <strong>solr</strong> query. I'm using the <strong>solrpy</strong> library to interface with the solr server. The query returns approximately 80,000 records. Immediately after issuing the query the python memory footprint as viewed through...
9
2009-07-28T14:19:10Z
1,195,441
<p>CPython implementation only exceptionally free's allocated memory. This is a widely known bug, but it isn't receiving much attention by CPython developers. The recommended workaround is to "fork and die" the process that consumes lots RAM.</p>
2
2009-07-28T17:06:03Z
[ "python", "memory-leaks", "solr" ]
Python memory footprint vs. heap size
1,194,416
<p>I'm having some memory issues while using a python script to issue a large <strong>solr</strong> query. I'm using the <strong>solrpy</strong> library to interface with the solr server. The query returns approximately 80,000 records. Immediately after issuing the query the python memory footprint as viewed through...
9
2009-07-28T14:19:10Z
1,196,291
<p>I've implemented hruske's advice of "fork and die". I'm using os.fork() to execute the memory intensive section of code in a child process, then I let the child process exit. The parent process executes an os.waitpid() on the child so that only one thread is executing at a given time.</p> <p>If anyone sees any pi...
0
2009-07-28T19:35:36Z
[ "python", "memory-leaks", "solr" ]
What's wrong with this bit of python code using lambda?
1,194,543
<p>Some python code that keeps throwing up an invalid syntax error:</p> <pre><code>stat.sort(lambda x1, y1: 1 if x1.created_at &lt; y1.created_at else -1) </code></pre>
1
2009-07-28T14:35:24Z
1,194,590
<p>Try the <a href="http://www.diveintopython.org/power%5Fof%5Fintrospection/and%5For.html" rel="nofollow">and-or trick</a>:</p> <pre><code>lambda x1, y1: x1.created_at &lt; y1.created_at and 1 or -1 </code></pre>
1
2009-07-28T14:42:57Z
[ "python" ]
What's wrong with this bit of python code using lambda?
1,194,543
<p>Some python code that keeps throwing up an invalid syntax error:</p> <pre><code>stat.sort(lambda x1, y1: 1 if x1.created_at &lt; y1.created_at else -1) </code></pre>
1
2009-07-28T14:35:24Z
1,194,766
<p>This is a better solution:</p> <pre><code>stat.sort(key=lambda x: x.created_at, reverse=True) </code></pre> <p>Or, to avoid the lambda altogether:</p> <pre><code>from operator import attrgetter stat.sort(key=attrgetter('created_at'), reverse=True) </code></pre>
8
2009-07-28T15:06:01Z
[ "python" ]
Forward declaration - no admin page in django?
1,194,723
<p>This is probably a db design issue, but I couldn't figure out any better. Among several others, I have these models:</p> <pre><code>class User(models.Model): name = models.CharField( max_length=40 ) # some fields omitted bands = models.ManyToManyField( Band ) </code></pre> <p>and</p> <pre><code>class Band(m...
3
2009-07-28T15:00:56Z
1,194,800
<p>See: <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey">http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey</a>, which says:</p> <blockquote> <p>If you need to create a relationship on a model that has not yet been defined, you can use the name of the model, rather t...
12
2009-07-28T15:11:35Z
[ "python", "django", "database-design", "circular-dependency", "forward-declaration" ]
How to update manytomany field in Django?
1,194,737
<p>Here's an example:</p> <p>If I have these classes</p> <pre><code>class Author(models.Model): name = models.CharField(max_length=45) class Book(models.Model): name = models.CharField(max_length=45) authors = models.ManyToManyField(Author) </code></pre> <p>In the database I have one Author with the nam...
10
2009-07-28T15:02:37Z
1,195,759
<p>With the auto-generated through table, you can do a two-step insert and delete, which is nice for readability.</p> <pre><code>george = Author.objects.get(name='George') georfe = Author.objects.get(name='Georfe') book.authors.add(george) book.authors.remove(georfe) assert george in book.authors </code></pre> <p>If...
8
2009-07-28T18:10:14Z
[ "python", "django" ]
How to update manytomany field in Django?
1,194,737
<p>Here's an example:</p> <p>If I have these classes</p> <pre><code>class Author(models.Model): name = models.CharField(max_length=45) class Book(models.Model): name = models.CharField(max_length=45) authors = models.ManyToManyField(Author) </code></pre> <p>In the database I have one Author with the nam...
10
2009-07-28T15:02:37Z
1,195,768
<p><strong>Note:</strong> This code will <em>delete</em> the bad 'georfe' author, as well as updating the books to point to the correct author. If you don't want to do that, then use <code>.remove()</code> as @jcdyer's answer mentions.</p> <p>Can you do something like this?</p> <pre><code>george_author = Author.objec...
10
2009-07-28T18:11:54Z
[ "python", "django" ]
How do I change the directory of InMemoryUploadedFile?
1,194,963
<p>It seems that if I do not create a ModelForm from a model, and create a new object and save it, it will not respect the field's upload directory.</p> <p>How do I change the directory of a InMemoryUploadedFile so I can manually implement the upload dir? Because the InMemoryUploadedFile obj is just the filename, and ...
0
2009-07-28T15:38:46Z
1,197,046
<p>How did you define the attribute of image in your ProductImages model? Did you have upload_to argument in your FileField? </p> <pre><code>class ProductImages(models.Model): image = models.FileField(upload_to="images/") </code></pre>
1
2009-07-28T22:13:02Z
[ "python", "django" ]
Installing Django with mod_wsgi
1,195,260
<p>I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is <a href="http://www.wampserver.com" rel="nofollow" title="WAMPServer's WebSite">WAMP2.0</a>. I've been a ...
3
2009-07-28T16:33:46Z
1,195,457
<p>Have you seen <a href="http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango">http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango</a> ?</p> <p>You need more than one line to assure that Apache will play nicely.</p> <pre><code>Alias /media/ /usr/local/django/mysite/media/ &lt;Directory /usr/local/dja...
6
2009-07-28T17:09:08Z
[ "python", "django", "apache", "mod-wsgi" ]
Installing Django with mod_wsgi
1,195,260
<p>I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is <a href="http://www.wampserver.com" rel="nofollow" title="WAMPServer's WebSite">WAMP2.0</a>. I've been a ...
3
2009-07-28T16:33:46Z
1,195,520
<p>mod_wsgi's documentation is very good. Try using their quick configuration guide and go from there: <a href="http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide" rel="nofollow">http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide</a></p>
1
2009-07-28T17:21:28Z
[ "python", "django", "apache", "mod-wsgi" ]
Installing Django with mod_wsgi
1,195,260
<p>I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is <a href="http://www.wampserver.com" rel="nofollow" title="WAMPServer's WebSite">WAMP2.0</a>. I've been a ...
3
2009-07-28T16:33:46Z
1,197,411
<p>You have:</p> <pre><code>WSGIScriptAlias / /C:/Users/Marcos/Documents/mysite/apache/django.wsgi </code></pre> <p>That is wrong as RHS is not a valid Windows pathname. Use:</p> <pre><code>WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi </code></pre> <p>That is, no leading slash before the Wi...
7
2009-07-29T00:04:32Z
[ "python", "django", "apache", "mod-wsgi" ]
django @login_required decorator error
1,195,432
<p>I'm running django 1.1rc. All of my code works correctly using django's built in development server; however, when I move it into production using Apache's mod_python, I get the following error on all of my views:</p> <pre><code> Caught an exception while rendering: Reverse for '&lt;django.contrib.auth.decorators._...
3
2009-07-28T17:03:33Z
1,195,486
<p>Having googled on this a bit, it sounds like you may need to delete any .pyc files on the server and let it recompile them the first time they're accessed.</p>
0
2009-07-28T17:15:34Z
[ "python", "django" ]
django @login_required decorator error
1,195,432
<p>I'm running django 1.1rc. All of my code works correctly using django's built in development server; however, when I move it into production using Apache's mod_python, I get the following error on all of my views:</p> <pre><code> Caught an exception while rendering: Reverse for '&lt;django.contrib.auth.decorators._...
3
2009-07-28T17:03:33Z
1,196,998
<p>I had a problem with my apache configuration:</p> <p>I changed this:</p> <p>SetEnv DJANGO_SETTINGS_MODULE settings</p> <p>to this:</p> <p>SetEnv DJANGO_SETTINGS_MODULE booster.settings</p> <p>To solve the defualt auth login problem, I added the setting settings.LOGIN_URL.</p>
1
2009-07-28T22:00:19Z
[ "python", "django" ]
django @login_required decorator error
1,195,432
<p>I'm running django 1.1rc. All of my code works correctly using django's built in development server; however, when I move it into production using Apache's mod_python, I get the following error on all of my views:</p> <pre><code> Caught an exception while rendering: Reverse for '&lt;django.contrib.auth.decorators._...
3
2009-07-28T17:03:33Z
1,647,161
<p>This is a pretty common 'phantom error' in Django. In other words, there's a bug in your code, but the debug page is spitting back a misleading exception. Usually when I see this error, it's because I've screwed something up in a url tag in one of my templates - most commonly a misspelled url or a url for a view tha...
0
2009-10-29T23:24:05Z
[ "python", "django" ]
Python scoping problem
1,195,577
<p>I have a trivial example:</p> <pre><code> def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() </code></pre> I expect the output to be: <pre> first local_var: None second local_v...
3
2009-07-28T17:38:30Z
1,195,635
<p>Before Python 3.0, functions couldn't write to non-global variables in outer scopes. Python3 has introduced the <code>nonlocal</code> keyword that lets this work. You'd add <code>nonlocal local_var</code> at the top of <code>func()</code>'s definition to get the output you expected. See <a href="http://www.python.or...
1
2009-07-28T17:47:24Z
[ "python", "scoping" ]
Python scoping problem
1,195,577
<p>I have a trivial example:</p> <pre><code> def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() </code></pre> I expect the output to be: <pre> first local_var: None second local_v...
3
2009-07-28T17:38:30Z
1,195,680
<p>The standard way to solve this problem pre-3.0 would be</p> <pre><code>def func1(): local_var = [None] def func(args): print args, print "local_var:", local_var[0] local_var[0] = "local" func("first") func("second") func1() </code></pre>
1
2009-07-28T17:56:25Z
[ "python", "scoping" ]
Python scoping problem
1,195,577
<p>I have a trivial example:</p> <pre><code> def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() </code></pre> I expect the output to be: <pre> first local_var: None second local_v...
3
2009-07-28T17:38:30Z
1,195,692
<p>Python's scoping rules are discussed and explained in this related question:</p> <p><a href="http://stackoverflow.com/questions/1188944/reason-for-unintuitive-unboundlocalerror-behaviour">http://stackoverflow.com/questions/1188944/reason-for-unintuitive-unboundlocalerror-behaviour</a></p>
1
2009-07-28T17:58:16Z
[ "python", "scoping" ]
Python scoping problem
1,195,577
<p>I have a trivial example:</p> <pre><code> def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() </code></pre> I expect the output to be: <pre> first local_var: None second local_v...
3
2009-07-28T17:38:30Z
1,195,696
<p>The assignment to <code>local_var</code> in <code>func</code> makes it local <strong>to <code>func</code></strong> -- so the <code>print</code> statement references that "very very local" variable before it's ever assigned to, as the exception says. As jtb says, in Python 3 you can solve this with <code>nonlocal</co...
9
2009-07-28T17:58:36Z
[ "python", "scoping" ]
Load non-uniform data from a txt file into a msql database
1,195,753
<p>I have text files with a lot of uniform rows that I'd like to load into a mysql database, but the files are not completely uniform. There are several rows at the beginning for some miscellaneous information, and there are timestamps about every 6 lines.</p> <p>"LOAD DATA INFILE" doesn't seem like the answer here be...
0
2009-07-28T18:08:59Z
1,195,784
<p>LOAD DATA INFILE has an IGNORE LINES option which you can use to skip the header. According to <a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html" rel="nofollow">the docs</a>, it also has a " LINES STARTING BY 'prefix_string'" option which you could use since all of your data lines seem to start with two...
2
2009-07-28T18:15:11Z
[ "python", "mysql", "file-io", "sqlalchemy", "load-data-infile" ]
Load non-uniform data from a txt file into a msql database
1,195,753
<p>I have text files with a lot of uniform rows that I'd like to load into a mysql database, but the files are not completely uniform. There are several rows at the beginning for some miscellaneous information, and there are timestamps about every 6 lines.</p> <p>"LOAD DATA INFILE" doesn't seem like the answer here be...
0
2009-07-28T18:08:59Z
1,195,978
<p>Another way to do this is to just have Python transform the files for you. You could have it filter the input file to an output file based on the criteria that you specify pretty easily. This code assumes you have some function is_data(line) that checks line for the criteria you specify and returns true if it is d...
2
2009-07-28T18:42:22Z
[ "python", "mysql", "file-io", "sqlalchemy", "load-data-infile" ]
Web Services with Google App Engine
1,195,893
<p>I see that Google App Engine can host web applications that will return html, etc. But what about web services that communicate over http and accept / return xml?</p> <p>Does anyone know how this is being done in Goggle App Engine with Python or for that matter in Java (JAS-WX is not supported)? Any links o sample...
6
2009-07-28T18:31:01Z
1,195,949
<p>Google App Engine allows you to write web services that return any type of HTTP response content. This includes xml, json, text, etc.</p> <p>For instance, take a look at the <a href="http://code.google.com/appengine/docs/java/gettingstarted/">guestbook sample project</a> offered by Google which shows the HTTP resp...
9
2009-07-28T18:38:23Z
[ "java", "python", "web-services", "google-app-engine" ]
Web Services with Google App Engine
1,195,893
<p>I see that Google App Engine can host web applications that will return html, etc. But what about web services that communicate over http and accept / return xml?</p> <p>Does anyone know how this is being done in Goggle App Engine with Python or for that matter in Java (JAS-WX is not supported)? Any links o sample...
6
2009-07-28T18:31:01Z
1,196,729
<p>Most python apps just write a handler that outputs the shaped xml directly... this example serves any GET requests submitted to the root url ("/"): </p> <pre><code>import wsgiref.handlers from google.appengine.ext import webapp class MainHandler(webapp.RequestHandler): def get(self): self.response.out.writ...
3
2009-07-28T21:05:22Z
[ "java", "python", "web-services", "google-app-engine" ]
Web Services with Google App Engine
1,195,893
<p>I see that Google App Engine can host web applications that will return html, etc. But what about web services that communicate over http and accept / return xml?</p> <p>Does anyone know how this is being done in Goggle App Engine with Python or for that matter in Java (JAS-WX is not supported)? Any links o sample...
6
2009-07-28T18:31:01Z
1,197,991
<p>It's definitely possible (and not too hard) to use GAE to host "web services that communicate over http and accept / return xml".</p> <p>To parse XML requests (presumably coming in as the body of HTTP POST or PUT requests), you have several options, e.g. pyexpat or minidom on top of it, see <a href="http://groups.g...
2
2009-07-29T04:05:34Z
[ "java", "python", "web-services", "google-app-engine" ]
How to manage many to one relationship in Django
1,195,911
<p>I am trying to make a many to one relationship and want to be able to control it (add -remove etc) via the admin panel. So this is my model.py:</p> <pre><code>from django.db import models class Office(models.Model): name = models.CharField(max_length=30) class Province(models.Model): numberPlate = models...
5
2009-07-28T18:34:21Z
1,196,107
<p>Have you looked at the docs for doing Inlines?</p> <p>In your admin.py</p> <pre><code>class Office(admin.TabularInline): model = Office class ProvinceAdmin(admin.ModelAdmin): inlines = [ Office, ] </code></pre>
1
2009-07-28T19:01:55Z
[ "python", "django", "django-models", "django-admin" ]
How to manage many to one relationship in Django
1,195,911
<p>I am trying to make a many to one relationship and want to be able to control it (add -remove etc) via the admin panel. So this is my model.py:</p> <pre><code>from django.db import models class Office(models.Model): name = models.CharField(max_length=30) class Province(models.Model): numberPlate = models...
5
2009-07-28T18:34:21Z
1,196,142
<p>It seams that you have your models setup <em>backwards</em>. If you want province to have many offices, then province should be a foreign key in the Office model.</p> <pre><code>from django.db import models class Province(models.Model): numberPlate = models.IntegerField(primary_key=True) name = models.Char...
6
2009-07-28T19:08:47Z
[ "python", "django", "django-models", "django-admin" ]
Sources of PyS60's standard functions (particularly appuifw.query)
1,196,050
<p>I need to give user ability to enter a time in form hh:mm:ss (with appropriate validation of course). And standard function <code>appuifw.query(u'Label', 'time')</code> works almost fine except that it allows to enter only hours and minutes (hh:mm). So I want to look though its source and write my own that enhances ...
0
2009-07-28T18:52:23Z
1,203,088
<p>Are the <a href="https://garage.maemo.org/frs/?group%5Fid=854" rel="nofollow">*_src.zip files</a> on garage.maemo.org any useful? (I don't currently have the tools to verify what's in there.)</p>
1
2009-07-29T21:14:29Z
[ "python", "mobile", "pys60" ]