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 |
|---|---|---|---|---|---|---|---|---|---|
How do I coherently organize modules for a PyGTK desktop application? | 216,093 | <p>I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:</p>
<ul>
<li>application.py - holds the primary application class (most functional routines)</li>
<li>gui.py - holds a loosely coupled GTK gui imp... | 7 | 2008-10-19T06:07:28Z | 219,737 | <p>So having not heard back regarding my edit to the original question, I have done some more research and the conclusion I seem to be coming to is that <em>yes</em>, I should break the interface out into several views, each with its own controller. Python-gtkmvc provides the ability to this by providing a <code>glade... | 0 | 2008-10-20T20:15:32Z | [
"python",
"gtk",
"module",
"pygtk",
"organization"
] |
How do I coherently organize modules for a PyGTK desktop application? | 216,093 | <p>I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:</p>
<ul>
<li>application.py - holds the primary application class (most functional routines)</li>
<li>gui.py - holds a loosely coupled GTK gui imp... | 7 | 2008-10-19T06:07:28Z | 252,361 | <p>Sorry to answer so late. <a href="http://async.com.br/projects/kiwi" rel="nofollow">Kiwi</a> seems to me a far better solution than gtkmvc. It is my first dependency for any pygtk project.</p>
| 2 | 2008-10-31T01:31:40Z | [
"python",
"gtk",
"module",
"pygtk",
"organization"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 216,123 | <p>Take the first element, reverse the rest of the list recursively, and append the first element at the end of the list.</p>
| 1 | 2008-10-19T07:02:44Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 216,132 | <p>The trick is to join <em>after</em> recursing:</p>
<pre>
def backwards(l):
if not l:
return
x, y = l[0], l[1:]
return backwards(y) + [x]
</pre>
| 2 | 2008-10-19T07:14:33Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 216,136 | <p>Append the first element of the list to a reversed sublist:</p>
<pre><code>mylist = [1, 2, 3, 4, 5]
backwards = lambda l: (backwards (l[1:]) + l[:1] if l else [])
print backwards (mylist)
</code></pre>
| 9 | 2008-10-19T07:20:02Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 216,168 | <p>A bit more explicit:</p>
<pre><code>def rev(l):
if len(l) == 0: return []
return [l[-1]] + rev(l[:-1])
</code></pre>
<p><hr></p>
<p>This turns into:</p>
<pre><code>def rev(l):
if not l: return []
return [l[-1]] + rev(l[:-1])
</code></pre>
<p>Which turns into:</p>
<pre><code>def rev(l):
retu... | 5 | 2008-10-19T08:18:43Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 216,184 | <p>I know it's not a helpful answer (though this question has been already answered), but in any real code, please don't do that. Python cannot optimize tail-calls, has slow function calls and has a fixed recursion depth, so there are at least 3 reasons why to do it iteratively instead.</p>
| 6 | 2008-10-19T08:50:19Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 217,204 | <p>This one reverses in place. (Of course an iterative version would be better, but it has to be recursive, hasn't it?)</p>
<pre><code>def reverse(l, first=0, last=-1):
if first >= len(l)/2: return
l[first], l[last] = l[last], l[first]
reverse(l, first+1, last-1)
mylist = [1,2,3,4,5]
print mylist
reverse(... | 1 | 2008-10-20T00:11:43Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 2,105,565 | <pre><code>def reverse(q):
if len(q) != 0:
temp = q.pop(0)
reverse(q)
q.append(temp)
return q
</code></pre>
| 1 | 2010-01-20T22:36:52Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 35,097,940 | <pre><code>def revList(alist):
if len(alist) == 1:
return alist #base case
else:
return revList(alist[1:]) + [alist[0]]
print revList([1,2,3,4])
#prints [4,3,2,1]
</code></pre>
| 0 | 2016-01-30T04:21:54Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 35,679,380 | <pre><code>def reverseList(listName,newList = None):
if newList == None:
newList = []
if len(listName)>0:
newList.append((listName.pop()))
return reverseList(listName, newList)
else:
return newList
</code></pre>
<p>print reverseList([1,2,3,4])
[4,3,2,1]</p>
| 0 | 2016-02-28T06:09:27Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 39,977,940 | <p>Using Mutable default argument and recursion :</p>
<pre><code>def hello(x,d=[]):
d.append(x[-1])
if len(x)<=1:
s="".join(d)
print(s)
else:
return hello(x[:-1])
hello("word")
</code></pre>
<h1>additional info</h1>
<pre><code>x[-1] # last item in the array
x[-2:] # last... | 1 | 2016-10-11T13:05:51Z | [
"python",
"list",
"recursion"
] |
How do I reverse a list using recursion in Python? | 216,119 | <p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
| 0 | 2008-10-19T06:56:01Z | 39,978,152 | <p>Why not:</p>
<pre><code>a = [1,2,3,4,5]
a = [a[i] for i in xrange(len(a)-1, -1, -1)] # now a is reversed!
</code></pre>
| 1 | 2016-10-11T13:16:19Z | [
"python",
"list",
"recursion"
] |
Smart Sudoku Golf | 216,141 | <p>The point of this question is to create the shortest <b>not abusively slow</b> Sudoku solver. This is defined as: <b>don't recurse when there are spots on the board which can only possibly be one digit</b>.</p>
<p>Here is the shortest I have so far in python:</p>
<pre><code>r=range(81)
s=range(1,10)
def R(A):
... | 2 | 2008-10-19T07:38:32Z | 216,603 | <p>I've just trimmed the python a bit here:</p>
<pre><code>r=range(81);s=range(1,10)
def R(A):
z={}
for i in r:
if A[i]!=0:continue
h={}
for j in r:h[A[j]if j/9==i/9 or j%9==i%9 or j/27==i/27 and j%9/3==i%9/3 else 0]=1
z[9-len(h)]=h,i
for l,(h,i)in sorted(z.items(),cmp,lambd... | 2 | 2008-10-19T16:19:42Z | [
"python",
"perl",
"code-golf",
"sudoku"
] |
Smart Sudoku Golf | 216,141 | <p>The point of this question is to create the shortest <b>not abusively slow</b> Sudoku solver. This is defined as: <b>don't recurse when there are spots on the board which can only possibly be one digit</b>.</p>
<p>Here is the shortest I have so far in python:</p>
<pre><code>r=range(81)
s=range(1,10)
def R(A):
... | 2 | 2008-10-19T07:38:32Z | 217,114 | <p>I haven't really made much of a change - the algorithm is identical, but here are a few further micro-optimisations you can make to your python code.</p>
<ul>
<li><p>No need for !=0, 0 is false in a boolean context.</p></li>
<li><p>a if c else b is more expensive than using [a,b][c] if you don't need short-circuiti... | 3 | 2008-10-19T22:54:37Z | [
"python",
"perl",
"code-golf",
"sudoku"
] |
Smart Sudoku Golf | 216,141 | <p>The point of this question is to create the shortest <b>not abusively slow</b> Sudoku solver. This is defined as: <b>don't recurse when there are spots on the board which can only possibly be one digit</b>.</p>
<p>Here is the shortest I have so far in python:</p>
<pre><code>r=range(81)
s=range(1,10)
def R(A):
... | 2 | 2008-10-19T07:38:32Z | 217,569 | <pre><code>r=range(81)
def R(A):
if(0in A)-1:yield A;return
def H(i):h=set(A[j]for j in r if j/9==i/9or j%9==i%9or j/27==i/27and j%9/3==i%9/3);return len(h),h,i
l,h,i=max(H(i)for i in r if not A[i])
for j in r[1:10]:
if(j in h)-1:
A[i]=j
for S in R(A):yield S
A[i]=0
</code></pre>
<p>269 characters, and i... | 3 | 2008-10-20T05:12:33Z | [
"python",
"perl",
"code-golf",
"sudoku"
] |
How close are development webservers to production webservers? | 216,489 | <p>Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?</p>
<p>I haven't quite decided which framework to go with, much less what production server to use, so... | 5 | 2008-10-19T14:45:47Z | 216,495 | <p>Generally, they are same in terms of the settings which are required to run the applications which include the environment setting. <br>
However, the clients genereally have dev systems which are less powerful in terms of the processing power and other h/w resources. I have seen using them virtual servers in dev evi... | 2 | 2008-10-19T14:50:57Z | [
"python",
"webserver",
"web-frameworks"
] |
How close are development webservers to production webservers? | 216,489 | <p>Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?</p>
<p>I haven't quite decided which framework to go with, much less what production server to use, so... | 5 | 2008-10-19T14:45:47Z | 216,505 | <p>Ideally, the logical configuration of the development, test, and production server should be the same. They should have the same version of OS, web server, and all other software assets used to run the application. However, depending on how strong your environment things will crop - hand copied images/scripts etc on... | 1 | 2008-10-19T15:06:47Z | [
"python",
"webserver",
"web-frameworks"
] |
How close are development webservers to production webservers? | 216,489 | <p>Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?</p>
<p>I haven't quite decided which framework to go with, much less what production server to use, so... | 5 | 2008-10-19T14:45:47Z | 216,628 | <p>The lower environments should try to match the production environment as closely as possible given the resources available. This applies to all development efforts regardless of whether they are python-based or even web-based. In practical terms, most organizations are not willing to spend that type of money. In thi... | 5 | 2008-10-19T16:36:03Z | [
"python",
"webserver",
"web-frameworks"
] |
How close are development webservers to production webservers? | 216,489 | <p>Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?</p>
<p>I haven't quite decided which framework to go with, much less what production server to use, so... | 5 | 2008-10-19T14:45:47Z | 216,653 | <p>I develop with django. The production server we have is remote, so it's a pain to be using it for development. Thus, at first, I created a vm and tried to match as closely as I could the environment of the prod server. At some point that vm got hosed (due to an unrelated incident). I took stock of the situation at t... | 2 | 2008-10-19T16:50:49Z | [
"python",
"webserver",
"web-frameworks"
] |
How close are development webservers to production webservers? | 216,489 | <p>Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?</p>
<p>I haven't quite decided which framework to go with, much less what production server to use, so... | 5 | 2008-10-19T14:45:47Z | 217,467 | <p>Your staging environment should mimic your production environment. Development is more like a playground, and the control on the development environment should not be quite so strict. However, the development environment should periodically be refreshed from the production environment (e.g,. prod data copied to the ... | 0 | 2008-10-20T03:38:02Z | [
"python",
"webserver",
"web-frameworks"
] |
Group by date in a particular format in SQLAlchemy | 216,657 | <p>I have a table called logs which has a datetime field.
I want to select the date and count of rows based on a particular date format. </p>
<p>How do I do this using SQLAlchemy?</p>
| 1 | 2008-10-19T16:52:44Z | 216,730 | <p>I don't know SQLAlchemy, so I could be off-target. However, I think that all you need is:</p>
<pre><code>SELECT date_formatter(datetime_field, "format-specification") AS dt_field, COUNT(*)
FROM logs
GROUP BY date_formatter(datetime_field, "format-specification")
ORDER BY 1;
</code></pre>
<p>OK, maybe ... | 0 | 2008-10-19T17:50:23Z | [
"python",
"sql",
"sqlalchemy"
] |
Group by date in a particular format in SQLAlchemy | 216,657 | <p>I have a table called logs which has a datetime field.
I want to select the date and count of rows based on a particular date format. </p>
<p>How do I do this using SQLAlchemy?</p>
| 1 | 2008-10-19T16:52:44Z | 216,757 | <p>Does counting yield the same result when you just group by the unformatted datetime column? If so, you could just run the query and use Python date's strftime() method afterwards. i.e.</p>
<pre><code>query = select([logs.c.datetime, func.count(logs.c.datetime)]).group_by(logs.c.datetime)
results = session.execute(q... | 1 | 2008-10-19T18:11:32Z | [
"python",
"sql",
"sqlalchemy"
] |
Group by date in a particular format in SQLAlchemy | 216,657 | <p>I have a table called logs which has a datetime field.
I want to select the date and count of rows based on a particular date format. </p>
<p>How do I do this using SQLAlchemy?</p>
| 1 | 2008-10-19T16:52:44Z | 218,974 | <p>I don't know of a generic SQLAlchemy answer. Most databases support some form of date formatting, typically via functions. SQLAlchemy supports calling functions via sqlalchemy.sql.func. So for example, using SQLAlchemy over a Postgres back end, and a table my_table(foo varchar(30), when timestamp) I might do so... | 4 | 2008-10-20T16:05:14Z | [
"python",
"sql",
"sqlalchemy"
] |
In Python, what does it mean if an object is subscriptable or not? | 216,972 | <p>Which types of objects fall into the domain of "subscriptable"?</p>
| 109 | 2008-10-19T21:08:23Z | 216,980 | <p>It basically means that the object implements the <code>__getitem__()</code> method. In other words, it describes objects that are "containers", meaning they contain other objects. This includes lists, tuples, and dictionaries.</p>
| 102 | 2008-10-19T21:11:05Z | [
"python",
"terminology"
] |
In Python, what does it mean if an object is subscriptable or not? | 216,972 | <p>Which types of objects fall into the domain of "subscriptable"?</p>
| 109 | 2008-10-19T21:08:23Z | 217,049 | <p>A scriptable object is an object that records the operations done to it and it can store them as a "script" which can be replayed.</p>
<p>For example, see: <a href="https://svn.enthought.com/enthought/browser/AppTools/trunk/docs/source/appscripting/Introduction.rst">Application Scripting Framework</a></p>
<p>Now, ... | 5 | 2008-10-19T22:05:30Z | [
"python",
"terminology"
] |
In Python, what does it mean if an object is subscriptable or not? | 216,972 | <p>Which types of objects fall into the domain of "subscriptable"?</p>
| 109 | 2008-10-19T21:08:23Z | 217,081 | <p>Off the top of my head, the following are the only built-ins that are subscriptable:</p>
<pre><code>string: "foobar"[3] == "b"
tuple: (1,2,3,4)[3] == 4
list: [1,2,3,4][3] == 4
dict: {"a":1, "b":2, "c":3}["c"] == 3
</code></pre>
<p>But mipadi's answer is correct; any class that implements __getitem__ is su... | 20 | 2008-10-19T22:39:47Z | [
"python",
"terminology"
] |
Python/editline on OS X: £ sign seems to be bound to ed-prev-word | 217,020 | <p>On Mac OS X I canât enter a pound sterling sign (£) into the Python interactive shell.</p>
<pre><code>* Mac OS X 10.5.5
* Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
* European keyboard (£ is shift-3)
</code></pre>
<p>When I type shift-3 in the Python interactive shell, I seem to invoke the previous word ... | 0 | 2008-10-19T21:33:45Z | 217,036 | <p>This may be an editline issue; libedit may not accept UTF-8 characters:</p>
<ul>
<li><a href="http://tracker.firebirdsql.org/browse/CORE-362#action_11593" rel="nofollow">http://tracker.firebirdsql.org/browse/CORE-362#action_11593</a></li>
<li><a href="http://marc.info/?t=119056021900002&r=1&w=2" rel="nofoll... | 1 | 2008-10-19T21:54:07Z | [
"python",
"osx",
"unix",
"terminal",
"editline"
] |
How can I determine the display idle time from Python in Windows, Linux, and MacOS? | 217,157 | <p>I would like to know how long it's been since the user last hit a key or moved the mouse - not just in my application, but on the whole "computer" (i.e. display), in order to guess whether they're still at the computer and able to observe notifications that pop up on the screen.</p>
<p>I'd like to do this purely fr... | 15 | 2008-10-19T23:25:08Z | 217,304 | <p>I got an answer regarding mouse-clicks suggesting to use <a href="http://www.cs.unc.edu/Research/assist/developer.shtml" rel="nofollow">pyHook</a>:</p>
<p><a href="http://stackoverflow.com/questions/165495/detecting-mouse-clicks-in-windows-using-python">http://stackoverflow.com/questions/165495/detecting-mouse-clic... | 2 | 2008-10-20T01:27:38Z | [
"python",
"winapi",
"gtk",
"pygtk",
"pywin32"
] |
How can I determine the display idle time from Python in Windows, Linux, and MacOS? | 217,157 | <p>I would like to know how long it's been since the user last hit a key or moved the mouse - not just in my application, but on the whole "computer" (i.e. display), in order to guess whether they're still at the computer and able to observe notifications that pop up on the screen.</p>
<p>I'd like to do this purely fr... | 15 | 2008-10-19T23:25:08Z | 1,145,688 | <p><a href="http://www.gajim.org/" rel="nofollow">Gajim</a> does it this way on Windows, OS X and GNU/Linux (and other *nixes):</p>
<ol>
<li><a href="https://trac.gajim.org/browser/src/common/sleepy.py?rev=604c5de0dfe72dfa76b3014c410a50daae381cbe" rel="nofollow">Python wrapper module</a> (also includes Windows idle ti... | 10 | 2009-07-17T21:07:04Z | [
"python",
"winapi",
"gtk",
"pygtk",
"pywin32"
] |
How can I determine the display idle time from Python in Windows, Linux, and MacOS? | 217,157 | <p>I would like to know how long it's been since the user last hit a key or moved the mouse - not just in my application, but on the whole "computer" (i.e. display), in order to guess whether they're still at the computer and able to observe notifications that pop up on the screen.</p>
<p>I'd like to do this purely fr... | 15 | 2008-10-19T23:25:08Z | 16,777,652 | <p>If you use PyGTK and X11 on Linux, you can do something like this, which is based on what Pidgin does:</p>
<pre><code>import ctypes
import ctypes.util
import platform
class XScreenSaverInfo(ctypes.Structure):
_fields_ = [('window', ctypes.c_long),
('state', ctypes.c_int),
('kind... | 4 | 2013-05-27T17:06:43Z | [
"python",
"winapi",
"gtk",
"pygtk",
"pywin32"
] |
Troubleshooting py2exe packaging problem | 217,666 | <p>I've written a setup.py script for py2exe, generated an executable for my python GUI application and I have a whole bunch of files in the dist directory, including the app, w9xopen.exe and MSVCR71.dll. When I try to run the application, I get an error message that just says "see the logfile for details". The only pr... | 5 | 2008-10-20T06:46:22Z | 218,263 | <p>You may need to fix log handling first, <a href="http://www.py2exe.org/index.cgi/StderrLog" rel="nofollow">this</a> URL may help.</p>
<p>Later you may look for answer <a href="http://www.py2exe.org/index.cgi/GeneralTipsAndTricks" rel="nofollow">here</a>.</p>
<p>My answer is very general because you didn't give any... | 1 | 2008-10-20T12:33:37Z | [
"python",
"user-interface",
"py2exe"
] |
Troubleshooting py2exe packaging problem | 217,666 | <p>I've written a setup.py script for py2exe, generated an executable for my python GUI application and I have a whole bunch of files in the dist directory, including the app, w9xopen.exe and MSVCR71.dll. When I try to run the application, I get an error message that just says "see the logfile for details". The only pr... | 5 | 2008-10-20T06:46:22Z | 218,432 | <p>See <a href="http://www.wxpython.org/docs/api/wx.App-class.html" rel="nofollow">http://www.wxpython.org/docs/api/wx.App-class.html</a> for wxPyton's <code>App</code> class initializer. If you want to run the app from a console and have stderr print to there, then supply <code>False</code> for the <code>redirect</co... | 1 | 2008-10-20T13:31:21Z | [
"python",
"user-interface",
"py2exe"
] |
String Simple Substitution | 217,881 | <p>What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?</p>
<p>As an example, I need to convert this:</p>
<pre><code>string = "*abc+de?"
</code></pre>
<p>to this:</p>
<pre><code>string = ".*abc.+de.?"
</code></pre>
<p>Of course I coul... | 0 | 2008-10-20T09:27:08Z | 217,896 | <p>I'd use <a href="http://www.python.org/doc/2.5.2/lib/string-methods.html#l2h-255" rel="nofollow"><code>replace</code></a>:</p>
<pre><code>def wildcard_to_regex(str):
return str.replace("*", ".*").replace("?", .?").replace("#", "\d")
</code></pre>
<p>This probably isn't the most efficient way but it should be e... | 0 | 2008-10-20T09:35:04Z | [
"python",
"string"
] |
String Simple Substitution | 217,881 | <p>What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?</p>
<p>As an example, I need to convert this:</p>
<pre><code>string = "*abc+de?"
</code></pre>
<p>to this:</p>
<pre><code>string = ".*abc.+de.?"
</code></pre>
<p>Of course I coul... | 0 | 2008-10-20T09:27:08Z | 217,916 | <p>Here is a <a href="http://www.unix.com.ua/orelly/perl/cookbook/ch06_10.htm" rel="nofollow">Perl example</a> of doing this. It is simply using a table to replace each wildcard construct with the corresponding regular expression. I've done this myself previously, but in C. It shouldn't be too hard to port to Python.</... | 0 | 2008-10-20T09:44:38Z | [
"python",
"string"
] |
String Simple Substitution | 217,881 | <p>What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?</p>
<p>As an example, I need to convert this:</p>
<pre><code>string = "*abc+de?"
</code></pre>
<p>to this:</p>
<pre><code>string = ".*abc.+de.?"
</code></pre>
<p>Of course I coul... | 0 | 2008-10-20T09:27:08Z | 217,933 | <p>You'll probably only be doing this substitution occasionally, such as each time a user enters a new search string, so I wouldn't worry about how efficient the solution is.</p>
<p>You need to generate a list of the replacements you need to convert from the "user format" to a regex. For ease of maintenance I would s... | 1 | 2008-10-20T09:51:47Z | [
"python",
"string"
] |
String Simple Substitution | 217,881 | <p>What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?</p>
<p>As an example, I need to convert this:</p>
<pre><code>string = "*abc+de?"
</code></pre>
<p>to this:</p>
<pre><code>string = ".*abc.+de.?"
</code></pre>
<p>Of course I coul... | 0 | 2008-10-20T09:27:08Z | 217,978 | <p>.replacing() each of the wildcards is the quick way, but what if the wildcarded string contains other regex special characters? eg. someone searching for 'my.thing*' probably doesn't mean that '.' to match any character. And in the worst case things like match-group-creating parentheses are likely to break your fina... | 2 | 2008-10-20T10:13:13Z | [
"python",
"string"
] |
String Simple Substitution | 217,881 | <p>What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?</p>
<p>As an example, I need to convert this:</p>
<pre><code>string = "*abc+de?"
</code></pre>
<p>to this:</p>
<pre><code>string = ".*abc.+de.?"
</code></pre>
<p>Of course I coul... | 0 | 2008-10-20T09:27:08Z | 218,102 | <p>Those don't look like regexps you're trying to translate, they look more like unix shell globs. Python has a <a href="http://www.python.org/doc/2.5.2/lib/module-fnmatch.html" rel="nofollow">module</a> for doing this already. It doesn't know about the "+" syntax you used, but neither does my shell, and I think the ... | 5 | 2008-10-20T11:29:13Z | [
"python",
"string"
] |
how to generate unit test code for methods | 217,900 | <p>i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script.
but i do not how to i write. can any one give me example of small code for unit testing in python.
i am thankful </p>
| 3 | 2008-10-20T09:36:51Z | 217,925 | <p>Read the <a href="http://www.python.org/doc/2.5.2/lib/module-unittest.html" rel="nofollow">unit testing framework section</a> of the <a href="http://www.python.org/doc/2.5.2/lib/lib.html" rel="nofollow">Python Library Reference</a>.</p>
<p>A <a href="http://www.python.org/doc/2.5.2/lib/minimal-example.html" rel="no... | 7 | 2008-10-20T09:48:11Z | [
"python",
"unit-testing"
] |
how to generate unit test code for methods | 217,900 | <p>i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script.
but i do not how to i write. can any one give me example of small code for unit testing in python.
i am thankful </p>
| 3 | 2008-10-20T09:36:51Z | 217,930 | <p>Here's an <a href="http://www.python.org/doc/2.5.2/lib/minimal-example.html" rel="nofollow">example</a> and you might want to read a little more on <a href="http://www.python.org/doc/2.5.2/lib/module-unittest.html" rel="nofollow">pythons unit testing</a>.</p>
| 1 | 2008-10-20T09:49:29Z | [
"python",
"unit-testing"
] |
how to generate unit test code for methods | 217,900 | <p>i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script.
but i do not how to i write. can any one give me example of small code for unit testing in python.
i am thankful </p>
| 3 | 2008-10-20T09:36:51Z | 218,489 | <p>It's probably best to start off with the given <code>unittest</code> example. Some standard best practices: </p>
<ul>
<li>put all your tests in a <code>tests</code> folder at the root of your project.</li>
<li>write one test module for each python module you're testing.</li>
<li>test modules should start with the w... | 4 | 2008-10-20T13:46:52Z | [
"python",
"unit-testing"
] |
Getting method parameter names in python | 218,616 | <p>Given the python function:</p>
<pre><code>def aMethod(arg1, arg2):
pass
</code></pre>
<p>How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2")</p>
<p>The usage scenario for this is that I have a decorator, and... | 131 | 2008-10-20T14:22:02Z | 218,625 | <p>In CPython, the number of arguments is</p>
<pre><code>aMethod.func_code.co_argcount
</code></pre>
<p>and their names are in the beginning of</p>
<pre><code>aMethod.func_code.co_varnames
</code></pre>
<p>These are implementation details of CPython, so this probably does not work in other implementations of Python... | 73 | 2008-10-20T14:24:48Z | [
"python",
"decorator",
"introspection",
"python-datamodel"
] |
Getting method parameter names in python | 218,616 | <p>Given the python function:</p>
<pre><code>def aMethod(arg1, arg2):
pass
</code></pre>
<p>How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2")</p>
<p>The usage scenario for this is that I have a decorator, and... | 131 | 2008-10-20T14:22:02Z | 218,709 | <p>Take a look at the <a href="http://docs.python.org/library/inspect.html">inspect</a> module - this will do the inspection of the various code object properties for you.</p>
<pre><code>>>> inspect.getargspec(aMethod)
(['arg1', 'arg2'], None, None, None)
</code></pre>
<p>The other results are the name of th... | 240 | 2008-10-20T14:52:19Z | [
"python",
"decorator",
"introspection",
"python-datamodel"
] |
Getting method parameter names in python | 218,616 | <p>Given the python function:</p>
<pre><code>def aMethod(arg1, arg2):
pass
</code></pre>
<p>How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2")</p>
<p>The usage scenario for this is that I have a decorator, and... | 131 | 2008-10-20T14:22:02Z | 220,366 | <p>Here is something I think will work for what you want, using a decorator.</p>
<pre><code>class LogWrappedFunction(object):
def __init__(self, function):
self.function = function
def logAndCall(self, *arguments, **namedArguments):
print "Calling %s with arguments %s and named arguments %s" %... | 10 | 2008-10-21T00:02:19Z | [
"python",
"decorator",
"introspection",
"python-datamodel"
] |
Getting method parameter names in python | 218,616 | <p>Given the python function:</p>
<pre><code>def aMethod(arg1, arg2):
pass
</code></pre>
<p>How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2")</p>
<p>The usage scenario for this is that I have a decorator, and... | 131 | 2008-10-20T14:22:02Z | 2,991,341 | <p>I think what you're looking for is the locals method - </p>
<pre><code>
In [6]: def test(a, b):print locals()
...:
In [7]: test(1,2)
{'a': 1, 'b': 2}
</code></pre>
| 9 | 2010-06-07T16:37:20Z | [
"python",
"decorator",
"introspection",
"python-datamodel"
] |
Getting method parameter names in python | 218,616 | <p>Given the python function:</p>
<pre><code>def aMethod(arg1, arg2):
pass
</code></pre>
<p>How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2")</p>
<p>The usage scenario for this is that I have a decorator, and... | 131 | 2008-10-20T14:22:02Z | 16,542,145 | <p>In a decorator method, you can list arguments of the original method in this way:</p>
<pre><code>import inspect, itertools
def my_decorator():
def decorator(f):
def wrapper(*args, **kwargs):
# if you want arguments names as a list:
args_name = inspect.getargs... | 11 | 2013-05-14T11:36:45Z | [
"python",
"decorator",
"introspection",
"python-datamodel"
] |
How do you share data between a parent and forked child process in Python? | 218,935 | <p>I'm pretty sure one would do this using the os.plock(op) function, but I have no idea how. Also, if there's a better way, I'd be grateful to find out. Code snippets are very welcome. </p>
| 10 | 2008-10-20T15:57:05Z | 218,943 | <p>This is pretty much Python-independent! It's a classic example of Unix interprocess communication. One good option is to use <code>popen()</code> to open a pipe between the parent and child processes, and pass data/messages back and forth along the pipe.</p>
<p>Take a look at the <a href="http://www.python.org/do... | 4 | 2008-10-20T15:59:25Z | [
"python",
"fork",
"share"
] |
How do you share data between a parent and forked child process in Python? | 218,935 | <p>I'm pretty sure one would do this using the os.plock(op) function, but I have no idea how. Also, if there's a better way, I'd be grateful to find out. Code snippets are very welcome. </p>
| 10 | 2008-10-20T15:57:05Z | 218,970 | <p>You have two options: <code>os.popen*</code> in the <code>os</code> module, or you can use the <code>subprocess</code> module to the same effect. The Python manual has pretty documentation and examples for <a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html" rel="nofollow" title="popen">popen</a> and <a ... | 1 | 2008-10-20T16:03:59Z | [
"python",
"fork",
"share"
] |
How do you share data between a parent and forked child process in Python? | 218,935 | <p>I'm pretty sure one would do this using the os.plock(op) function, but I have no idea how. Also, if there's a better way, I'd be grateful to find out. Code snippets are very welcome. </p>
| 10 | 2008-10-20T15:57:05Z | 219,048 | <p><a href="http://docs.python.org/library/subprocess">Subprocess</a> replaces os.popen, os.system, os.spawn, popen2 and commands. A <a href="http://docs.python.org/library/subprocess#replacing-shell-pipe-line">simple example for piping</a> would be:</p>
<pre><code>p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep"... | 12 | 2008-10-20T16:26:05Z | [
"python",
"fork",
"share"
] |
How do you share data between a parent and forked child process in Python? | 218,935 | <p>I'm pretty sure one would do this using the os.plock(op) function, but I have no idea how. Also, if there's a better way, I'd be grateful to find out. Code snippets are very welcome. </p>
| 10 | 2008-10-20T15:57:05Z | 219,066 | <p>Take a look at the <a href="http://docs.python.org/dev/library/multiprocessing.html">multiprocessing</a> module new in python 2.6 (also available for earlier versions a <a href="http://pyprocessing.berlios.de/">pyprocessing</a></p>
<p>Here's an example from the docs illustrating passing information using a pipe fo... | 7 | 2008-10-20T16:30:34Z | [
"python",
"fork",
"share"
] |
how can i use sharepoint (via soap?) from python? | 218,987 | <p>I want to use Sharepoint with python (C-Python)</p>
<p>Has anyone tried this before ?</p>
| 9 | 2008-10-20T16:09:36Z | 219,175 | <p>SharePoint exposes several web services which you can use to query and update data.</p>
<p>I'm not sure what web service toolkits there are for Python but they should be able to build proxies for these services without any issues.</p>
<p>This article should give you enough information to get started.</p>
<p><a hr... | 3 | 2008-10-20T17:05:58Z | [
"python",
"sharepoint",
"soap",
"ntlm",
"suds"
] |
how can i use sharepoint (via soap?) from python? | 218,987 | <p>I want to use Sharepoint with python (C-Python)</p>
<p>Has anyone tried this before ?</p>
| 9 | 2008-10-20T16:09:36Z | 219,236 | <p>SOAP with Python is pretty easy. <a href="http://www.diveintopython.net/soap_web_services/index.html" rel="nofollow">Here's a tutorial</a> from Dive Into Python.</p>
| 4 | 2008-10-20T17:29:52Z | [
"python",
"sharepoint",
"soap",
"ntlm",
"suds"
] |
how can i use sharepoint (via soap?) from python? | 218,987 | <p>I want to use Sharepoint with python (C-Python)</p>
<p>Has anyone tried this before ?</p>
| 9 | 2008-10-20T16:09:36Z | 222,242 | <p>To get the wsdl :</p>
<pre><code>import sys
# we use suds -> https://fedorahosted.org/suds
from suds import WebFault
from suds.client import *
import urllib2
# my 2 url conf
# url_sharepoint,url_NTLM_authproxy
import myconfig as my
# build url
wsdl = '_vti_bin/SiteData.asmx?WSDL'
url = '/'.join([my.url_shar... | 8 | 2008-10-21T15:13:46Z | [
"python",
"sharepoint",
"soap",
"ntlm",
"suds"
] |
how can i use sharepoint (via soap?) from python? | 218,987 | <p>I want to use Sharepoint with python (C-Python)</p>
<p>Has anyone tried this before ?</p>
| 9 | 2008-10-20T16:09:36Z | 5,403,203 | <p>I suspect that since this question was answered the SUDS library has been updated to take care of the required authentication itself. After jumping through various hoops, I found this to do the trick:</p>
<pre><code>
from suds import WebFault
from suds.client import *
from suds.transport.https import WindowsHttpAut... | 9 | 2011-03-23T09:36:12Z | [
"python",
"sharepoint",
"soap",
"ntlm",
"suds"
] |
How Python web frameworks, WSGI and CGI fit together | 219,110 | <p>I have a <a href="http://en.wikipedia.org/wiki/Bluehost">Bluehost</a> account where I can run Python scripts as CGI. I guess it's the simplest CGI, because to run I have to define the following in <code>.htaccess</code>:</p>
<pre><code>Options +ExecCGI
AddType text/html py
AddHandler cgi-script .py
</code></pre>
<... | 127 | 2008-10-20T16:43:57Z | 219,124 | <p>You can <a href="http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side">run WSGI over CGI as Pep333 demonstrates</a> as an example. However every time there is a request a new Python interpreter is started and the whole context (database connections, etc.) needs to be build which all take time.</p>
<p>Th... | 21 | 2008-10-20T16:49:17Z | [
"python",
"apache",
"cgi",
"wsgi"
] |
How Python web frameworks, WSGI and CGI fit together | 219,110 | <p>I have a <a href="http://en.wikipedia.org/wiki/Bluehost">Bluehost</a> account where I can run Python scripts as CGI. I guess it's the simplest CGI, because to run I have to define the following in <code>.htaccess</code>:</p>
<pre><code>Options +ExecCGI
AddType text/html py
AddHandler cgi-script .py
</code></pre>
<... | 127 | 2008-10-20T16:43:57Z | 505,534 | <p>I think <a href="http://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together/219124#219124">Florian's answer</a> answers the part of your question about "what is WSGI", especially if you read <a href="http://www.python.org/dev/peps/pep-0333">the PEP</a>.</p>
<p>As for the questions... | 49 | 2009-02-03T00:04:46Z | [
"python",
"apache",
"cgi",
"wsgi"
] |
How Python web frameworks, WSGI and CGI fit together | 219,110 | <p>I have a <a href="http://en.wikipedia.org/wiki/Bluehost">Bluehost</a> account where I can run Python scripts as CGI. I guess it's the simplest CGI, because to run I have to define the following in <code>.htaccess</code>:</p>
<pre><code>Options +ExecCGI
AddType text/html py
AddHandler cgi-script .py
</code></pre>
<... | 127 | 2008-10-20T16:43:57Z | 518,104 | <p>It's a simple abstraction layer for Python, akin to what the Servlet spec is for Java. Whereas CGI is really low level and just dumps stuff into the process environment and standard in/out, the above two specs model the http request and response as constructs in the language. My impression however is that in Pytho... | 4 | 2009-02-05T21:48:33Z | [
"python",
"apache",
"cgi",
"wsgi"
] |
How Python web frameworks, WSGI and CGI fit together | 219,110 | <p>I have a <a href="http://en.wikipedia.org/wiki/Bluehost">Bluehost</a> account where I can run Python scripts as CGI. I guess it's the simplest CGI, because to run I have to define the following in <code>.htaccess</code>:</p>
<pre><code>Options +ExecCGI
AddType text/html py
AddHandler cgi-script .py
</code></pre>
<... | 127 | 2008-10-20T16:43:57Z | 520,194 | <p><strong>How WSGI, CGI, and the frameworks are all connected ?</strong></p>
<p>Apache listens on port 80. It gets an HTTP request. It parses the request to find a way to respond. Apache has a LOT of choices for responding. One way to respond is to use CGI to run a script. Another way to respond is to simply se... | 200 | 2009-02-06T13:04:12Z | [
"python",
"apache",
"cgi",
"wsgi"
] |
How Python web frameworks, WSGI and CGI fit together | 219,110 | <p>I have a <a href="http://en.wikipedia.org/wiki/Bluehost">Bluehost</a> account where I can run Python scripts as CGI. I guess it's the simplest CGI, because to run I have to define the following in <code>.htaccess</code>:</p>
<pre><code>Options +ExecCGI
AddType text/html py
AddHandler cgi-script .py
</code></pre>
<... | 127 | 2008-10-20T16:43:57Z | 9,932,664 | <p>If you are unclear on all the terms in this space, and lets face it, its a confusing acronym-laden one, there's also a good background reader in the form of an official python HOWTO which discusses CGI vs. FastCGI vs. WSGI and so on: <a href="http://docs.python.org/howto/webservers.html">http://docs.python.org/howto... | 6 | 2012-03-29T20:04:51Z | [
"python",
"apache",
"cgi",
"wsgi"
] |
How do I use Tkinter with Python on Windows Vista? | 219,215 | <p>I installed Python 2.6 for one user on Windows Vista. Python works okay, but when I try: <code>import Tkinter</code>, it says the side-by-side configuration has errors. I've tried tinkering with the Visual Studio runtime, with no good results. Any ideas on how to resolve this?</p>
| 3 | 2008-10-20T17:19:57Z | 219,284 | <p>Maybe you should downgrade to 2.5 version?</p>
| 1 | 2008-10-20T17:45:02Z | [
"python",
"windows",
"windows-vista",
"tkinter"
] |
How do I use Tkinter with Python on Windows Vista? | 219,215 | <p>I installed Python 2.6 for one user on Windows Vista. Python works okay, but when I try: <code>import Tkinter</code>, it says the side-by-side configuration has errors. I've tried tinkering with the Visual Studio runtime, with no good results. Any ideas on how to resolve this?</p>
| 3 | 2008-10-20T17:19:57Z | 219,326 | <p>It seems this is a one of the many weird Vista problems and some random reinstalling, installing/upgrading of the visual studio runtime or some such seems sometimes to help, or disabling sxs in the system configuration or writing a manifest file etc.</p>
<p>Though I think you should downgrade to windows XP.</p>
| 1 | 2008-10-20T18:03:30Z | [
"python",
"windows",
"windows-vista",
"tkinter"
] |
How do I use Tkinter with Python on Windows Vista? | 219,215 | <p>I installed Python 2.6 for one user on Windows Vista. Python works okay, but when I try: <code>import Tkinter</code>, it says the side-by-side configuration has errors. I've tried tinkering with the Visual Studio runtime, with no good results. Any ideas on how to resolve this?</p>
| 3 | 2008-10-20T17:19:57Z | 792,527 | <p>python 2.6.2 + tkinter 8.5, no problems</p>
| -1 | 2009-04-27T07:34:14Z | [
"python",
"windows",
"windows-vista",
"tkinter"
] |
django,fastcgi: how to manage a long running process? | 219,329 | <p>I have inherited a django+fastcgi application which needs to be modified to perform a lengthy computation (up to half an hour or more). What I want to do is run the computation in the background and return a "your job has been started" -type response. While the process is running, further hits to the url should retu... | 8 | 2008-10-20T18:05:22Z | 219,353 | <p>Maybe you could look at the problem the other way around.</p>
<p>Maybe you could try <a href="http://code.google.com/p/django-queue-service/" rel="nofollow">DjangoQueueService</a>, and have a "daemon" listening to the queue, seeing if there's something new and process it.</p>
| 3 | 2008-10-20T18:13:38Z | [
"python",
"django",
"fastcgi"
] |
django,fastcgi: how to manage a long running process? | 219,329 | <p>I have inherited a django+fastcgi application which needs to be modified to perform a lengthy computation (up to half an hour or more). What I want to do is run the computation in the background and return a "your job has been started" -type response. While the process is running, further hits to the url should retu... | 8 | 2008-10-20T18:05:22Z | 397,968 | <p>I have to solve a similar problem now. It is not going to be a public site, but similarly, an internal server with low traffic.</p>
<p>Technical constraints:</p>
<ul>
<li>all input data to the long running process can be supplied on its start</li>
<li>long running process does not require user interaction (except ... | 4 | 2008-12-29T15:51:23Z | [
"python",
"django",
"fastcgi"
] |
Iâm stunned: weird problem with python and sockets + threads | 219,547 | <p>I have a python script that is a http-server: <a href="http://paste2.org/p/89701" rel="nofollow">http://paste2.org/p/89701</a>, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everyth... | 2 | 2008-10-20T19:19:45Z | 219,642 | <p>I found <a href="http://www.mail-archive.com/[email protected]/msg22589.html" rel="nofollow">this article</a> on backlog on tomcat / java which gives an interesting insight in the backlog:</p>
<blockquote>
<p>for example, if all threads are busy
in java handling requests, the kernel
will handle SYN and TC... | 0 | 2008-10-20T19:48:00Z | [
"python",
"multithreading",
"apache",
"sockets"
] |
Iâm stunned: weird problem with python and sockets + threads | 219,547 | <p>I have a python script that is a http-server: <a href="http://paste2.org/p/89701" rel="nofollow">http://paste2.org/p/89701</a>, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everyth... | 2 | 2008-10-20T19:19:45Z | 219,671 | <p>I cannot confirm your results, and your server is coded fishy. I whipped up my own server and do not have this problem either. Let's move the discussion to a simpler level:</p>
<pre><code>import thread, socket, Queue
connections = Queue.Queue()
num_threads = 10
backlog = 10
def request():
while 1:
con... | 7 | 2008-10-20T19:56:00Z | [
"python",
"multithreading",
"apache",
"sockets"
] |
Iâm stunned: weird problem with python and sockets + threads | 219,547 | <p>I have a python script that is a http-server: <a href="http://paste2.org/p/89701" rel="nofollow">http://paste2.org/p/89701</a>, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everyth... | 2 | 2008-10-20T19:19:45Z | 219,676 | <p>it looks like you're not really getting concurrency. apparently, when you do socket.accept(), the main thread doesn't go immediately back to waiting for the next connection. maybe your connection-handling thread is only python code, so you're getting sequentialized by the SIL (single interpreder lock).</p>
<p>if ... | 0 | 2008-10-20T19:57:04Z | [
"python",
"multithreading",
"apache",
"sockets"
] |
Iâm stunned: weird problem with python and sockets + threads | 219,547 | <p>I have a python script that is a http-server: <a href="http://paste2.org/p/89701" rel="nofollow">http://paste2.org/p/89701</a>, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everyth... | 2 | 2008-10-20T19:19:45Z | 219,824 | <p>For the heck of it I also implemented an asynchronous version:</p>
<pre><code>import socket, Queue, select
class Request(object):
def __init__(self, conn):
self.conn = conn
self.fileno = conn.fileno
self.perform = self._perform().next
def _perform(self):
data = self.conn.re... | 4 | 2008-10-20T20:37:12Z | [
"python",
"multithreading",
"apache",
"sockets"
] |
Iâm stunned: weird problem with python and sockets + threads | 219,547 | <p>I have a python script that is a http-server: <a href="http://paste2.org/p/89701" rel="nofollow">http://paste2.org/p/89701</a>, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everyth... | 2 | 2008-10-20T19:19:45Z | 222,713 | <p>Ok, so I ran the code on a totally different server - (a vps I got at slicehost), not a single problem (everything works as expected) so honestly I think it's something wrong with my laptop now ;p </p>
<p>Thanks for everyones help though!</p>
| 0 | 2008-10-21T17:21:36Z | [
"python",
"multithreading",
"apache",
"sockets"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,536 | <p>If you create a lock file and put the pid in it, you can check your process id against it and tell if you crashed, no?</p>
<p>I haven't done this personally, so take with appropriate amounts of salt. :p</p>
| 0 | 2008-10-21T02:08:17Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,539 | <p>Can you use the 'pidof' utility? If your app is running, pidof will write the Process ID of your app to stdout. If not, it will print a newline (LF) and return an error code.</p>
<p>Example (from bash, for simplicity):</p>
<pre><code>linux# pidof myapp
8947
linux# pidof nonexistent_app
linux#
</code></pre>
| 0 | 2008-10-21T02:09:29Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,541 | <p>By far the most common method is to drop a file into /var/run/ called [application].pid which contains only the PID of the running process, or parent process.
As an alternative, you can create a named pipe in the same directory to be able to send messages to the active process, e.g. to open a new file.</p>
| 0 | 2008-10-21T02:10:09Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,542 | <p>There are several common techniques including using semaphores. The one I see used most often is to create a "pid lock file" on startup that contains the pid of the running process. If the file already exists when the program starts up, open it up and grab the pid inside, check to see if a process with that pid is... | 21 | 2008-10-21T02:10:24Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,544 | <p><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/semaphore.h.html" rel="nofollow">The set of functions defined in <code>semaphore.h</code></a> -- <code>sem_open()</code>, <code>sem_trywait()</code>, etc -- are the POSIX equivalent, I believe.</p>
| 1 | 2008-10-21T02:10:53Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,590 | <p>Look for a python module that interfaces to SYSV semaphores on unix. The semaphores have a SEM_UNDO flag which will cause the resources held by the a process to be released if the process crashes.</p>
<p>Otherwise as Bernard suggested, you can use </p>
<pre><code>import os
os.getpid()
</code></pre>
<p>And write ... | 1 | 2008-10-21T02:39:56Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 220,709 | <p>The Right Thing is advisory locking using <code>flock(LOCK_EX)</code>; in Python, this is found in the <A HREF="http://docs.python.org/3/library/fcntl.html"><code>fcntl</code> module</A>.</p>
<p>Unlike pidfiles, these locks are always automatically released when your process dies for any reason, have no race condit... | 49 | 2008-10-21T03:43:36Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 221,159 | <p>Complete locking solution using the <code>fcntl</code> module:</p>
<pre><code>import fcntl
pid_file = 'program.pid'
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
# another instance is running
sys.exit(1)
</code></pre>
| 20 | 2008-10-21T08:30:11Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 476,133 | <p>wxWidgets offers a wxSingleInstanceChecker class for this purpose: <a href="http://www.wxpython.org/docs/api/wx.SingleInstanceChecker-class.html">wxPython doc</a>, or <a href="http://docs.wxwidgets.org/stable/wx_wxsingleinstancechecker.html">wxWidgets doc</a>. The wxWidgets doc has sample code in C++, but the pytho... | 8 | 2009-01-24T15:20:51Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 559,978 | <p>I've made a basic framework for running these kinds of applications when you want to be able to pass the command line arguments of subsequent attempted instances to the first one. An instance will start listening on a predefined port if it does not find an instance already listening there. If an instance already e... | 0 | 2009-02-18T05:41:36Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 15,016,759 | <p>This builds upon the <a href="https://stackoverflow.com/a/221159/832230">answer</a> by user <a href="https://stackoverflow.com/users/12138/zgoda">zgoda</a>. It mainly addresses a tricky concern having to do with write access to the lock file. In particular, if the lock file was first created by <code>root</code>, an... | 6 | 2013-02-22T04:18:27Z | [
"python",
"linux",
"singleinstance"
] |
Ensure a single instance of an application in Linux | 220,525 | <p>I'm working on a GUI application in WxPython, and I am not sure how I can ensure that only one copy of my application is running at any given time on the machine. Due to the nature of the application, running more than once doesn't make any sense, and will fail quickly. Under Win32, I can simply make a named mutex a... | 28 | 2008-10-21T01:58:30Z | 34,659,754 | <p>Here's the TCP port-based solution:</p>
<pre><code># Use a listening socket as a mutex against multiple invocations
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 5080))
s.listen(1)
</code></pre>
| 1 | 2016-01-07T16:04:31Z | [
"python",
"linux",
"singleinstance"
] |
Including PYDs/DLLs in py2exe builds | 220,777 | <p>One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to i... | 9 | 2008-10-21T04:40:57Z | 220,830 | <p>If they're not being automatically detected, try manually copying them into py2exe's temporary build directory. They will be included in the final executable.</p>
| 1 | 2008-10-21T05:08:35Z | [
"python",
"dll",
"installation",
"py2exe",
"pyd"
] |
Including PYDs/DLLs in py2exe builds | 220,777 | <p>One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to i... | 9 | 2008-10-21T04:40:57Z | 220,892 | <p>You can modify the setup script to copy the files explicitly:</p>
<pre><code>script = "PyInvaders.py" #name of starting .PY
project_name = os.path.splitext(os.path.split(script)[1])[0]
setup(name=project_name, scripts=[script]) #this installs the program
#also need to hand copy the extra files here
def install... | 2 | 2008-10-21T05:51:12Z | [
"python",
"dll",
"installation",
"py2exe",
"pyd"
] |
Including PYDs/DLLs in py2exe builds | 220,777 | <p>One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to i... | 9 | 2008-10-21T04:40:57Z | 224,154 | <p>Maybe you could use the data_files option to setup():</p>
<pre><code>import glob
setup(name='MyApp',
# other options,
data_files=[('.', glob.glob('*.dll')),
('.', glob.glob('*.pyd'))],
)
</code></pre>
<p>data_files should be a list of tuples, where each tuple contains:</p>
<ol>
... | 2 | 2008-10-22T01:22:00Z | [
"python",
"dll",
"installation",
"py2exe",
"pyd"
] |
Including PYDs/DLLs in py2exe builds | 220,777 | <p>One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to i... | 9 | 2008-10-21T04:40:57Z | 224,274 | <p>.pyd's and .DLL's are different here, in that a .pyd ought to be automatically found by modulefinder and so included (as long as you have the appropriate "import" statement) without needing to do anything. If one is missed, you do the same thing as if a .py file was missed (they're both just modules): use the "incl... | 11 | 2008-10-22T02:27:44Z | [
"python",
"dll",
"installation",
"py2exe",
"pyd"
] |
load dll from python | 220,902 | <p>I'm building a python application from some source code I've found <a href="http://code.google.com/p/enso" rel="nofollow">Here</a></p>
<p>I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:</p>
<p>When running the application this message appears.</p>
<p><img src="http... | 2 | 2008-10-21T05:57:08Z | 220,955 | <p>You probably need to install the VC++ runtime redistributables. The links to them are <a href="http://stackoverflow.com/questions/99479/visual-cstudio-application-configuration-incorrect#100310">here</a>.</p>
| 0 | 2008-10-21T06:20:16Z | [
"python",
"swig",
"scons",
"dynamic-linking"
] |
load dll from python | 220,902 | <p>I'm building a python application from some source code I've found <a href="http://code.google.com/p/enso" rel="nofollow">Here</a></p>
<p>I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:</p>
<p>When running the application this message appears.</p>
<p><img src="http... | 2 | 2008-10-21T05:57:08Z | 221,092 | <p>I've been able to compile and run Enso by using /LD as a compiler flag. This links dynamically to the MS Visual C++ runtime, and seems to allow you to get away without a manifest.</p>
<p>If you're using SCons, see the diff file here: <a href="http://paste2.org/p/69732" rel="nofollow">http://paste2.org/p/69732</a><... | 0 | 2008-10-21T07:53:11Z | [
"python",
"swig",
"scons",
"dynamic-linking"
] |
load dll from python | 220,902 | <p>I'm building a python application from some source code I've found <a href="http://code.google.com/p/enso" rel="nofollow">Here</a></p>
<p>I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:</p>
<p>When running the application this message appears.</p>
<p><img src="http... | 2 | 2008-10-21T05:57:08Z | 221,200 | <p><strong>update</strong>
I've downloaded python2.6 and VS C++ express edition 2008 and the problem with the msvcr80.dll is gone ( I assume because Python and VSC++2008xe use msvscr90.dll) </p>
<p>I've compile with /LD and all the changes listed here: <a href="http://paste2.org/p/69732" rel="nofollow">http://paste2.o... | 0 | 2008-10-21T08:50:26Z | [
"python",
"swig",
"scons",
"dynamic-linking"
] |
load dll from python | 220,902 | <p>I'm building a python application from some source code I've found <a href="http://code.google.com/p/enso" rel="nofollow">Here</a></p>
<p>I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:</p>
<p>When running the application this message appears.</p>
<p><img src="http... | 2 | 2008-10-21T05:57:08Z | 222,263 | <p>Looking at your update, it looks like you need to install <a href="http://www.cairographics.org/pycairo/" rel="nofollow">Pycairo</a> since you're missing the _cairo module installed as part of Pycairo. See the <a href="http://www.cairographics.org/download/" rel="nofollow">Pycairo downloads page</a> for instructions... | 2 | 2008-10-21T15:18:38Z | [
"python",
"swig",
"scons",
"dynamic-linking"
] |
What is the best way on python 2.3 for windows to execute a program like ghostscript with multiple arguments and spaces in paths? | 221,097 | <p>Surely there is some kind of abstraction that allows for this?</p>
<p>This is essentially the command</p>
<blockquote>
<blockquote>
<p>cmd = self._ghostscriptPath + 'gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -r196X204 -sPAPERSIZE=a4 -sOutputFile="' + tifDest + " " + pdfSource + '"'</p>
<p>os.pop... | 3 | 2008-10-21T07:56:33Z | 221,113 | <p>Use <a href="http://docs.python.org/library/subprocess" rel="nofollow">subprocess</a>, it superseeds os.popen, though it is not much more of an abstraction:</p>
<pre><code>from subprocess import Popen, PIPE
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
#this is how I'd mangle the arguments toget... | 4 | 2008-10-21T08:00:56Z | [
"python",
"windows",
"ghostscript"
] |
How can I write a method within a Django model to retrieve related objects? | 221,328 | <p>I have two models. We'll call them object A and object B. Their design looks something like this:</p>
<pre><code>class Foo(models.Model):
name = models.CharField()
class Bar(models.Model):
title = models.CharField()
Foo= models.ForeignKey('myapp.Foo')
</code></pre>
<p>Now, suppose I want to make a ... | 2 | 2008-10-21T09:49:04Z | 221,338 | <p>You get this for free:</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects</a></p>
<p>By default, you can access a Manager which gives you access to related items through ... | 10 | 2008-10-21T09:54:58Z | [
"python",
"django",
"model-view-controller",
"frameworks"
] |
Is it possible to implement Python code-completion in TextMate? | 221,339 | <p><a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">PySmell</a> seems like a good starting point.</p>
<p>I think it should be possible, PySmell's <code>idehelper.py</code> does a majority of the complex stuff, it should just be a case of giving it the current line, offering up the completions (th... | 20 | 2008-10-21T09:54:58Z | 221,609 | <p>This isn't exactly what you're looking for but it might be able to get you started:</p>
<p><a href="http://code.djangoproject.com/wiki/TextMate" rel="nofollow">Using TextMate with Django</a></p>
<p>They appear to be somewhat Django specific but some snippets may assist with your needs. You also may be able to bui... | 3 | 2008-10-21T12:06:28Z | [
"python",
"autocomplete",
"text-editor",
"textmate"
] |
Is it possible to implement Python code-completion in TextMate? | 221,339 | <p><a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">PySmell</a> seems like a good starting point.</p>
<p>I think it should be possible, PySmell's <code>idehelper.py</code> does a majority of the complex stuff, it should just be a case of giving it the current line, offering up the completions (th... | 20 | 2008-10-21T09:54:58Z | 223,862 | <p>In TextMate PHP has a simple auto-completion in form of hardcoded set of function names. Sounds as ugly as PHP, but in practice it's good enough to be useful.</p>
| 0 | 2008-10-21T22:59:10Z | [
"python",
"autocomplete",
"text-editor",
"textmate"
] |
Is it possible to implement Python code-completion in TextMate? | 221,339 | <p><a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">PySmell</a> seems like a good starting point.</p>
<p>I think it should be possible, PySmell's <code>idehelper.py</code> does a majority of the complex stuff, it should just be a case of giving it the current line, offering up the completions (th... | 20 | 2008-10-21T09:54:58Z | 248,819 | <p>EDIT: I've actually took your code above and integrated into a command. It will properly show a completion list for you to choose.</p>
<p>You can grab it here: <a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">http://github.com/orestis/pysmell/tree/master</a> (hit download and do python setup.p... | 9 | 2008-10-29T23:42:15Z | [
"python",
"autocomplete",
"text-editor",
"textmate"
] |
Is it possible to implement Python code-completion in TextMate? | 221,339 | <p><a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">PySmell</a> seems like a good starting point.</p>
<p>I think it should be possible, PySmell's <code>idehelper.py</code> does a majority of the complex stuff, it should just be a case of giving it the current line, offering up the completions (th... | 20 | 2008-10-21T09:54:58Z | 428,145 | <p>It's not perfect, but you can give it a try: <a href="http://mtod.org/tempy" rel="nofollow">http://mtod.org/tempy</a></p>
| 1 | 2009-01-09T14:04:59Z | [
"python",
"autocomplete",
"text-editor",
"textmate"
] |
Putting Copyright Symbol into a Python File | 221,376 | <p>I need to include a copyright statement at the top of every Python source file I produce:</p>
<pre><code># Copyright: © 2008 etc.
</code></pre>
<p>However, when I then run such a file I get this message:</p>
<p>SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see <... | 11 | 2008-10-21T10:15:16Z | 221,380 | <p>The copyright symbol in ASCII is spelled <code>(c)</code> or "<code>Copyright</code>".</p>
<p>See circular 61, <a href="http://www.copyright.gov/circs/circ61.pdf">Copyright Registration for Computer Programs</a>. </p>
<p>While it's true that the legal formalism (see Circular 1, <a href="http://www.copyright.gov/c... | 28 | 2008-10-21T10:17:32Z | [
"python",
"encoding"
] |
Putting Copyright Symbol into a Python File | 221,376 | <p>I need to include a copyright statement at the top of every Python source file I produce:</p>
<pre><code># Copyright: © 2008 etc.
</code></pre>
<p>However, when I then run such a file I get this message:</p>
<p>SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see <... | 11 | 2008-10-21T10:15:16Z | 221,381 | <p>You can always revert to good old (c)</p>
| 2 | 2008-10-21T10:17:51Z | [
"python",
"encoding"
] |
Putting Copyright Symbol into a Python File | 221,376 | <p>I need to include a copyright statement at the top of every Python source file I produce:</p>
<pre><code># Copyright: © 2008 etc.
</code></pre>
<p>However, when I then run such a file I get this message:</p>
<p>SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see <... | 11 | 2008-10-21T10:15:16Z | 221,543 | <p>Waiting for <a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html" rel="nofollow">Python 3k</a>, where the default encoding of the source will be UTF-8?</p>
| 2 | 2008-10-21T11:40:55Z | [
"python",
"encoding"
] |
Putting Copyright Symbol into a Python File | 221,376 | <p>I need to include a copyright statement at the top of every Python source file I produce:</p>
<pre><code># Copyright: © 2008 etc.
</code></pre>
<p>However, when I then run such a file I get this message:</p>
<p>SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see <... | 11 | 2008-10-21T10:15:16Z | 221,569 | <p>Contrary to the accepted answer, AFAIK, (c) is not an officially recognized alternative to the copyright symbol, although I'm not sure it's been tested in court.</p>
<p>However, © is just an abreviation of the word Copyright. Saying "Copyright 2008 Robert Munro" is identical to saying "© 2008 Robert Munro"</p>
<... | 8 | 2008-10-21T11:50:53Z | [
"python",
"encoding"
] |
Putting Copyright Symbol into a Python File | 221,376 | <p>I need to include a copyright statement at the top of every Python source file I produce:</p>
<pre><code># Copyright: © 2008 etc.
</code></pre>
<p>However, when I then run such a file I get this message:</p>
<p>SyntaxError: Non-ASCII character '\xa9' in file MyFile.py on line 3, but no encoding declared; see <... | 11 | 2008-10-21T10:15:16Z | 221,594 | <p>Answers to this <a href="http://stackoverflow.com/questions/201837/do-you-put-copyright-notices-in-your-proprietary-code" rel="nofollow" title="Do you put copyright notices in your proprietary code?">question</a>, particularly @<a href="http://stackoverflow.com/questions/201837/do-you-put-copyright-notices-in-your-p... | 0 | 2008-10-21T12:01:50Z | [
"python",
"encoding"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.