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
Question about paths in Python
1,125,399
<p>let's say i have directory paths looking like this:</p> <pre><code>this/is/the/basedir/path/a/include this/is/the/basedir/path/b/include this/is/the/basedir/path/a this/is/the/basedir/path/b </code></pre> <p>In Python, how can i split these paths up so they will look like this instead:</p> <pre><code>a/include b/...
1
2009-07-14T13:30:55Z
1,125,569
<p>Maybe something like this:</p> <pre><code>result = [] prefix = os.path.commonprefix(list_of_paths) for path in list_of_paths: result.append(os.path.relpath(path, prefix)) </code></pre> <p>This works only in 2.6. The relapath in 2.5 and before does the work only in case the path is the current working director...
1
2009-07-14T13:56:52Z
[ "python", "operating-system" ]
Question about paths in Python
1,125,399
<p>let's say i have directory paths looking like this:</p> <pre><code>this/is/the/basedir/path/a/include this/is/the/basedir/path/b/include this/is/the/basedir/path/a this/is/the/basedir/path/b </code></pre> <p>In Python, how can i split these paths up so they will look like this instead:</p> <pre><code>a/include b/...
1
2009-07-14T13:30:55Z
1,125,837
<p>While the criterion is not 100% clear, it seems from the OP's comment that the key issue is specifically whether the path's last component ends in "include". If that is the case, and to avoid going wrong when the last component is e.g. "dontinclude" (as another answer does by trying string matching instead of path m...
0
2009-07-14T14:36:01Z
[ "python", "operating-system" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
1,125,613
<p>Disclaimer: I have not tried this.</p> <p>I believe you need to implement a custom database back end. There are a few examples on the web that shows how to implement a database back end with connection pooling.</p> <p>Using a connection pool would probably be a good solution for you case, as the network connection...
3
2009-07-14T14:05:49Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
1,175,140
<p>In Django trunk, edit <code>django/db/__init__.py</code> and comment out the line:</p> <pre><code>signals.request_finished.connect(close_connection) </code></pre> <p>This signal handler causes it to disconnect from the database after every request. I don't know what all of the side-effects of doing this will be, ...
17
2009-07-23T23:55:40Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
1,351,213
<p>I made some small custom psycopg2 backend that implements persistent connection using global variable. With this I was able to improve the amout of requests per second from 350 to 1600 (on very simple page with few selects) Just save it in the file called <code>base.py</code> in any directory (e.g. postgresql_psyco...
0
2009-08-29T11:32:36Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
1,698,102
<p>Try <a href="http://wiki.postgresql.org/wiki/PgBouncer" rel="nofollow">PgBouncer</a> - a lightweight connection pooler for PostgreSQL. Features:</p> <ul> <li>Several levels of brutality when rotating connections: <ul> <li>Session pooling</li> <li>Transaction pooling</li> <li>Statement pooling</li> </ul></li> <li>Lo...
19
2009-11-08T22:15:33Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
6,712,190
<p>I created a small <a href="http://dumpz.org/67550/">Django patch</a> that implements connection pooling of MySQL and PostgreSQL via sqlalchemy pooling.</p> <p>This works perfectly on production of <a href="http://grandcapital.net/">http://grandcapital.net/</a> for a long period of time.</p> <p>The patch was writte...
13
2011-07-15T19:26:17Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Django persistent database connection
1,125,504
<p>I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). Wh...
45
2009-07-14T13:47:00Z
19,438,241
<p>Django <strong>1.6</strong> has added <a href="https://docs.djangoproject.com/en/1.9/ref/databases/#persistent-connections" rel="nofollow">persistent connections support (link to doc for django 1.9)</a>:</p> <blockquote> <p>Persistent connections avoid the overhead of re-establishing a connection to the databas...
17
2013-10-17T22:13:17Z
[ "python", "database", "django", "mod-wsgi", "persistent" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,645
<p>So far as I know, the standard Python shell doesn't know how to execute remote scripts. Try using <code>curl</code> or <code>wget</code> to retrieve the script and run it from the local copy.</p> <pre><code>$ wget http://cs.edu.com/u/user/TEST/one.py $ python one.py </code></pre> <p>UPDATE: Based on the <a href="h...
3
2009-07-14T14:11:54Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,651
<pre><code>wget http://cs.edu.com/u/user/TEST/one.py python one.py </code></pre>
1
2009-07-14T14:12:32Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,656
<p>You can't do this. If you have SSH access to the server you can then run the python script located on the server using your SSH connection. If you want to write websites in python google python web frameworks for examples of how to set up and run websites with Python.</p>
3
2009-07-14T14:13:06Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,670
<p>You can mount the remote servers directory with some sort of file networking, like NFS or something. That way it becomes local.</p> <p>But a better idea is that you explain why you are trying to do this, so we can solve the real usecase. There is most likely tons of better solutions, depending on what the real prob...
1
2009-07-14T14:15:40Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,674
<p>The python interpreter doesn't know how to read from a URL. The file needs to be local. </p> <p>However, if you are trying to get the <em>server</em> to execute the python code, you can use <a href="http://www.modpython.org/" rel="nofollow">mod_python</a> or various kinds of CGI. </p> <p>You can't do what you a...
1
2009-07-14T14:16:44Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,125,712
<p>Maybe something like this?</p> <pre><code>python -c "import urllib; eval(urllib.urlopen(\"http://cs.edu.com/u/user/TEST/one.py").read())" </code></pre>
1
2009-07-14T14:20:34Z
[ "python" ]
Running Python code from a server?
1,125,637
<p><strong>Problem:</strong> to run one.py from a server.</p> <p><strong>Error</strong></p> <p>When I try to do it in Mac, I get errors:</p> <pre><code>$python http://cs.edu.com/u/user/TEST/one.py ~ /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: c...
0
2009-07-14T14:10:25Z
1,126,247
<p>OK, now when you explained, here is a new answer.</p> <p>You run that script with </p> <pre><code> python one.py </code></pre> <p>It's a server side-script. It's run on the server. It's also located on the server. Why you try to access it via http is beyond me. Run it from the file system.</p> <p>Although, you s...
1
2009-07-14T15:38:23Z
[ "python" ]
Running programs w/ a GUI over a remote connection
1,125,894
<p>I'm trying to start perfmon and another program that have GUI's through a python script that uses a PKA ssh connection. Is it possible to do this? If so could anyone point me in the right direction?</p>
0
2009-07-14T14:43:57Z
1,125,920
<p>If you mean <a href="http://perfmon.sourceforge.net/" rel="nofollow">this</a> perfmon (the one that runs under Linux &amp;c == I believe there's a honomym program that's Windows-only and would behave very differently), <code>ssh -X</code> or <code>ssh -Y</code> let you open an ssh connection which tunnels an X11 (GU...
1
2009-07-14T14:48:59Z
[ "python", "user-interface", "ssh", "perfmon" ]
Running programs w/ a GUI over a remote connection
1,125,894
<p>I'm trying to start perfmon and another program that have GUI's through a python script that uses a PKA ssh connection. Is it possible to do this? If so could anyone point me in the right direction?</p>
0
2009-07-14T14:43:57Z
1,196,773
<p>I've found a program called psexec that will open a program remotely on another windows machine. <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx" rel="nofollow">http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx</a> There are options or flags that you can use with this command line ...
0
2009-07-28T21:12:38Z
[ "python", "user-interface", "ssh", "perfmon" ]
Python: Persistent shell variables in subprocess
1,126,116
<p>I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.</p> <p>Is there any way to go about this? I could create ...
8
2009-07-14T15:19:21Z
1,126,137
<p><code>subprocess.Popen</code> takes an optional named argument <code>env</code> that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of <code>os.environ</code> and alter that as you need) and pass it to all ...
13
2009-07-14T15:22:45Z
[ "python", "shell", "variables", "subprocess", "persistent" ]
Python: Persistent shell variables in subprocess
1,126,116
<p>I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.</p> <p>Is there any way to go about this? I could create ...
8
2009-07-14T15:19:21Z
1,339,904
<p>Alex is absolutely correct. To give an example</p> <pre><code>current_env=environ.copy() current_env["XXX"] = "SOMETHING" #If you want to change some env variable subProcess.Popen("command_n_args", env=current_env) </code></pre>
5
2009-08-27T09:22:32Z
[ "python", "shell", "variables", "subprocess", "persistent" ]
writeline problem in python
1,126,477
<p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <pre><code>ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read fi...
2
2009-07-14T16:15:17Z
1,126,505
<pre><code>#read following lines which contain data &amp; write it to ofile for line in ifile: if not line: continue #break stops the loop, you should use continue ofile.write(line) </code></pre>
4
2009-07-14T16:22:15Z
[ "python" ]
writeline problem in python
1,126,477
<p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <pre><code>ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read fi...
2
2009-07-14T16:15:17Z
1,126,515
<p>You should be calling ofile.close() according to <a href="http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow">python docs</a>.</p> <p>I'm not sure that writes are fully flushed out to a file without an explicit close. </p> <p>Also, as SilentGhost mentioned, check for empty l...
5
2009-07-14T16:23:00Z
[ "python" ]
writeline problem in python
1,126,477
<p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <pre><code>ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read fi...
2
2009-07-14T16:15:17Z
1,126,525
<p>oh, why does it look so foolish, the formation i mean? Give it another go...</p> <p>hi,</p> <p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <p>ifile=open("C:\Python24\Ots...
0
2009-07-14T16:24:28Z
[ "python" ]
writeline problem in python
1,126,477
<p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <pre><code>ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read fi...
2
2009-07-14T16:15:17Z
1,126,539
<p>The "if not line:" - Check is unnecessary.</p> <pre><code>for line in ifile: ofile.write(line) </code></pre>
3
2009-07-14T16:26:44Z
[ "python" ]
writeline problem in python
1,126,477
<p>I have a very basic problem. I am learning my first steps with python &amp; scripting in general and so even this makes me wonder:</p> <p>I want to read &amp; write lines to new file:</p> <pre><code>ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r") ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w") #read fi...
2
2009-07-14T16:15:17Z
1,127,857
<p>Why are you using python2.4? the latest is python2.6 </p> <p>and then you can use </p> <pre><code>from contextlib import nested ipath = "C:\Python24\OtsakkeillaSPSS.csv" opath = "C:\Python24\OtsakkeillaSPSSout.csv" with nested(open(ipath,'r'), open(opath,'w') as ifile, ofile: #read first line with headers ...
1
2009-07-14T20:33:30Z
[ "python" ]
How would you inherit from and override the django model classes to create a listOfStringsField?
1,126,642
<p>I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following:</p> <p><strong>models.py:</strong></p> <pre><code>from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharF...
6
2009-07-14T16:44:43Z
1,126,953
<p>I think what you want is a <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/" rel="nofollow">custom model field</a>.</p>
-1
2009-07-14T17:50:43Z
[ "python", "django", "inheritance", "django-models" ]
How would you inherit from and override the django model classes to create a listOfStringsField?
1,126,642
<p>I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following:</p> <p><strong>models.py:</strong></p> <pre><code>from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharF...
6
2009-07-14T16:44:43Z
1,127,073
<p>There's some very good documentation on creating custom fields <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/">here</a>. </p> <p>However, I think you're overthinking this. It sounds like you actually just want a standard foreign key, but with the additional ability to retrieve all the elem...
6
2009-07-14T18:15:54Z
[ "python", "django", "inheritance", "django-models" ]
How would you inherit from and override the django model classes to create a listOfStringsField?
1,126,642
<p>I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following:</p> <p><strong>models.py:</strong></p> <pre><code>from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharF...
6
2009-07-14T16:44:43Z
1,128,596
<p>I also think you're going about this the wrong way. Trying to make a Django field create an ancillary database table is almost certainly the wrong approach. It would be very difficult to do, and would likely confuse third party developers if you are trying to make your solution generally useful.</p> <p>If you're tr...
5
2009-07-14T23:13:30Z
[ "python", "django", "inheritance", "django-models" ]
How would you inherit from and override the django model classes to create a listOfStringsField?
1,126,642
<p>I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following:</p> <p><strong>models.py:</strong></p> <pre><code>from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharF...
6
2009-07-14T16:44:43Z
1,132,043
<p>Thanks for all those that answered. Even if I didn't use your answer directly the examples and links got me going in the right direction.</p> <p>I am not sure if this is production ready, but it appears to be working in all my tests so far. </p> <pre><code>class ListValueDescriptor(object): def __init__(self, ...
1
2009-07-15T15:14:04Z
[ "python", "django", "inheritance", "django-models" ]
How would you inherit from and override the django model classes to create a listOfStringsField?
1,126,642
<p>I want to create a new type of field for django models that is basically a ListOfStrings. So in your model code you would have the following:</p> <p><strong>models.py:</strong></p> <pre><code>from django.db import models class ListOfStringsField(???): ??? class myDjangoModelClass(): myName = models.CharF...
6
2009-07-14T16:44:43Z
1,153,959
<p>What you have described sounds to me really similar to the tags.<br /> So, why not using <a href="http://code.google.com/p/django-tagging/">django tagging</a>?<br /> It works like a charm, you can install it independently from your application and its API is quite easy to use.</p>
5
2009-07-20T14:32:47Z
[ "python", "django", "inheritance", "django-models" ]
django-timezones
1,126,811
<p>I am trying to setup django-timezones but am unfamiliar on how to go about this. The only info that I have found is here: <a href="http://www.ohloh.net/p/django-timezones" rel="nofollow">http://www.ohloh.net/p/django-timezones</a></p> <pre><code>class MyModel(Model): timezone = TimeZoneField() datetime =...
1
2009-07-14T17:23:31Z
1,128,277
<p>Well, the firs thing you need to do when installing any Django app, is add it to your INSTALLED_APPS in settings.py. This particular app doesn't do to much other then give you some handy fields and things that you can use in other parts of your Django project. Your best bet to understand it is reading the source, I ...
4
2009-07-14T21:53:08Z
[ "python", "django", "timezone" ]
Best way to have full Python install under cygwin/XP?
1,126,842
<p>Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not l...
3
2009-07-14T17:28:02Z
1,126,858
<p>Well, in my windows environment I use <a href="http://www.activestate.com/activepython/" rel="nofollow">active python</a> and it, so far, works for me.</p>
0
2009-07-14T17:30:49Z
[ "python", "windows-xp", "cygwin" ]
Best way to have full Python install under cygwin/XP?
1,126,842
<p>Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not l...
3
2009-07-14T17:28:02Z
1,126,874
<p>Just a little off the question, but...</p> <p>Have you considered running Sun's VirtualBox with Fedora or Ubuntu inside of it? I'm assuming you have to / need to use windows because you still are, but don't like it. Then you would have python running inside a native linux desktop without any of the troubles you m...
0
2009-07-14T17:34:13Z
[ "python", "windows-xp", "cygwin" ]
Best way to have full Python install under cygwin/XP?
1,126,842
<p>Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not l...
3
2009-07-14T17:28:02Z
1,126,885
<p>I use Python from within cygwin, but I don't use the version that cygwin gives you the option of installing as I don't have the control over version number used that I need (we use an older version at work). I have my python version installed via the windows installer (the xp version as you put it) and add the /cyg...
2
2009-07-14T17:37:23Z
[ "python", "windows-xp", "cygwin" ]
Best way to have full Python install under cygwin/XP?
1,126,842
<p>Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not l...
3
2009-07-14T17:28:02Z
1,128,193
<p>This probably has little value, but... I found myself in this exact situation -- we use ActivePython2.5 in production (pure windows environment) and I was trying to do my development within cygwin and cygwin's Python... </p> <p>After ripping out half of my hair, I have now switched over to Console2, gvim, iPython a...
0
2009-07-14T21:33:58Z
[ "python", "windows-xp", "cygwin" ]
Best way to have full Python install under cygwin/XP?
1,126,842
<p>Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not l...
3
2009-07-14T17:28:02Z
11,792,553
<p>I accidentally stumbled on this - If I launch Cygwin from the Cygwin.bat file (which is present directly under the main folder), I get access to the Python version installed under Cygwin (i.e 2.6.8)</p> <p>If I instead launch the Cygwin from bash.exe under bin directory (C:\Cygwin\bin\bash.exe for me), running "Pyt...
0
2012-08-03T09:00:18Z
[ "python", "windows-xp", "cygwin" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
1,127,042
<p>Normally, when I use ipython, I turn automatic debugging on with the "pdb" command inside it.</p> <p>I then run my script with the "run myscript.py" command in the directory where my script is located.</p> <p>If I get an exception, ipython stops the program inside the debugger. Check out the help command for the ...
7
2009-07-14T18:08:30Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
1,127,071
<p>From the <a href="http://ipython.scipy.org/doc/stable/html/interactive/extension%5Fapi.html#launching-ipython-instance-from-normal-python-code" rel="nofollow">IPython docs</a>:</p> <pre><code>import IPython.ipapi namespace = dict( kissa = 15, koira = 16) IPython.ipapi.launch_new_instance(namespace) </code><...
3
2009-07-14T18:15:32Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
1,127,087
<p>There is an <code>ipdb</code> project which embeds iPython into the standard pdb, so you can just do:</p> <pre><code>import ipdb; ipdb.set_trace() </code></pre> <p>It's installable via the usual <code>easy_install ipdb</code>.</p> <p><code>ipdb</code> is pretty short, so instead of easy_installing you can also cr...
91
2009-07-14T18:18:53Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
1,128,816
<p>The equivalent of </p> <pre><code>import pdb; pdb.set_trace() </code></pre> <p>with IPython is something like:</p> <pre><code>from IPython.ipapi import make_session; make_session() from IPython.Debugger import Pdb; Pdb().set_trace() </code></pre> <p>It's a bit verbose, but good to know if you don't have ipdb ins...
9
2009-07-15T00:40:39Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
4,087,236
<p>The fast-and-easy way:</p> <pre><code>from IPython.Debugger import Tracer debug = Tracer() </code></pre> <p>Then just write</p> <pre><code>debug() </code></pre> <p>wherever you want to start debugging your program.</p>
3
2010-11-03T12:57:03Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
7,411,459
<p>In IPython 0.11, you can embed IPython directly in your code like this</p> <p>Your program might look like this</p> <pre><code>In [5]: cat &gt; tmpf.py a = 1 from IPython import embed embed() # drop into an IPython session. # Any variables you define or modify here # will not affect program execut...
35
2011-09-14T05:00:59Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
12,177,383
<p>I like to simply paste this one-liner in my scripts where I want to set a breakpoint:</p> <pre><code>__import__('IPython').Debugger.Pdb(color_scheme='Linux').set_trace() </code></pre> <p>Newer version might use:</p> <pre><code>__import__('IPython').core.debugger.Pdb(color_scheme='Linux').set_trace() </code></pre>...
6
2012-08-29T11:58:31Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
12,528,973
<p>If you're using a more modern version of IPython (> 0.10.2) you can use something like</p> <pre><code>from IPython.core.debugger import Pdb Pdb().set_trace() </code></pre> <p>But it's probably better to just use ipdb </p>
9
2012-09-21T10:41:44Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
14,464,781
<p>Looks like modules have been shuffled around a bit recently. On IPython 0.13.1 the following works for me</p> <pre><code>from IPython.core.debugger import Tracer; breakpoint = Tracer() breakpoint() # &lt;= wherever you want to set the breakpoint </code></pre> <p>Though alas, it's all pretty <a href="https://githu...
5
2013-01-22T17:43:14Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
15,665,321
<p>Newer versions of IPython provide an easy mechanism for embedding and nesting IPython sessions into any Python programs. You can follow <a href="http://ipython.org/ipython-doc/dev/interactive/reference.html#embedding-ipython" rel="nofollow">the following recipe</a> to embed IPython sessions:</p> <pre><code>try: ...
4
2013-03-27T17:22:12Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Is it possible to go into ipython from code?
1,126,930
<p>For my debugging needs, <code>pdb</code> is pretty good. However, it would be <em>much</em> cooler (and helpful) if I could go into <code>ipython</code>. Is this thing possible?</p>
66
2009-07-14T17:45:59Z
29,082,893
<p>I had to google this a couple if times the last few days so adding an answer... sometimes it's nice to be able run a script normally and only drop into ipython/ipdb on errors, without having to put <code>ipdb.set_trace()</code> breakpoints into the code</p> <pre><code>ipython --pdb -c "%run path/to/my/script.py --...
1
2015-03-16T17:11:12Z
[ "python", "shell", "debugging", "ipython", "pdb" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,637
<p>If you don't test, how will you really know it does nothing? :)</p> <p>Sorry - couldn't resist. Seriously - I would test because some day it might do more?</p>
12
2009-07-14T20:02:42Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,638
<p>If it doesn't do anything then there's nothing to test. If you really want you could verify that it doesn't modify any state. I'm not familiar enough with Python to know if there's an easy way to make verify that your methods don't call any other methods, but you could do that as well if you really want.</p>
1
2009-07-14T20:02:43Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,641
<p>If it can't fail. There is nothing to test.</p> <p>Test case results need to contain at least one successful state, and at least one unsuccessful state. If any input into the test results in successful output. Then there is not a test you could create the would ever fail.</p>
4
2009-07-14T20:03:09Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,654
<p>Depends on your theory.</p> <p>If you do a test driven type of person, then in order for that code to exist, you had to write the test for it.</p> <p>If you are thinking of it as, I wrote it, how do I test it, then I think it warrants a test since you are relying on it to do nothing. You need the test to make sure...
2
2009-07-14T20:04:29Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,665
<p>I don't know Python, but I can think of one test- check that the class actually creates without error. This will at least regression test the class and means it should work in all circumstances.</p> <p>You never know someone might edit the class in the future and get it to throw an exception or something weird!</p...
1
2009-07-14T20:05:36Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,674
<p>Be pragmatic, there is nothing to test here. </p>
3
2009-07-14T20:06:23Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,688
<p>Argument: You don't base your tests on the reading of the implementation but on the intended behaviour. You test that the darn thing doesn't crash when called.</p> <p>This case a bit obsessive perhaps, and frankly I maybe I wouldn't bother. But it only take a small increment over these null functions for there to b...
1
2009-07-14T20:08:16Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,699
<p>You could test the arguments that are passed to it. If this is a dummy object that will get called with a particular set of arguments then modifying that arguments will make it fail. A test like that will ensure that if it does get modified at least no other code break that depends on it.</p>
0
2009-07-14T20:10:22Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,713
<p>According to the "You Ain't Gonna Need It" rule, you shouldn't write a test when there is nothing to test even if one day it might do something.</p> <p>How to test that something has done nothing? That's a nice philosophical question :)</p>
0
2009-07-14T20:12:04Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,721
<p>I think the only useful benefit of a test for such a class is to hopefully catch if someone starts modifying it down the road. Otherwise I wouldn't bother.</p>
0
2009-07-14T20:12:36Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,742
<p>You at least want it to not break anything when used in place of the actual logger. So reuse the actual logger tests and factor out the assertions that test that it actually logs.</p>
0
2009-07-14T20:15:58Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,762
<p>If anyone's interested, here's a test I ended up writing:</p> <pre><code>def test_dummy_loader(): from loader_logs import DummyLog from copy import copy dummy = DummyLog() initial = copy(dummy.__dict__) dummy.insert_master_log('', '', '', '') dummy.update_master_log(0, 0, 0, 0) post = co...
2
2009-07-14T20:18:18Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,765
<p>That DummyLogger is what is called in design pattern a "Null Object". Subclass your real Logger from that, create some test for the real logger and then use the same test but with the DummyLogger.</p> <pre><code>class TestLogger(unittest.TestCase): def setUp(self): self.logger = RealLogger() def test_l...
1
2009-07-14T20:19:31Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,127,962
<p>Of course you can test a class that doesn't do anything. You test that it does, in fact, not do anything.</p> <p>In practice, that means:</p> <ul> <li>it exists and can be instantiated;</li> <li>it doesn't throw an exception when used; call every method and simply assert that they succeed. This also doubles as c...
4
2009-07-14T20:51:29Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Do I test a class that does nothing?
1,127,626
<p>In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:</p> <pre><code>class DummyLog(object): def insert_master_log(self, spec_name, file_name, data_source, ...
4
2009-07-14T19:59:41Z
1,133,575
<p>It obviously does something or you wouldn't have written it.</p> <p>I'm going to guess its meant to mirror the interface of your real logging class. So test that it has the same interface, that it takes the same arguments. You're likely to change your logging while forgetting to update the dummy. If that seems r...
2
2009-07-15T19:50:23Z
[ "python", "unit-testing", "testing", "logging", "polymorphism" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,804
<p>You should tell the interpreter which encoding you're using, because apparently on your system it defaults to ascii. See <a href="http://www.python.org/dev/peps/pep-0263/" rel="nofollow">PEP 263</a>. In your case, place the following at the top of your file:</p> <pre><code># -*- coding: utf-8 -*- </code></pre> <p>...
11
2009-07-14T20:24:50Z
[ "python", "chars" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,807
<p>Do you store the Python file as UTF-8? Does your editor support UTF-8? Are you using unicode strings like so?</p> <pre><code>foo = u'ƃƃƃƃƃ' </code></pre>
1
2009-07-14T20:25:25Z
[ "python", "chars" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,810
<p>Declare Unicode strings.</p> <p>somestring = u'æøå'</p>
0
2009-07-14T20:25:53Z
[ "python", "chars" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,815
<p><a href="http://docs.python.org/tutorial/interpreter.html#source-code-encoding" rel="nofollow">http://docs.python.org/tutorial/interpreter.html#source-code-encoding</a></p>
3
2009-07-14T20:26:41Z
[ "python", "chars" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,820
<p>In python it should be</p> <pre><code>u"\u0183" </code></pre> <p>The u before the String start indicates that the String contains Unicode characters.</p> <p>See here for reference: </p> <p><a href="http://www.fileformat.info/info/unicode/char/0183/index.htm" rel="nofollow">http://www.fileformat.info/info/unicode...
0
2009-07-14T20:27:15Z
[ "python", "chars" ]
Special chars in Python
1,127,786
<p>i have to use special chars in my python-application. For example: ƃ I have information like this:</p> <pre><code>U+0183 LATIN SMALL LETTER B WITH TOPBAR General Character Properties In Unicode since: 1.1 Unicode category: Letter, Lowercase Various Useful Representations UTF-8: 0xC6 0x83 UTF-16: 0x0183 C octa...
2
2009-07-14T20:21:58Z
1,127,970
<p>While the answers so fare are all correct, I thought I'd provide a more complete treatment:</p> <p>The simplest way to represent a non-ASCII character in a script literal is to use the u prefix and u or U escapes, like so:</p> <pre><code>print u"Look \u0411\u043e\u0440\u0438\u0441, a G-clef: \U0001d11e" </code></p...
3
2009-07-14T20:52:26Z
[ "python", "chars" ]
Python object has no referrers but still accessible via a weakref?
1,127,836
<p>Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?</p> <p>If so how would I start trying to identify the cause for this object not being garbage collected?</p> <p>Edit: I'm not sure exactly how a code sample would help...
3
2009-07-14T20:29:34Z
1,127,854
<p>Yes: <a href="http://docs.python.org/library/weakref.html" rel="nofollow">http://docs.python.org/library/weakref.html</a></p> <p>A weak reference won't be keeping the object alive.</p> <p>The get_referrers() function will only locate those containers which support garbage collection; extension types which do refer...
1
2009-07-14T20:32:51Z
[ "python", "garbage-collection", "cpython" ]
Python object has no referrers but still accessible via a weakref?
1,127,836
<p>Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?</p> <p>If so how would I start trying to identify the cause for this object not being garbage collected?</p> <p>Edit: I'm not sure exactly how a code sample would help...
3
2009-07-14T20:29:34Z
1,127,890
<p>As <a href="http://stackoverflow.com/questions/1127836/python-object-has-no-referrers-but-still-accessible-via-a-weakref/1127854#1127854">Christopher says</a>, a weak reference does not count into object refcount, and therefore is not able to keep Python from deleting an object.</p> <p>However, Python's garbage col...
0
2009-07-14T20:38:33Z
[ "python", "garbage-collection", "cpython" ]
Python object has no referrers but still accessible via a weakref?
1,127,836
<p>Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?</p> <p>If so how would I start trying to identify the cause for this object not being garbage collected?</p> <p>Edit: I'm not sure exactly how a code sample would help...
3
2009-07-14T20:29:34Z
1,128,036
<p>If you do have a strong reference to the object, use gc.get_referrers(obj) to find it.</p> <p>This can help if you have a leak and don't know what's leaking:</p> <p><a href="http://mg.pov.lt/objgraph.py" rel="nofollow">http://mg.pov.lt/objgraph.py</a> <a href="http://mg.pov.lt/blog/hunting-python-memleaks" rel="no...
0
2009-07-14T21:06:00Z
[ "python", "garbage-collection", "cpython" ]
Python object has no referrers but still accessible via a weakref?
1,127,836
<p>Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?</p> <p>If so how would I start trying to identify the cause for this object not being garbage collected?</p> <p>Edit: I'm not sure exactly how a code sample would help...
3
2009-07-14T20:29:34Z
1,128,216
<p>It might also be the case that a reference was leaked by a buggy C extension, IMHO you will not see the referer, yet still the refcount does not go down to 0. You might want to check the return value of <code>sys.getrefcount</code>. </p>
1
2009-07-14T21:37:41Z
[ "python", "garbage-collection", "cpython" ]
Python object has no referrers but still accessible via a weakref?
1,127,836
<p>Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?</p> <p>If so how would I start trying to identify the cause for this object not being garbage collected?</p> <p>Edit: I'm not sure exactly how a code sample would help...
3
2009-07-14T20:29:34Z
4,093,658
<p>I am glad you have found your problem, unrelated to the initial question. Nonetheless, I have a different take on the answer for posterity, in case others have the problem.</p> <p>It IS legal for the object to have no referrers and yet not be garbage collected.</p> <p>From the Python 2.7 manual: "An implementation...
1
2010-11-04T03:26:36Z
[ "python", "garbage-collection", "cpython" ]
wxPython, how do I fire events?
1,128,074
<p>I am making my own button class, subclass of a panel where I draw with a DC, and I need to fire wx.EVT_BUTTON when my custom button is pressed. How do I do it?</p>
2
2009-07-14T21:12:58Z
1,128,120
<p>Create a wx.CommandEvent object, call its setters to set the appropriate attributes, and pass it to wx.PostEvent.</p> <p><a href="http://docs.wxwidgets.org/stable/wx%5Fwxcommandevent.html#wxcommandeventctor">http://docs.wxwidgets.org/stable/wx_wxcommandevent.html#wxcommandeventctor</a></p> <p><a href="http://docs....
6
2009-07-14T21:20:39Z
[ "python", "events", "wxpython" ]
wxPython, how do I fire events?
1,128,074
<p>I am making my own button class, subclass of a panel where I draw with a DC, and I need to fire wx.EVT_BUTTON when my custom button is pressed. How do I do it?</p>
2
2009-07-14T21:12:58Z
1,128,992
<p>The Wiki is pretty nice for reference. Andrea Gavana has a pretty complete recipe for building your own <a href="http://wiki.wxpython.org/CreatingCustomControls">custom controls</a>. The following is taken directly from there and extends what <a href="http://stackoverflow.com/questions/1128074/wxpython-how-do-i-fi...
9
2009-07-15T01:48:20Z
[ "python", "events", "wxpython" ]
How can I obtain the full AST in Python?
1,128,234
<p>I like the options offered by the <b>_ast</b> module, it's really powerful. Is there a way of getting the full AST from it? </p> <p>For example, if I get the AST of the following code :</p> <pre><code> import os os.listdir(".") </code></pre> <p>by using :</p> <pre><code> ast = compile(source_string,"&lt;string&g...
4
2009-07-14T21:43:02Z
1,128,260
<pre><code>py&gt; ast._fields ('body',) py&gt; ast.body [&lt;_ast.Import object at 0xb7978e8c&gt;, &lt;_ast.Expr object at 0xb7978f0c&gt;] py&gt; ast.body[1] &lt;_ast.Expr object at 0xb7978f0c&gt; py&gt; ast.body[1]._fields ('value',) py&gt; ast.body[1].value &lt;_ast.Call object at 0xb7978f2c&gt; py&gt; ast.body[1].va...
5
2009-07-14T21:49:38Z
[ "python", "abstract-syntax-tree" ]
How can I obtain the full AST in Python?
1,128,234
<p>I like the options offered by the <b>_ast</b> module, it's really powerful. Is there a way of getting the full AST from it? </p> <p>For example, if I get the AST of the following code :</p> <pre><code> import os os.listdir(".") </code></pre> <p>by using :</p> <pre><code> ast = compile(source_string,"&lt;string&g...
4
2009-07-14T21:43:02Z
1,128,283
<p>You do get the whole tree this way -- all the way to the bottom -- but, it IS held as a tree, exactly... so at each level to get the children you have to explicitly visit the needed attributes. For example (i'm naming the <code>compile</code> result <code>cf</code> rather than <code>ast</code> because that would hid...
8
2009-07-14T21:55:19Z
[ "python", "abstract-syntax-tree" ]
To understand Typeset for PythonPath
1,128,366
<p>One recommends me the following code apparently only in .zshrc without explaining its purpose clearly.</p> <pre><code>typeset -U PYTHONPATH </code></pre> <p>I am interested in how you can use the code in .bashrc. My Bash goes upset about the command.</p> <p><strong>How can you use the command in Bash?</strong></p...
0
2009-07-14T22:16:22Z
1,128,392
<p>That zsh command is useful because <strong>zsh</strong> can treat the environment variable PYTHONPATH as an actual array of paths. The <code>-U</code> argument to <code>typeset</code> says, then when representing the array in the environment value passed to the program (Python, in this case), only include the first...
3
2009-07-14T22:25:06Z
[ "python", "bash", "path", "zsh", "typeset" ]
Need some help with python string / slicing operations
1,128,431
<p>This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends. But i did not find any article that explained how do it...
2
2009-07-14T22:31:09Z
1,128,447
<p>If you have spaces between your command, title, and definition you could:</p> <pre><code>wordList = myString.split() cmd = wordList[0] # !save title = wordList[1] # python definition = ' '.join(wordList[2:]) # Python is a high-level object oriented language created by Guido van Rossum. </code></pre> <p>If you rea...
2
2009-07-14T22:34:32Z
[ "python", "string", "slice" ]
Need some help with python string / slicing operations
1,128,431
<p>This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends. But i did not find any article that explained how do it...
2
2009-07-14T22:31:09Z
1,128,452
<p>Why is split overkill?</p> <pre><code>verb, title, definition = myString.split (' ', 2) </code></pre>
12
2009-07-14T22:35:41Z
[ "python", "string", "slice" ]
Need some help with python string / slicing operations
1,128,431
<p>This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends. But i did not find any article that explained how do it...
2
2009-07-14T22:31:09Z
1,128,781
<p>The selected answer (after PEP8ing):</p> <pre><code>verb, title, definition = my_string.split(' ', 2) </code></pre> <p>splits on a single space. It's likely a better choice to split on runs of whitespace, just in case there are tabs or multiple spaces on either side of the title:</p> <pre><code>verb, title, defin...
2
2009-07-15T00:26:02Z
[ "python", "string", "slice" ]
How Do I Use A Decimal Number In A Django URL Pattern?
1,128,693
<p>I'd like to use a number with a decimal point in a Django URL pattern but I'm not sure whether it's actually possible (I'm not a regex expert).</p> <p>Here's what I want to use for URLs:</p> <pre><code>/item/value/0.01 /item/value/0.05 </code></pre> <p>Those URLs would show items valued at $0.01 or $0.05. Sure, ...
5
2009-07-14T23:45:49Z
1,128,700
<p>I don't know about Django specifically, but this should match the URL:</p> <pre><code>r"^/item/value/(\d+\.\d+)$" </code></pre>
13
2009-07-14T23:49:23Z
[ "python", "regex", "django", "django-urls" ]
How Do I Use A Decimal Number In A Django URL Pattern?
1,128,693
<p>I'd like to use a number with a decimal point in a Django URL pattern but I'm not sure whether it's actually possible (I'm not a regex expert).</p> <p>Here's what I want to use for URLs:</p> <pre><code>/item/value/0.01 /item/value/0.05 </code></pre> <p>Those URLs would show items valued at $0.01 or $0.05. Sure, ...
5
2009-07-14T23:45:49Z
1,128,740
<p>It can be something like</p> <pre><code>urlpatterns = patterns('', (r'^item/value/(?P&lt;value&gt;\d+\.\d{2})/$', 'myapp.views.byvalue'), ... more urls ) </code></pre> <p>url should not start with slash.</p> <p>in views you can have function:</p> <pre><code>def byvalue(request,value='0.99'): try: ...
12
2009-07-15T00:08:58Z
[ "python", "regex", "django", "django-urls" ]
How Do I Use A Decimal Number In A Django URL Pattern?
1,128,693
<p>I'd like to use a number with a decimal point in a Django URL pattern but I'm not sure whether it's actually possible (I'm not a regex expert).</p> <p>Here's what I want to use for URLs:</p> <pre><code>/item/value/0.01 /item/value/0.05 </code></pre> <p>Those URLs would show items valued at $0.01 or $0.05. Sure, ...
5
2009-07-14T23:45:49Z
1,129,903
<p>If the values to be accepted are only $0.01 or $0.05, the harto's pattern may be specified like this:</p> <pre><code>r"^/item/value/(\d\.\d{2})$" </code></pre>
3
2009-07-15T07:25:44Z
[ "python", "regex", "django", "django-urls" ]
How to split two nested lists and combine the parts to create two new nested lists
1,128,924
<p>I'm trying to code a simple genetic programming utility in python. But right now I'm stuck at the crossover/mate function for my trees. The trees are built by nested lists and look something like this:</p> <pre><code># f = internal node (a function), c = leaf node (a constant) tree1 = [f, [f, [f, c, c], [f, c, c]],...
4
2009-07-15T01:21:50Z
1,128,963
<p>If you store in each internal node a count of the children in each branch, then you could pick a split point by generating a random number from 0 to 1+total children. If the answer is 1, split at that node, otherwise use the number to figure out which subtree to descend to, and repeat the process.</p>
0
2009-07-15T01:37:05Z
[ "python", "list", "genetic-programming" ]
How to split two nested lists and combine the parts to create two new nested lists
1,128,924
<p>I'm trying to code a simple genetic programming utility in python. But right now I'm stuck at the crossover/mate function for my trees. The trees are built by nested lists and look something like this:</p> <pre><code># f = internal node (a function), c = leaf node (a constant) tree1 = [f, [f, [f, c, c], [f, c, c]],...
4
2009-07-15T01:21:50Z
1,129,486
<p>I ended up implementing most of this as an exercise.</p> <p>First, find the number of possible locations to split: the number of non-function nodes.</p> <pre><code>def count(obj): total = 0 for o in obj[1:]: # Add the node itself. total += 1 if isinstance(o, list): tota...
2
2009-07-15T05:02:11Z
[ "python", "list", "genetic-programming" ]
Is it possible to encode (<em>asdf</em>) in python Textile?
1,128,951
<p>I'm using <a href="http://pypi.python.org/pypi/textile" rel="nofollow">python Textile</a> to store markup in the database. I would like to yield the following HTML snippet:</p> <pre><code>(&lt;em&gt;asdf&lt;/em&gt;) </code></pre> <p>The obvious doesn't get encoded:</p> <pre><code>(_asdf_) -&gt; &lt;p&gt;(_as...
0
2009-07-15T01:31:25Z
1,129,730
<p>It's hard to say if this is a bug or not; in the form on the <a href="http://textile.thresholdstate.com/" rel="nofollow">Textile website</a>, <code>(_foo_)</code> works as you want, but in the downloadable PHP implementation, it doesn't.</p> <p>You should be able to do this:</p> <pre><code>([_asdf_]) -&gt; &lt;p...
1
2009-07-15T06:31:42Z
[ "python", "markup", "textile" ]
How to Redirect To Same Page on Failed Login
1,129,091
<p>The Django framework easily handles redirecting when a user fails to log in properly. However, this redirection goes to a separate login page. I can set the template to be the same as the page I logged in on, but none of my other objects exist in the new page.</p> <p>For example, I have a front page that shows a bu...
2
2009-07-15T02:23:46Z
1,129,123
<p>Do you want to redirect to the referring page on failed login?</p> <pre><code>... authentication code above if user.is_authenticated(): #show success view else: return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse('index')) </code></pre> <p>you might want to check that referring page url i...
6
2009-07-15T02:33:46Z
[ "python", "django", "authentication", "redirect", "login" ]
How to Redirect To Same Page on Failed Login
1,129,091
<p>The Django framework easily handles redirecting when a user fails to log in properly. However, this redirection goes to a separate login page. I can set the template to be the same as the page I logged in on, but none of my other objects exist in the new page.</p> <p>For example, I have a front page that shows a bu...
2
2009-07-15T02:23:46Z
1,129,743
<p>This is because redirecting to a view misses the original context you use to render the page in the first place.</p> <p>You are missing just a simple logic here. You are trying to render the same template again, but with no news_article list. </p> <p>I suppose (in the first place), you are rendering the template w...
0
2009-07-15T06:34:29Z
[ "python", "django", "authentication", "redirect", "login" ]
How to Redirect To Same Page on Failed Login
1,129,091
<p>The Django framework easily handles redirecting when a user fails to log in properly. However, this redirection goes to a separate login page. I can set the template to be the same as the page I logged in on, but none of my other objects exist in the new page.</p> <p>For example, I have a front page that shows a bu...
2
2009-07-15T02:23:46Z
1,149,663
<ol> <li>Use an <code>&lt;IFRAME&gt;</code> in the sidebar to call the login view -- all postbacks will happen within the iframe, so your page stays intact. If the visitor logs in successfully, you can use javascript to redirect the parent page to some other URL</li> <li>Use <a href="http://malsup.com/jquery/form/" rel...
0
2009-07-19T11:04:35Z
[ "python", "django", "authentication", "redirect", "login" ]
How can I make setuptools ignore subversion inventory?
1,129,180
<p>When packaging a Python package with a setup.py that uses the setuptools:</p> <pre><code>from setuptools import setup ... </code></pre> <p>the source distribution created by:</p> <pre><code>python setup.py sdist </code></pre> <p>not only includes, as usual, the files specified in MANIFEST.in, but it also, gratui...
18
2009-07-15T03:00:19Z
1,129,848
<p>Probably the answer is in your setup.py. Do you use find_packages? This function by default uses the VCS (e.g. subversion, hg, ...). If you don't like it, just write a different Python function which collects only the things you want.</p>
1
2009-07-15T07:07:32Z
[ "python", "packaging", "setuptools", "egg" ]
How can I make setuptools ignore subversion inventory?
1,129,180
<p>When packaging a Python package with a setup.py that uses the setuptools:</p> <pre><code>from setuptools import setup ... </code></pre> <p>the source distribution created by:</p> <pre><code>python setup.py sdist </code></pre> <p>not only includes, as usual, the files specified in MANIFEST.in, but it also, gratui...
18
2009-07-15T03:00:19Z
1,129,874
<p>You probably want something like this:</p> <pre><code>from distutils.core import setup def packages(): import os packages = [] for path, dirs, files in os.walk("yourprogram"): if ".svn" in dirs: dirs.remove(".svn") if "__init__.py" in files: packages.append(pa...
-1
2009-07-15T07:15:15Z
[ "python", "packaging", "setuptools", "egg" ]
How can I make setuptools ignore subversion inventory?
1,129,180
<p>When packaging a Python package with a setup.py that uses the setuptools:</p> <pre><code>from setuptools import setup ... </code></pre> <p>the source distribution created by:</p> <pre><code>python setup.py sdist </code></pre> <p>not only includes, as usual, the files specified in MANIFEST.in, but it also, gratui...
18
2009-07-15T03:00:19Z
1,130,598
<p>I know you know much of this, Brandon, but I'll try to give as a complete answer as I can (although I'm no setuptools gury) for the benefit of others.</p> <p>The problem here is that setuptools itself involves quite a lot of black magick, including using an entry point called setuptools.file_finders where you can a...
13
2009-07-15T10:27:16Z
[ "python", "packaging", "setuptools", "egg" ]
How can I make setuptools ignore subversion inventory?
1,129,180
<p>When packaging a Python package with a setup.py that uses the setuptools:</p> <pre><code>from setuptools import setup ... </code></pre> <p>the source distribution created by:</p> <pre><code>python setup.py sdist </code></pre> <p>not only includes, as usual, the files specified in MANIFEST.in, but it also, gratui...
18
2009-07-15T03:00:19Z
1,132,909
<p>I would argue that the default sdist behavior is correct. When you are building a <strong>source</strong> distribution, I would expect it to contain <strong>everything</strong> that is checked into Subversion. Of course it would be nice to be able to override it cleanly in special circumstances.</p> <p>Compare sdis...
0
2009-07-15T17:53:08Z
[ "python", "packaging", "setuptools", "egg" ]
How can I make setuptools ignore subversion inventory?
1,129,180
<p>When packaging a Python package with a setup.py that uses the setuptools:</p> <pre><code>from setuptools import setup ... </code></pre> <p>the source distribution created by:</p> <pre><code>python setup.py sdist </code></pre> <p>not only includes, as usual, the files specified in MANIFEST.in, but it also, gratui...
18
2009-07-15T03:00:19Z
1,959,924
<p>Create a MANIFEST.in file with:</p> <pre><code>recursive-exclude . # other MANIFEST.in commands go here # to explicitly include whatever files you want </code></pre> <p>See <a href="http://docs.python.org/distutils/commandref.html#sdist-cmd">http://docs.python.org/distutils/commandref.html#sdist-cmd</a> for the MA...
8
2009-12-24T22:24:50Z
[ "python", "packaging", "setuptools", "egg" ]
creating non-reloading dynamic webapps using Django
1,129,210
<p>As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. </p> <p>For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments...
0
2009-07-15T03:15:27Z
1,129,222
<p>You want to do that with out any client side code (javascript and ajax are just examples) and with out reloading your page (or at least part of it)?</p> <p>If that is your question, then the answer unfortunately is you can't. You need to either have client side code or reload your page.</p> <p>Think about it, once...
7
2009-07-15T03:20:55Z
[ "python", "ajax", "django" ]
creating non-reloading dynamic webapps using Django
1,129,210
<p>As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. </p> <p>For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments...
0
2009-07-15T03:15:27Z
1,129,349
<p>To do it right, ajax would be the way to go BUT in a limited sense you can achieve the same thing by using a <a href="http://www.w3schools.com/TAGS/tag%5Fiframe.asp" rel="nofollow">iframe</a>, iframe is like another page embedded inside main page, so instead of refreshing whole page you may just refresh the inner if...
1
2009-07-15T04:03:03Z
[ "python", "ajax", "django" ]
creating non-reloading dynamic webapps using Django
1,129,210
<p>As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. </p> <p>For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments...
0
2009-07-15T03:15:27Z
1,129,395
<p>Maybe a few iFrames and some Comet/long-polling? Have the comment submission in an iFrame (so the whole page doesn't reload), and then show the result in the long-polled iFrame...</p> <p>Having said that, it's a pretty bad design idea, and you probably don't want to be doing this. AJAX/JavaScript is pretty much the...
1
2009-07-15T04:17:31Z
[ "python", "ajax", "django" ]
creating non-reloading dynamic webapps using Django
1,129,210
<p>As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. </p> <p>For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments...
0
2009-07-15T03:15:27Z
1,129,685
<p>You definitely want to use AJAX. Which means the client will need to run some javascript code.</p> <p>If you don't want to learn javascript you can always try something like <a href="http://pyjs.org/" rel="nofollow">pyjamas</a>. You can check out an example of it's HttpRequest <a href="http://pyjs.org/book/output...
3
2009-07-15T06:16:58Z
[ "python", "ajax", "django" ]
how do i filter an itertools chain() result?
1,129,344
<p>in my views, if i import an itertools module:</p> <pre><code>from itertools import chain </code></pre> <p>and i chain some objects with it:</p> <pre><code>franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art') amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exa...
3
2009-07-15T04:00:25Z
1,129,381
<p>By this point in the code, you've already loaded up all of the objects into memory and into a list. Just sort the list like you would any old Python list.</p> <pre><code>&gt;&gt;&gt; import operator &gt;&gt;&gt; ourtags.sort(key=operator.attrgetter('date_added')) </code></pre>
4
2009-07-15T04:13:54Z
[ "python", "django", "django-views", "itertools" ]
how do i filter an itertools chain() result?
1,129,344
<p>in my views, if i import an itertools module:</p> <pre><code>from itertools import chain </code></pre> <p>and i chain some objects with it:</p> <pre><code>franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art') amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exa...
3
2009-07-15T04:00:25Z
1,129,387
<pre><code>import operator ourtags = sorted(ourtags, key=operator.attrgetter('date_added')) </code></pre>
10
2009-07-15T04:15:09Z
[ "python", "django", "django-views", "itertools" ]