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 |
|---|---|---|---|---|---|---|---|---|---|
Possible: Program executing Qt3 and Qt4 code? | 910,230 | <p>Maybe its a very dumb question but I hope you can give me some answers.</p>
<p>I have a commercial application which uses Qt3 for its GUI and an embedded Python interpreter (command line) for scripting. I want to write a custom plugin for this application which uses Qt4. The plugin is mainly a subclassed QMainWindo... | 3 | 2009-05-26T11:35:27Z | 910,452 | <p>See <a href="http://labs.trolltech.com/forums/topic/414" rel="nofollow">this thread</a> on a Trolltech forum.
(Well actually that's about Qt3 plugins in a Qt4 app but I suspect the answer is much the same). </p>
<p>Update: link now a dud, but the <a href="http://web.archive.org/web/20090112213159/http://labs.trollt... | 3 | 2009-05-26T12:36:00Z | [
"c++",
"python",
"windows",
"qt",
"boost"
] |
Possible: Program executing Qt3 and Qt4 code? | 910,230 | <p>Maybe its a very dumb question but I hope you can give me some answers.</p>
<p>I have a commercial application which uses Qt3 for its GUI and an embedded Python interpreter (command line) for scripting. I want to write a custom plugin for this application which uses Qt4. The plugin is mainly a subclassed QMainWindo... | 3 | 2009-05-26T11:35:27Z | 910,558 | <p>This might be possible by namespacing Qt. From <code>configure --help</code>;</p>
<pre><code>-qtnamespace <name> Wraps all Qt library code in 'namespace <name> {...}'.
</code></pre>
<p>Theoretically this should prevent the symbol clashes which is likely making your current approach fail.</p>
| 3 | 2009-05-26T13:02:07Z | [
"c++",
"python",
"windows",
"qt",
"boost"
] |
Django objects change model field | 910,287 | <p>This doesn't work:</p>
<pre><code>>>> pa = Person.objects.all()
>>> pa[2].nickname
u'arst'
>>> pa[2].nickname = 'something else'
>>> pa[2].save()
>>> pa[2].nickname
u'arst'
</code></pre>
<p>But it works if you take </p>
<pre><code> p = Person.objects.get(pk=2)
</co... | 2 | 2009-05-26T11:44:43Z | 910,330 | <p>If you assigned your <code>pa[2]</code> to a variable, like you do with <code>Person.objects.get(pk=2)</code> you'd have it right:</p>
<pre><code>pa = Person.objects.all()
print pa[2].nickname
'Jonny'
pa[2].nickname = 'Billy'
print pa[2].nickname
'Jonny'
# when you assign it to some variable, your operations
# ch... | 3 | 2009-05-26T11:58:37Z | [
"python",
"django",
"django-models"
] |
Django objects change model field | 910,287 | <p>This doesn't work:</p>
<pre><code>>>> pa = Person.objects.all()
>>> pa[2].nickname
u'arst'
>>> pa[2].nickname = 'something else'
>>> pa[2].save()
>>> pa[2].nickname
u'arst'
</code></pre>
<p>But it works if you take </p>
<pre><code> p = Person.objects.get(pk=2)
</co... | 2 | 2009-05-26T11:44:43Z | 911,863 | <pre><code>>>> type(Person.objects.all())
<class 'django.db.models.query.QuerySet'>
>>> pa = Person.objects.all() # Not evaluated yet - lazy
>>> type(pa)
<class 'django.db.models.query.QuerySet'>
</code></pre>
<p>DB queried to give you a Person object</p>
<pre><code>>>>... | 10 | 2009-05-26T17:41:35Z | [
"python",
"django",
"django-models"
] |
Django objects change model field | 910,287 | <p>This doesn't work:</p>
<pre><code>>>> pa = Person.objects.all()
>>> pa[2].nickname
u'arst'
>>> pa[2].nickname = 'something else'
>>> pa[2].save()
>>> pa[2].nickname
u'arst'
</code></pre>
<p>But it works if you take </p>
<pre><code> p = Person.objects.get(pk=2)
</co... | 2 | 2009-05-26T11:44:43Z | 911,971 | <p><code>Person.objects.all()</code> returns a <code>QuerySet</code>, which is lazy (doesn't perform a DB query until data is requested from it). Slicing a <code>QuerySet</code> (pa[2]) performs a database query to get a single row from the database (using LIMIT and OFFSET in SQL). Slicing the same <code>QuerySet</co... | 2 | 2009-05-26T18:13:04Z | [
"python",
"django",
"django-models"
] |
A reliable way to determine if ntfs permissions were inherited | 910,696 | <p>I have a somewhat obscure question here.</p>
<p>What I need: To determine if the permissions (or, strictly speaking, a specific ACE of a DACL) of a file/folder was inherited.</p>
<p>How I tried to solve this: using winapi bindings for python (win32security module, to be precise). Here is the stripped down version... | 5 | 2009-05-26T13:31:29Z | 1,036,160 | <p>You can use the .Net framework </p>
<pre><code>System.Security.AccessControl
</code></pre>
<p>This covers ACL and DACL and SACL.</p>
| 1 | 2009-06-24T02:32:39Z | [
"python",
"winapi",
"acl",
"ntfs",
"file-permissions"
] |
A reliable way to determine if ntfs permissions were inherited | 910,696 | <p>I have a somewhat obscure question here.</p>
<p>What I need: To determine if the permissions (or, strictly speaking, a specific ACE of a DACL) of a file/folder was inherited.</p>
<p>How I tried to solve this: using winapi bindings for python (win32security module, to be precise). Here is the stripped down version... | 5 | 2009-05-26T13:31:29Z | 1,040,954 | <p>On my Win XP Home Edition this code doesn't seem to work at all :-)</p>
<p>I get this stack trace:</p>
<blockquote>
<p>Traceback (most recent call last):<br />
File "C:\1.py", line 37, in
main(sys.argv[1:])<br />
File "C:\1.py", line 29, in main
for ace_index in range(dacl.GetAceCount()):</p>
... | 0 | 2009-06-24T20:58:07Z | [
"python",
"winapi",
"acl",
"ntfs",
"file-permissions"
] |
A reliable way to determine if ntfs permissions were inherited | 910,696 | <p>I have a somewhat obscure question here.</p>
<p>What I need: To determine if the permissions (or, strictly speaking, a specific ACE of a DACL) of a file/folder was inherited.</p>
<p>How I tried to solve this: using winapi bindings for python (win32security module, to be precise). Here is the stripped down version... | 5 | 2009-05-26T13:31:29Z | 2,213,129 | <p>I think the original poster is seeing behavior detailed in</p>
<p><a href="http://groups.google.co.uk/group/microsoft.public.platformsdk.security/browse_thread/thread/5204736623c71a84/" rel="nofollow">This newsgroup posting</a></p>
<p>Note that the control flags set on the container can change simply by un-ticking... | 0 | 2010-02-06T12:50:53Z | [
"python",
"winapi",
"acl",
"ntfs",
"file-permissions"
] |
Send an xmpp message using a python library | 910,737 | <p>How can I send an XMPP message using one of the following Python libraries: wokkel, xmpppy, or jabber.py ?</p>
<p>I think I am aware of the pseudo-code, but so far have not been able to get one running correctly. This is what I have tried so far:</p>
<ul>
<li>Call some API and pass the servername and port number ... | 11 | 2009-05-26T13:39:08Z | 912,629 | <p>This is the simplest possible xmpp client. It will send a 'hello :)' message. I'm using <a href="https://pypi.python.org/pypi/xmpppy" rel="nofollow"><code>xmpppy</code></a> in the example. And connecting to gtalk server. I think the example is self-explanatory:</p>
<pre><code>import xmpp
username = 'username'
pass... | 38 | 2009-05-26T20:36:32Z | [
"python",
"xmpp"
] |
Send an xmpp message using a python library | 910,737 | <p>How can I send an XMPP message using one of the following Python libraries: wokkel, xmpppy, or jabber.py ?</p>
<p>I think I am aware of the pseudo-code, but so far have not been able to get one running correctly. This is what I have tried so far:</p>
<ul>
<li>Call some API and pass the servername and port number ... | 11 | 2009-05-26T13:39:08Z | 1,083,324 | <p><a href="http://xmpppy.sourceforge.net/" rel="nofollow">xmpppy</a> has a number of examples listed on its main page (under "examples"), the most basic of which <a href="http://xmpppy.sourceforge.net/examples/README.py" rel="nofollow">sends a single test message</a>. They make the examples progressively more interest... | 2 | 2009-07-05T01:46:45Z | [
"python",
"xmpp"
] |
How to show characters non ascii in python? | 910,809 | <p>I'm using the Python Shell in this way:</p>
<pre><code>>>> s = 'Ã'
>>> s
'\xc3'
</code></pre>
<p>How can I print s variable to show the character Ã??? This is the first and easiest question. Really, I'm getting the content from a web page that has non ascii characters like the previous and othe... | 0 | 2009-05-26T13:53:18Z | 910,880 | <p><strong>How can I print s variable to show the character Ã???</strong><br>
use <code>print</code>:</p>
<pre><code>>>> s = 'Ã'
>>> s
'\xc3'
>>> print s
Ã
</code></pre>
| 2 | 2009-05-26T14:06:47Z | [
"python",
"urllib2"
] |
How to show characters non ascii in python? | 910,809 | <p>I'm using the Python Shell in this way:</p>
<pre><code>>>> s = 'Ã'
>>> s
'\xc3'
</code></pre>
<p>How can I print s variable to show the character Ã??? This is the first and easiest question. Really, I'm getting the content from a web page that has non ascii characters like the previous and othe... | 0 | 2009-05-26T13:53:18Z | 910,886 | <p>I would use <code>ord()</code> to find out if a character is ASCII/special:</p>
<pre><code>if ord(c) > 127:
# special character
</code></pre>
<p>This probably won't work with multibyte encodings such as UTF-8. In this case, I would convert to Unicode before testing.</p>
<p>If you get special characters fro... | 1 | 2009-05-26T14:07:17Z | [
"python",
"urllib2"
] |
How to show characters non ascii in python? | 910,809 | <p>I'm using the Python Shell in this way:</p>
<pre><code>>>> s = 'Ã'
>>> s
'\xc3'
</code></pre>
<p>How can I print s variable to show the character Ã??? This is the first and easiest question. Really, I'm getting the content from a web page that has non ascii characters like the previous and othe... | 0 | 2009-05-26T13:53:18Z | 911,365 | <p>Suppose you want to print it as utf-8. Before python 3, the best is to specifically encode it</p>
<pre><code>print u'Ã'.encode('utf-8')
</code></pre>
<p>if you get the text externally then you have to specifically decode('utf-8) such as</p>
<pre><code>f = open(my_file)
a = f.next().decode('utf-8') # you have a u... | 2 | 2009-05-26T15:41:53Z | [
"python",
"urllib2"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 910,954 | <p>Well ... If you expect to really <em>fill</em> that space, then you're probably best off with a densely packed matrix-like structure, basically <a href="http://en.wikipedia.org/wiki/Voxel" rel="nofollow">voxels</a>.</p>
<p>If you don't expect to fill it, look into something a bit more optimized. I would start by lo... | 3 | 2009-05-26T14:20:43Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 910,981 | <p>It depends upon the precise configuration of your system, but from the example you give you are using integers and discrete points, so it would probably be appropriate to consider <a href="http://en.wikipedia.org/wiki/Sparse%5Fmatrix" rel="nofollow">Sparse Matrix</a> data structures. </p>
| -1 | 2009-05-26T14:27:14Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,057 | <p>You can do the first 2 queries with slicing in numpy :</p>
<pre><code>a = numpy.zeros((4, 4, 4))
a[1, 2, 3] # The point at x=1,y=2,z=3
a[:, 2, :] # All points where y=2
</code></pre>
<p>For the third one if you mean "getting all points within a sphere of radius 3 and centered at x=1,y=2,z=3", you will have to writ... | 0 | 2009-05-26T14:40:16Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,111 | <p>One advantage of numpy is that it is blazingly fast,
e.g. calculating the pagerank of a 8000x8000 adjacency matrix takes milliseconds. Even though <code>numpy.ndarray</code> will only accept numbers, you can store number/id-object mappings in an external hash-table i.e. dictionary (which in again is a highly optimi... | 1 | 2009-05-26T14:50:21Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,115 | <p>Here's an approach that may work.</p>
<p>Each point is a 4-tuple (x,y,z,data), and your database looks like this:</p>
<pre><code>database = [ (x,y,z,data), (x,y,z,data), ... ]
</code></pre>
<p>Let's look at your use cases.</p>
<p>Get the point where x=1,y=2,z=3.</p>
<pre><code>[ (x,y,z,data) for x,y,z,data in d... | 0 | 2009-05-26T14:51:03Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,318 | <p>Here's another common approach</p>
<pre><code>class Point( object ):
def __init__( self, x, y, z, data ):
self.x, self.y, self.z = x, y, z
self.data = data
def distFrom( self, x, y, z )
return math.sqrt( (self.x-x)**2 + (self.y-y)**2 + (self.z-z)**2 )
database = [ Point(x,y,z,data),... | 3 | 2009-05-26T15:30:30Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,444 | <p><a href="http://stackoverflow.com/questions/99796/when-to-use-binary-space-partitioning-quadtree-octree">When to use Binary Space Partitioning, Quadtree, Octree?</a></p>
<p>3d array imo is worthless. Especially if your world is dynamic. You should decide between BSP, Quadtree or Octtree. BSP would do just fine. Sin... | 0 | 2009-05-26T15:59:24Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Storing information on points in a 3d space | 910,930 | <p>I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like:</p>
<ul>
<li>Get the point where x=1,y=2,z=3.</li>
<li>Getting all points where y... | 4 | 2009-05-26T14:17:04Z | 911,746 | <p>Using a dictionary with x,y,z tuples as keys is another solution, if you want a relatively simple solution with the standard library.</p>
<pre><code>import math
#use indexing to get point at (1,2,3): points[(1,2,3)]
get_points(points, x=None, y=None, x=None):
"""returns dict of all points with given x,y and/or... | 0 | 2009-05-26T17:06:27Z | [
"python",
"data-structures",
"3d",
"matrix",
"numpy"
] |
Django/Python EnvironmentError? | 911,085 | <p>I am getting an error when I try to use <code>syncdb</code>:</p>
<pre><code>python manage.py syncdb
</code></pre>
<p>Error message:</p>
<pre><code>File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 83, in __init__
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path?... | 2 | 2009-05-26T14:45:21Z | 911,121 | <p>Make sure your settings.py file is in the same directory as manage.py (you will also have to run manage.py from this directory, i.e. ./manage.py syncdb), or make the environment variable DJANGO_SETTINGS_MODULE point to it.</p>
| 1 | 2009-05-26T14:52:23Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python EnvironmentError? | 911,085 | <p>I am getting an error when I try to use <code>syncdb</code>:</p>
<pre><code>python manage.py syncdb
</code></pre>
<p>Error message:</p>
<pre><code>File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 83, in __init__
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path?... | 2 | 2009-05-26T14:45:21Z | 911,176 | <p>Your trace states:</p>
<pre><code>Import by filename is not supported.
</code></pre>
<p>Which might indicate that you try to import (or maybe set the DJANGO_SETTINGS_MODULE) to the full python filename, where it should be a module path: <code>your.module.settings</code></p>
<p>You could also try to specify your D... | 12 | 2009-05-26T15:04:41Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python EnvironmentError? | 911,085 | <p>I am getting an error when I try to use <code>syncdb</code>:</p>
<pre><code>python manage.py syncdb
</code></pre>
<p>Error message:</p>
<pre><code>File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 83, in __init__
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path?... | 2 | 2009-05-26T14:45:21Z | 983,548 | <p>Another thing that gives this error is permissions - very hard to track down.</p>
<p>Solution for me was to move <code><myproject></code> to /var/www/<code><myproject></code>
and do chown -R root:root /var/www/<code><myproject></code></p>
| 1 | 2009-06-11T20:44:36Z | [
"python",
"django",
"django-syncdb"
] |
python monitoring over serial port | 911,089 | <p>Good afternoon,</p>
<p>I would ask some suggestion about the best way to monitor events over the serial port.</p>
<p>I'm using PySerial to write "commands" over the serial port towards some devices and</p>
<p>I would like to receive feedback about the status of this devices.</p>
<p>Wich is the best way: 1) fullf... | 2 | 2009-05-26T14:46:20Z | 911,772 | <p>For general tips on working with pyserial, look at the search S.Lott suggested in the comment.</p>
<p>Regarding the best strategy to implement your application - it all depends on how your protocols are defined. Do the devices immediately respond to queries? Or do they continually send data that must be monitored? ... | 3 | 2009-05-26T17:13:46Z | [
"python",
"pyserial"
] |
python monitoring over serial port | 911,089 | <p>Good afternoon,</p>
<p>I would ask some suggestion about the best way to monitor events over the serial port.</p>
<p>I'm using PySerial to write "commands" over the serial port towards some devices and</p>
<p>I would like to receive feedback about the status of this devices.</p>
<p>Wich is the best way: 1) fullf... | 2 | 2009-05-26T14:46:20Z | 919,620 | <p>The strategy choosen is to use python multiprocessing and queue
see:</p>
<ol>
<li><p><a href="http://www.ibm.com/developerworks/aix/library/au-threadingpython/index.html" rel="nofollow">http://www.ibm.com/developerworks/aix/library/au-threadingpython/index.html</a>
and</p></li>
<li><p><a href="http://www.ibm.com/de... | 1 | 2009-05-28T07:32:21Z | [
"python",
"pyserial"
] |
Python and Qt (PyQt) - calling method before resize event | 911,167 | <p>i have a question. There is application class in my program. It is inherited from QtGui.QMainWindow. In <strong>ini</strong> I call my own method which works with graphic. And it should be called before resize event. How can i do that?
Thanks.</p>
<p>EDIT: As you can se <a href="http://doc.trolltech.com/4.2/qevent.... | 1 | 2009-05-26T15:03:22Z | 911,392 | <p>You could override in your class the <code>resizeEvent</code> method (which <code>QMainWindows</code> inherits from <code>QWidget</code>), see <a href="http://doc.trolltech.com/4.4/qwidget.html#resizeEvent" rel="nofollow">http://doc.trolltech.com/4.4/qwidget.html#resizeEvent</a> -- in your override, call your other ... | 1 | 2009-05-26T15:47:47Z | [
"python",
"constructor",
"pyqt"
] |
Django/Python UserWarning Error | 911,273 | <p>I keep getting this error/warning, which is annoying, and wanted to see if I can fix it, but I'm not sure where to start (I'm a newbie):</p>
<pre><code>/home/simi/workspace/hssn_svn/hssn/../hssn/log/loggers.py:28: UserWarning: ERROR: Could not configure logging
warnings.warn('ERROR: Could not configure logging', ... | 0 | 2009-05-26T15:22:09Z | 911,596 | <p>Do you have write permissions to all the files within the application you are working with. Also make sure you have everything in settings.py setup correctly, make sure specified paths exist and you have permissions.</p>
| 1 | 2009-05-26T16:33:10Z | [
"python",
"django"
] |
Python: Inheriting from Built-In Types | 911,375 | <p>I have a question concerning subtypes of built-in types and their constructors. I want a class to inherit both from tuple and from a custom class.</p>
<p>Let me give you the concrete example. I work a lot with graphs, meaning nodes connected with edges. I am starting to do some work on my own graph framework.</p>
... | 2 | 2009-05-26T15:43:52Z | 911,413 | <p>Since tuples are immutable, you need to override the __new__ method as well. See <a href="http://www.python.org/download/releases/2.2.3/descrintro/" rel="nofollow">http://www.python.org/download/releases/2.2.3/descrintro/</a>#__new__</p>
<pre><code>class GraphElement:
def __init__(self, graph):
pass
cl... | 9 | 2009-05-26T15:53:07Z | [
"python",
"oop",
"graph"
] |
Python: Inheriting from Built-In Types | 911,375 | <p>I have a question concerning subtypes of built-in types and their constructors. I want a class to inherit both from tuple and from a custom class.</p>
<p>Let me give you the concrete example. I work a lot with graphs, meaning nodes connected with edges. I am starting to do some work on my own graph framework.</p>
... | 2 | 2009-05-26T15:43:52Z | 911,415 | <p>You need to override <code>__new__</code> -- currently <code>tuple.__new__</code> is getting called (as you don't override it) with all the arguments you're passing to <code>Edge</code>.</p>
| 3 | 2009-05-26T15:53:59Z | [
"python",
"oop",
"graph"
] |
Python: Inheriting from Built-In Types | 911,375 | <p>I have a question concerning subtypes of built-in types and their constructors. I want a class to inherit both from tuple and from a custom class.</p>
<p>Let me give you the concrete example. I work a lot with graphs, meaning nodes connected with edges. I am starting to do some work on my own graph framework.</p>
... | 2 | 2009-05-26T15:43:52Z | 911,452 | <p>For what you need, I would avoid multiple inheritance and would implement an iterator using generator:</p>
<pre><code>class GraphElement:
def __init__(self, graph):
pass
class Edge(GraphElement):
def __init__(self, graph, (source, target)):
GraphElement.__init__(self, graph)
self.so... | 6 | 2009-05-26T16:00:22Z | [
"python",
"oop",
"graph"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 911,754 | <p><code>matplotlib</code> has pretty good documentation, and seems to be quite stable. The plots it produces are beautiful - "publication quality" for sure. Due to the good documentation and the amount of example code available online, it's easy to learn and use, and I don't think you'll have much trouble translating ... | 16 | 2009-05-26T17:09:47Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 911,765 | <ul>
<li>you can check the <a href="http://matplotlib.sourceforge.net/contents.html">documentation</a> yourself. I find it quite comprehensive.</li>
<li>I have very little experience with gnuplot-py, so I can not say.</li>
<li>Matplotlib is written in and designed specifically for Python, so it fits very nicely with P... | 36 | 2009-05-26T17:12:05Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 911,779 | <p>I have played with both, and I like Matplotlib much better in terms of Python integration, options, and quality of graphs/plots.</p>
| 7 | 2009-05-26T17:15:51Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 1,960,904 | <p>After using GNUplot (with my own Python wrapper) for a long time (and really not liking the 80s-looking output), I just started having a look at matplotlib. I must say I like it very much, the output looks really nice and the docs are high quality and extensive (although that also goes for GNUplot). The one thing I ... | 12 | 2009-12-25T10:01:31Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 15,175,597 | <p>What Gnuplot can do Gnuplot-Py can do too. Because Gnuplot can be driven by pipe(pgnuplot).
Gnuplot-Py is just a thin layer for it. So you don't need worry about it.</p>
<p>Why I prefer gnuplot maybe the many output format(PDF, PS and LaTex), which is very useful in papers, and the default output looks more scienti... | 3 | 2013-03-02T14:29:39Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 23,883,352 | <h2>Matplotlib = ease of use, Gnuplot = performance</h2>
<p>I know this post is old and answered but I was passing by and wanted to put my two cents. Here is my conclusion: as said above, if you have a not-so-big data set, you should use Matplotlib. It's easier and looks better. However, if you need performance, I wou... | 17 | 2014-05-27T07:21:57Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
gnuplot vs Matplotlib | 911,655 | <p>I've started on a project graphing <a href="http://en.wikipedia.org/wiki/Apache_Tomcat">Tomcat</a> logs using <a href="http://gnuplot-py.sourceforge.net/">gnuplot-py</a>, specifically correlating particular requests with memory allocation and garbage collection. What is the
collective wisdom on gnuplot-py vs <a hre... | 57 | 2009-05-26T16:49:02Z | 27,881,374 | <p>About performance and plotting a great number of points: I compared this for a scatterplot of 500.000 points loaded from a text file and saved to a png, using gnuplot* and matplotlib.</p>
<pre><code>500.000 points scatterplot
gnuplot: 5.171 s
matplotlib: 230.693 s
</code></pre>
<p>I ran it only once and the r... | 3 | 2015-01-10T21:26:25Z | [
"python",
"logging",
"matplotlib",
"gnuplot",
"graphing"
] |
Extracting titles from PDF files? | 911,672 | <p>I want to write a script to rename downloaded papers with their titles automatically, I'm wondering if there is any library or tricks i can make use of? The PDFs are all generated by TeX and should have some 'formal' structures.</p>
| 9 | 2009-05-26T16:52:40Z | 911,707 | <p>I would probably start with perl (seeing as it's always the first thing I reach for). There are <a href="http://search.cpan.org/search?mode=module&query=PDF" rel="nofollow">several modules for handling PDFs</a>. If you have a consistent structure, you could use regex to snag the titles.</p>
| 1 | 2009-05-26T16:58:14Z | [
"python",
"pdf"
] |
Extracting titles from PDF files? | 911,672 | <p>I want to write a script to rename downloaded papers with their titles automatically, I'm wondering if there is any library or tricks i can make use of? The PDFs are all generated by TeX and should have some 'formal' structures.</p>
| 9 | 2009-05-26T16:52:40Z | 911,708 | <p>You could try to use <a href="http://pybrary.net/pyPdf/" rel="nofollow">pyPdf</a> and <a href="http://blog.isnotworking.com/2006/08/extract-pdf-title-from-all-files-on.html" rel="nofollow">this example</a>.</p>
<p><strong>for example:</strong></p>
<pre><code>from pyPdf import PdfFileWriter, PdfFileReader
def get_... | 11 | 2009-05-26T16:58:14Z | [
"python",
"pdf"
] |
Extracting titles from PDF files? | 911,672 | <p>I want to write a script to rename downloaded papers with their titles automatically, I'm wondering if there is any library or tricks i can make use of? The PDFs are all generated by TeX and should have some 'formal' structures.</p>
| 9 | 2009-05-26T16:52:40Z | 911,719 | <p>You can try using <a href="http://www.lowagie.com/iText/" rel="nofollow">iText</a> with <a href="http://www.jython.org/Project/" rel="nofollow">Jython</a></p>
| 1 | 2009-05-26T17:00:36Z | [
"python",
"pdf"
] |
detecting idle time using python | 911,856 | <p>How do I detect if the system is idle on Windows using Python (i.e. no keyboard or mouse activity).
This has already been asked <a href="http://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-maco">before</a>, but there doesn't seem to be a <code>GetLastI... | 14 | 2009-05-26T17:39:35Z | 911,982 | <p>Actually, you can access <code>GetLastInputInfo</code> via the <code>cytpes</code> library:</p>
<pre><code>import ctypes
GetLastInputInfo = ctypes.windll.User32.GetLastInputInfo # callable function pointer
</code></pre>
<p>This might not be what you want though, as it does not provide idle information across the ... | 2 | 2009-05-26T18:15:37Z | [
"python",
"winapi"
] |
detecting idle time using python | 911,856 | <p>How do I detect if the system is idle on Windows using Python (i.e. no keyboard or mouse activity).
This has already been asked <a href="http://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-maco">before</a>, but there doesn't seem to be a <code>GetLastI... | 14 | 2009-05-26T17:39:35Z | 912,223 | <pre><code>from ctypes import Structure, windll, c_uint, sizeof, byref
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
windll.user32.GetLastI... | 16 | 2009-05-26T19:17:19Z | [
"python",
"winapi"
] |
detecting idle time using python | 911,856 | <p>How do I detect if the system is idle on Windows using Python (i.e. no keyboard or mouse activity).
This has already been asked <a href="http://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-maco">before</a>, but there doesn't seem to be a <code>GetLastI... | 14 | 2009-05-26T17:39:35Z | 3,483,654 | <p>Seems like <code>GetLastInputInfo</code> is now available in pywin32:</p>
<pre><code>win32api.GetLastInputInfo()
</code></pre>
<p>does the trick and returns the timer tick from the last user input action. </p>
<p>Here with an example program</p>
<pre><code>import time
import win32api
for i in range(10):
print... | 4 | 2010-08-14T14:06:35Z | [
"python",
"winapi"
] |
detecting idle time using python | 911,856 | <p>How do I detect if the system is idle on Windows using Python (i.e. no keyboard or mouse activity).
This has already been asked <a href="http://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-maco">before</a>, but there doesn't seem to be a <code>GetLastI... | 14 | 2009-05-26T17:39:35Z | 29,730,972 | <p>@FogleBird's answer is pretty cool and working, but in a hurry i wasn't sure how it works, so a little test example here. A thread is starting, looking for last idle time every 10 seconds. If any movement is made within this time window, it will be printed out.</p>
<pre><code>from ctypes import Structure, windll, c... | 0 | 2015-04-19T14:10:47Z | [
"python",
"winapi"
] |
detecting idle time using python | 911,856 | <p>How do I detect if the system is idle on Windows using Python (i.e. no keyboard or mouse activity).
This has already been asked <a href="http://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-maco">before</a>, but there doesn't seem to be a <code>GetLastI... | 14 | 2009-05-26T17:39:35Z | 33,765,403 | <pre><code>import win32api
def getIdleTime():
return (win32api.GetTickCount() - win32api.GetLastInputInfo()) / 1000.0
</code></pre>
| 1 | 2015-11-17T19:27:52Z | [
"python",
"winapi"
] |
Detect if a NumPy array contains at least one non-numeric value? | 911,871 | <p>I need to write a function which will detect if the input contains at least one value which is non-numeric. If a non-numeric value is found I will raise an error (because the calculation should only return a numeric value). The number of dimensions of the input array is not known in advance - the function should giv... | 34 | 2009-05-26T17:43:47Z | 913,499 | <p>This should be faster than iterating and will work regardless of shape.</p>
<pre><code>numpy.isnan(myarray).any()
</code></pre>
<p>Edit: 30x faster:</p>
<pre><code>import timeit
s = 'import numpy;a = numpy.arange(10000.).reshape((100,100));a[10,10]=numpy.nan'
ms = [
'numpy.isnan(a).any()',
'any(numpy.isna... | 49 | 2009-05-27T00:55:50Z | [
"python",
"numpy"
] |
Detect if a NumPy array contains at least one non-numeric value? | 911,871 | <p>I need to write a function which will detect if the input contains at least one value which is non-numeric. If a non-numeric value is found I will raise an error (because the calculation should only return a numeric value). The number of dimensions of the input array is not known in advance - the function should giv... | 34 | 2009-05-26T17:43:47Z | 1,325,396 | <p>With numpy 1.3 or svn you can do this</p>
<pre><code>In [1]: a = arange(10000.).reshape(100,100)
In [3]: isnan(a.max())
Out[3]: False
In [4]: a[50,50] = nan
In [5]: isnan(a.max())
Out[5]: True
In [6]: timeit isnan(a.max())
10000 loops, best of 3: 66.3 µs per loop
</code></pre>
<p>The treatment of nans in comp... | 2 | 2009-08-25T00:04:43Z | [
"python",
"numpy"
] |
Detect if a NumPy array contains at least one non-numeric value? | 911,871 | <p>I need to write a function which will detect if the input contains at least one value which is non-numeric. If a non-numeric value is found I will raise an error (because the calculation should only return a numeric value). The number of dimensions of the input array is not known in advance - the function should giv... | 34 | 2009-05-26T17:43:47Z | 33,043,793 | <p>If infinity is a possible value, I would use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.isfinite.html#numpy.isfinite" rel="nofollow">numpy.isfinite</a></p>
<pre><code>numpy.isfinite(myarray).all()
</code></pre>
<p>If the above evaluates to <code>True</code>, then <code>myarray</code> contai... | 4 | 2015-10-09T17:13:34Z | [
"python",
"numpy"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 911,918 | <p>Honestly I'm not sure I understand your question. If you want a way to override getattribute and yet keep the original attributes you can use <a href="http://docs.python.org/library/stdtypes.html#object.%5F%5Fdict%5F%5F" rel="nofollow"><code>__dict__</code></a></p>
<pre><code>def __getattribute__(self, attr):
i... | 1 | 2009-05-26T17:58:47Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 911,943 | <p>Method invocation in Python is two step process, first a function is looked up, then it is invoked. For a more involved discussion see my answer to <a href="http://stackoverflow.com/questions/852308/how-the-method-resolution-and-invocation-works-internally-in-python/870650#870650">this question</a>.</p>
<p>So you w... | 3 | 2009-05-26T18:06:50Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 911,944 | <p><strong>__getattribute__</strong> simply returns the attribute that was requested, in case of a method, the <strong>__call__</strong> interface is then used to call it.</p>
<p>Instead of returning the method, return a wrapper around it, for instance:</p>
<pre><code>def __getattribute__(self, attr):
def make_i... | 4 | 2009-05-26T18:06:57Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 911,953 | <p>I don't think you can. <code>__getattribute__</code> doesn't intercept the method call, it only intercepts the method name lookup. So it should return a function (or callable object), which will then be called with whatever parameters specified at the call site.</p>
<p>In particular, if it returns a function which ... | 1 | 2009-05-26T18:08:57Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 912,110 | <p>Yes</p>
<pre><code>def argumentViewer(func):
def newfunc(*args, **kwargs):
print "Calling %r with %r %r" % (func, args, kwargs)
return func(*args, **kwargs)
return newfunc
class Foo(object):
def __getattribute__(self, name):
print "retrieving data"
return object.__getatt... | 0 | 2009-05-26T18:45:48Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 1,880,279 | <p>Here is a variation on Unknown's suggestion that returns a callable "wrapper" instance in place of the requested function. This does not require decorating any methods:</p>
<pre><code>class F(object):
def __init__(self, func):
self.func = func
return
def __call__(self, *args, **kw):
print "... | 0 | 2009-12-10T11:08:25Z | [
"python",
"python-datamodel"
] |
Is there a way to access the formal parameters if you implement __getattribute__ | 911,905 | <p>It seems as though <code>__getattribute__</code> has only 2 parameters <code>(self, name)</code>.</p>
<p>However, in the actual code, the method I am intercepting actually takes arguments.</p>
<p>Is there anyway to access those arguments?</p>
<p>Thanks,</p>
<p>Charlie</p>
| 2 | 2009-05-26T17:53:29Z | 17,655,819 | <p>Thanks to <a href="http://stackoverflow.com/users/62569/ask">ASk</a> <a href="http://stackoverflow.com/a/911944/1322849">answer</a> (big thank you mate) I managed to solve my problem, however I had to replace</p>
<pre><code> att = self.__dict__[attr]
</code></pre>
<p>with</p>
<pre><code>att = type(self).__dic... | 0 | 2013-07-15T13:47:37Z | [
"python",
"python-datamodel"
] |
Python Best Practices: Abstract Syntax Trees | 911,930 | <h2>Modifying Abstract Syntax Trees</h2>
<p>I would like to be able to build and modify an <code>ast</code> and then optionally write it out as python byte code for execution later without overhead.</p>
<p>I have been hacking around with the <a href="http://docs.python.org/dev/py3k/library/ast.html" rel="nofollow">as... | 8 | 2009-05-26T18:02:13Z | 912,140 | <p>Other than the manual and the source code, you are on your own. This subject and python bytecode are very undocumented.</p>
<p>Alternatively you could try using this python bytecode library which I have heard good thing about but haven't tried it yet:</p>
<p><a href="http://code.google.com/p/byteplay/" rel="nofoll... | 4 | 2009-05-26T18:55:35Z | [
"python",
"abstract-syntax-tree"
] |
Python Best Practices: Abstract Syntax Trees | 911,930 | <h2>Modifying Abstract Syntax Trees</h2>
<p>I would like to be able to build and modify an <code>ast</code> and then optionally write it out as python byte code for execution later without overhead.</p>
<p>I have been hacking around with the <a href="http://docs.python.org/dev/py3k/library/ast.html" rel="nofollow">as... | 8 | 2009-05-26T18:02:13Z | 916,597 | <p>I think geniusql is doing something along those lines to translate an ast into sql... There was a talk on it but I can't find it - and I'm not allowed to link anyway :-(</p>
| 2 | 2009-05-27T16:05:56Z | [
"python",
"abstract-syntax-tree"
] |
How to find all child modules in Python? | 912,025 | <p>While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import <em>all</em> child modules.</p>
<p>I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I... | 12 | 2009-05-26T18:25:15Z | 912,061 | <p>using <a href="http://docs.python.org/library/functions.html#dir" rel="nofollow">dir()</a> and <a href="http://docs.python.org/library/imp.html" rel="nofollow">imp module</a></p>
| 0 | 2009-05-26T18:34:05Z | [
"python",
"module",
"package",
"python-import"
] |
How to find all child modules in Python? | 912,025 | <p>While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import <em>all</em> child modules.</p>
<p>I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I... | 12 | 2009-05-26T18:25:15Z | 912,067 | <p>When I was a kind and just beginning programming in Python I've written this for my modular IRC bot:</p>
<pre><code>
# Load plugins
_plugins = []
def ifName(name):
try:
return re.match('([^_.].+)\.[^.]+', a).group(1)
except:
return None
def isValidPlugin(ob... | 1 | 2009-05-26T18:37:09Z | [
"python",
"module",
"package",
"python-import"
] |
How to find all child modules in Python? | 912,025 | <p>While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import <em>all</em> child modules.</p>
<p>I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I... | 12 | 2009-05-26T18:25:15Z | 912,094 | <p>You can try <code>glob</code>bing the directory:</p>
<pre><code>import os
import glob
modules = glob.glob(os.path.join('/some/path/to/modules', '*.py'))
</code></pre>
<p>Then you can try importing them:</p>
<pre><code>checked_modules
for module in modules:
try:
__import__(module, globals(), locals())... | -1 | 2009-05-26T18:41:25Z | [
"python",
"module",
"package",
"python-import"
] |
How to find all child modules in Python? | 912,025 | <p>While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import <em>all</em> child modules.</p>
<p>I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I... | 12 | 2009-05-26T18:25:15Z | 7,320,937 | <p>I think the best way to do this sort of plugin thing is using <a href="http://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins" rel="nofollow"><code>entry_points</code></a> and the <a href="http://pythonhosted.org/setuptools/pkg_resources.html#convenience-api" rel="nofollow">API ... | 2 | 2011-09-06T13:44:00Z | [
"python",
"module",
"package",
"python-import"
] |
How to find all child modules in Python? | 912,025 | <p>While it is fairly trivial in Python to import a "child" module into another module and list its attributes, it becomes slightly more difficult when you want to import <em>all</em> child modules.</p>
<p>I'm building a library of tools for an existing 3D application. Each tool has its own menu item and sub menus. I... | 12 | 2009-05-26T18:25:15Z | 7,338,242 | <p>The solution above traversing the filesystem for finding submodules is ok as long as you implement every plugin as a filesystem based module.</p>
<p>A more flexible way would be an explicit plugin list in your main module, and have every plugin (whether a module created by file, dynamically, or even instance of a c... | 1 | 2011-09-07T17:48:02Z | [
"python",
"module",
"package",
"python-import"
] |
Class attributes with a "calculated" name | 912,412 | <p>When defining class attributes through "calculated" names, as in:</p>
<pre><code>class C(object):
for name in (....):
exec("%s = ..." % (name,...))
</code></pre>
<p>is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work because C i... | 3 | 2009-05-26T19:57:28Z | 912,428 | <p>How about:</p>
<pre><code>class C(object):
blah blah
for name in (...):
setattr(C, name, "....")
</code></pre>
<p>That is, do the attribute setting after the definition.</p>
| 11 | 2009-05-26T20:03:41Z | [
"python",
"exec",
"class-attributes"
] |
Class attributes with a "calculated" name | 912,412 | <p>When defining class attributes through "calculated" names, as in:</p>
<pre><code>class C(object):
for name in (....):
exec("%s = ..." % (name,...))
</code></pre>
<p>is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work because C i... | 3 | 2009-05-26T19:57:28Z | 912,739 | <p>What about using metaclasses for this purpose?</p>
<p>Check out <a href="http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python">Question 100003 : What is a metaclass in Python?</a>.</p>
| 0 | 2009-05-26T20:59:58Z | [
"python",
"exec",
"class-attributes"
] |
Class attributes with a "calculated" name | 912,412 | <p>When defining class attributes through "calculated" names, as in:</p>
<pre><code>class C(object):
for name in (....):
exec("%s = ..." % (name,...))
</code></pre>
<p>is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work because C i... | 3 | 2009-05-26T19:57:28Z | 912,790 | <pre><code>class C (object):
pass
c = C()
c.__dict__['foo'] = 42
c.foo # returns 42
</code></pre>
| 3 | 2009-05-26T21:13:02Z | [
"python",
"exec",
"class-attributes"
] |
Class attributes with a "calculated" name | 912,412 | <p>When defining class attributes through "calculated" names, as in:</p>
<pre><code>class C(object):
for name in (....):
exec("%s = ..." % (name,...))
</code></pre>
<p>is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work because C i... | 3 | 2009-05-26T19:57:28Z | 914,245 | <p>If your entire class is "calculated", then may I suggest the <code>type</code> callable. This is especially useful if your original container was a dict:</p>
<pre><code>d = dict(('member-%d' % k, k*100) for k in range(10))
C = type('C', (), d)
</code></pre>
<p>This would give you the same results as</p>
<pre><cod... | 2 | 2009-05-27T06:28:22Z | [
"python",
"exec",
"class-attributes"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 912,558 | <p>The simplest thing to do would be to create a class. Instead of dealing with a list of variables, the class will have attributes. Then you just use a single instance of the class.</p>
| 15 | 2009-05-26T20:25:40Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 912,561 | <p>if you have a finite set of these cases, you could write specific wrapper functions for each one. Each wrapper would do the work of building and unpacking lists taht are passed to the internal function.</p>
| 0 | 2009-05-26T20:26:20Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 912,571 | <blockquote>
<p>If I could pass the variables by reference into the function, then users could change them or not, and I would use the values once the program returned from the function.</p>
</blockquote>
<p>You can obtain much the same effect as "pass by reference" by passing a <code>dict</code> (or for syntactic c... | 1 | 2009-05-26T20:27:47Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 912,578 | <p>There are two decent options that come to mind.</p>
<p>The first is to use a dictionary to gather all the variables in one place:</p>
<pre><code>d = {}
d['var1'] = [1,2,3]
d['var2'] = 'asdf'
foo(d)
</code></pre>
<p>The second is to use a class to bundle all the arguments. This could be something as simple as:</p>... | 9 | 2009-05-26T20:29:08Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 912,582 | <p>To me, the ideal solution is to use a class like this:</p>
<pre><code>>>> class Vars(object):
... def __init__(self, **argd):
... self.__dict__.update(argd)
...
>>> x = Vars(x=1, y=2)
>>> x.x
1
>>> x.y
2
</code></pre>
<p>You can also build a dictionary and pass i... | 2 | 2009-05-26T20:29:25Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
How do I pass lots of variables to and from a function in Python? | 912,526 | <p>I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of th... | 3 | 2009-05-26T20:20:05Z | 913,540 | <ol>
<li>I would recommend using a dictionary
or a class to accumulate all details
about your variables
<ul>
<li>value</li>
<li>prompt text</li>
</ul></li>
<li>A list to store the order in which you want them to be displayed</li>
<li>Then use good old iteration to prepare input and collect output</li>
</ol>
<p>This wa... | 0 | 2009-05-27T01:18:09Z | [
"python",
"pass-by-reference",
"pass-by-value"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 912,847 | <p>Just found <code>sys.executable</code> - the full path to the current Python executable, which can be used to run the script (instead of relying on the shbang, which obviously doesn't work on Windows)</p>
<pre><code>import sys
import subprocess
theproc = subprocess.Popen([sys.executable, "myscript.py"])
theproc.co... | 45 | 2009-05-26T21:26:10Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 912,851 | <p>When you are running a python script on windows in subprocess you should use python in front of the script name. Try:</p>
<pre><code>process = subprocess.Popen("python /the/script.py")
</code></pre>
| 1 | 2009-05-26T21:26:41Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 912,862 | <p>It looks like windows tries to run the script using its own EXE framework rather than call it like </p>
<pre><code>python /the/script.py
</code></pre>
<p>Try,</p>
<pre><code>subprocess.Popen(["python", "/the/script.py"])
</code></pre>
<p>Edit: "python" would need to be on your path.</p>
| 4 | 2009-05-26T21:29:03Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 914,522 | <p>You are using a pathname separator which is platform dependent. Windows uses "\" and Unix uses "/".</p>
| 2 | 2009-05-27T08:08:52Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 1,036,086 | <p>How about this:</p>
<pre><code>import sys
import subprocess
theproc = subprocess.Popen("myscript.py", shell = True)
theproc.communicate() # ^^^^^^^^^^^^
</code></pre>
<p>This tells <code>subprocess</code> to use the OS shell to open your script, and works on anything that you can just run in cmd... | 15 | 2009-06-24T01:48:17Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 6,329,130 | <p>Yes <code>subprocess.Popen(cmd, ..., shell=True)</code> works like a charm. On Windows the <code>.py</code> file extension is recognized, so Python is invoked to process it (on *NIX just the usual shebang). The path environment controls whether things are seen. So the first arg to <code>Popen</code> is <em>just t... | 5 | 2011-06-13T10:15:57Z | [
"python",
"windows",
"subprocess"
] |
Using subprocess to run Python script on Windows | 912,830 | <p>Is there a simple way to run a Python script on Windows/Linux/OS X?</p>
<p>On the latter two, <code>subprocess.Popen("/the/script.py")</code> works, but on Windows I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "test_functional.py", line 91, in test_functional
log = tvnamer... | 31 | 2009-05-26T21:22:12Z | 24,752,537 | <p>For example, to execute following with command prompt or BATCH file we can use this: </p>
<pre><code>C:\Python27\python.exe "C:\Program files(x86)\dev_appserver.py" --host 0.0.0.0 --post 8080 "C:\blabla\"
</code></pre>
<p>Same thing to do with Python, we can do this:</p>
<pre><code>subprocess.Popen(['C:/Python27/... | 1 | 2014-07-15T07:40:06Z | [
"python",
"windows",
"subprocess"
] |
Dynamic Finders and Method Missing in Python | 913,020 | <p>I'm trying to implement something like Rails dynamic-finders in Python (for
webapp/GAE). The dynamic finders work like this:</p>
<ul>
<li>Your Person has some fields: name, age and email.</li>
<li>Suppose you want to find all the users whose name is "Robot". </li>
</ul>
<p>The Person class has a method called "fin... | 5 | 2009-05-26T22:10:42Z | 913,109 | <pre><code>class Person(object):
def __getattr__(self, name):
if not name.startswith("find_by"): raise AttributeError(name)
field_name = name.split("find_by_",1)[1]
return lambda name: Person.gql("WHERE %s = :1" % field_name, name).get()
</code></pre>
| 0 | 2009-05-26T22:31:23Z | [
"python",
"google-app-engine",
"web-applications"
] |
Dynamic Finders and Method Missing in Python | 913,020 | <p>I'm trying to implement something like Rails dynamic-finders in Python (for
webapp/GAE). The dynamic finders work like this:</p>
<ul>
<li>Your Person has some fields: name, age and email.</li>
<li>Suppose you want to find all the users whose name is "Robot". </li>
</ul>
<p>The Person class has a method called "fin... | 5 | 2009-05-26T22:10:42Z | 913,145 | <p>You could use a 'find_by' method and keywords, like Django does:</p>
<pre><code>class Person (object):
def find_by(self, *kw):
qspec = ' AND '.join('%s=%s' % kv for kv in kw.items())
return self.gql('WHERE ' + qspec)
person.find_by(name='Robot')
person.find_by(name='Robot', age='2')
</code></pr... | 1 | 2009-05-26T22:40:52Z | [
"python",
"google-app-engine",
"web-applications"
] |
Dynamic Finders and Method Missing in Python | 913,020 | <p>I'm trying to implement something like Rails dynamic-finders in Python (for
webapp/GAE). The dynamic finders work like this:</p>
<ul>
<li>Your Person has some fields: name, age and email.</li>
<li>Suppose you want to find all the users whose name is "Robot". </li>
</ul>
<p>The Person class has a method called "fin... | 5 | 2009-05-26T22:10:42Z | 913,438 | <p>There's really no need to use GQL here - it just complicates matters. Here's a simple implementation:</p>
<pre><code>class FindableModel(db.Model):
def __getattr__(self, name):
if not name.startswith("find_by_"):
raise AttributeError(name)
field = name[len("find_by_"):]
return lambda value: self... | 7 | 2009-05-27T00:34:53Z | [
"python",
"google-app-engine",
"web-applications"
] |
Dynamic Finders and Method Missing in Python | 913,020 | <p>I'm trying to implement something like Rails dynamic-finders in Python (for
webapp/GAE). The dynamic finders work like this:</p>
<ul>
<li>Your Person has some fields: name, age and email.</li>
<li>Suppose you want to find all the users whose name is "Robot". </li>
</ul>
<p>The Person class has a method called "fin... | 5 | 2009-05-26T22:10:42Z | 1,554,403 | <p>class Person:</p>
<pre><code> name = ""
age = 0
salary = 0
def __init__(self, name, age):
self.name = name
self.age = age
</code></pre>
<p>def find(clsobj, *args):
return Person(name="Jack", age=20)</p>
<p>The for loop below inserts @classmethod for all class attributes. This m... | 0 | 2009-10-12T12:50:08Z | [
"python",
"google-app-engine",
"web-applications"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,212 | <p>I would assume it'd be the same as running two versions of 2.x; as long as they're each in their own directory you should be OK.</p>
| 1 | 2009-05-26T23:05:02Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,216 | <p>If you are on Windows, then just install another version of Python using the installer. It would be installed into another directory.</p>
<p>Then if you install other packages using the installer, it would ask you for which python installation to apply. If you use installation from source or easy_install, then just... | 9 | 2009-05-26T23:06:24Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,222 | <p>You certainly can. On Mac Ports, there's a tool called python_select that lets you switch among python versions; if nothing like it exists on Windows (momentary googling didn't reveal one), it could certainly be written.</p>
| 1 | 2009-05-26T23:07:14Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,223 | <p>Erm... yes. I just installed Python 3.0 on this computer to test it. You haven't specified your operating system, but I'm running Ubuntu 9.04 and I can explicitly specify the version of Python I want to run by typing <code>python2.5 myscript.py</code> or <code>python3.0 myscript.py</code>, depending on my needs.</p>... | 3 | 2009-05-26T23:07:25Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,225 | <p>Typically python is installed with a name like <code>python2.6</code>, so you can have more than one. There <em>may</em> be a symlink from <code>python</code> to one of the numbered files. Quite workable.</p>
| 3 | 2009-05-26T23:07:40Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,269 | <p>Yes, it is possible. </p>
<p>I maintain 3 python installations (2.5, 2.6, 3.0). The only issue that could be confusing is figuring out which Python version takes precedence in PATH variable (if any) . To execute a script for a specific version, you would go into the python directory for that version</p>
<p>C:\Pyth... | 2 | 2009-05-26T23:22:37Z | [
"python",
"python-3.x"
] |
Is it possible to install python 3 and 2.6 on same PC? | 913,204 | <p>How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.</p>
<p>EDIT:: im on a windows vista 64-bit</p>
| 3 | 2009-05-26T23:02:23Z | 913,294 | <p>You can set up <a href="http://dumbotics.com/2009/05/24/virtual-pythonenvironments/" rel="nofollow">virtual python environments</a> using <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a>.</p>
| 0 | 2009-05-26T23:32:41Z | [
"python",
"python-3.x"
] |
mod_wsgi 2.5 on Ubuntu 9.04 with Python 2.6.2 installation | 913,232 | <p>Has anybody succeeded with mod_wsgi 2.5 on Ubuntu 9.04 with default Python installation (2.6.2)?</p>
<p>I got compilation errors:</p>
<pre><code>mod_wsgi.c:119:2: error: #error Sorry, mod_wsgi requires at least Python 2.3.0.
mod_wsgi.c:123:2: error: #error Sorry, mod_wsgi requires that Python supporting thread.
</... | 1 | 2009-05-26T23:09:29Z | 913,251 | <p>Perhaps the user that the server is running as does not have /usr/bin on its path, and there is another version of python somewhere else on the path that is < 2.3</p>
<p>Try:</p>
<pre><code>which -a python
</code></pre>
<p>to find all of the pythons on your path. Perhaps one of these is what the server is runn... | 2 | 2009-05-26T23:15:25Z | [
"python",
"compiler-construction",
"ubuntu",
"mod-wsgi",
"wsgi"
] |
mod_wsgi 2.5 on Ubuntu 9.04 with Python 2.6.2 installation | 913,232 | <p>Has anybody succeeded with mod_wsgi 2.5 on Ubuntu 9.04 with default Python installation (2.6.2)?</p>
<p>I got compilation errors:</p>
<pre><code>mod_wsgi.c:119:2: error: #error Sorry, mod_wsgi requires at least Python 2.3.0.
mod_wsgi.c:123:2: error: #error Sorry, mod_wsgi requires that Python supporting thread.
</... | 1 | 2009-05-26T23:09:29Z | 913,271 | <p>From your errors I see that you're having to compile python extensions. If you haven't already, I suggest you install the python-dev package because it's usually required for compiling python extensions and it's not part of the default installation.</p>
<p>Installing the package is as easy as running:</p>
<blockq... | 5 | 2009-05-26T23:23:29Z | [
"python",
"compiler-construction",
"ubuntu",
"mod-wsgi",
"wsgi"
] |
Can't catch exception! | 913,396 | <p>I'm using swig to wrap a class from a C++ library with python. It works overall, but there is an exception that is thrown from within the library and I can't seem to catch it in the swig interface, so it just crashes the python application!</p>
<p>The class PyMonitor.cc describes the swig interface to the desired c... | 4 | 2009-05-27T00:14:37Z | 913,526 | <p>I'm not familiar with swig, or with using C++ and Python together, but if this is under a recent version of Microsoft Visual C++, then the <code>Monitor</code> class is probably throwing a C structured exception, rather than a C++ typed exception. C structured exceptions aren't caught by C++ exception handlers, even... | 1 | 2009-05-27T01:07:33Z | [
"c++",
"python",
"exception",
"swig"
] |
Can't catch exception! | 913,396 | <p>I'm using swig to wrap a class from a C++ library with python. It works overall, but there is an exception that is thrown from within the library and I can't seem to catch it in the swig interface, so it just crashes the python application!</p>
<p>The class PyMonitor.cc describes the swig interface to the desired c... | 4 | 2009-05-27T00:14:37Z | 919,573 | <p>It's possible that a function called directly or indirectly by the Monitor <code>constructor</code> is violating its exception specification and doesn't allow <code>std::bad_exception</code> to be thrown. If you haven't replaced the standard function for trapping this, then it would explain the behaviour that you ar... | 1 | 2009-05-28T07:18:07Z | [
"c++",
"python",
"exception",
"swig"
] |
Can't catch exception! | 913,396 | <p>I'm using swig to wrap a class from a C++ library with python. It works overall, but there is an exception that is thrown from within the library and I can't seem to catch it in the swig interface, so it just crashes the python application!</p>
<p>The class PyMonitor.cc describes the swig interface to the desired c... | 4 | 2009-05-27T00:14:37Z | 7,443,941 | <p>You have to forward the exceptions to Python if you want to parse them there.
See the <a href="http://www.swig.org/Doc1.3/Customization.html#exception" rel="nofollow">SWIG Documentation</a>.
In order to forward exceptions, you only have to add some code in the SWIG interface (.i) file. Basically, this can be anywher... | 4 | 2011-09-16T11:21:28Z | [
"c++",
"python",
"exception",
"swig"
] |
Python3.0: tokenize & BytesIO | 913,409 | <p>When attempting to <code>tokenize</code> a string in python3.0, why do I get a leading <code>'utf-8'</code> before the tokens start?</p>
<p>From the <a href="http://docs.python.org/3.0/library/tokenize.html" rel="nofollow">python3 docs</a>, <code>tokenize</code> should now be used as follows:</p>
<pre><code>g = to... | 1 | 2009-05-27T00:22:37Z | 913,427 | <p>That's the coding cookie of the source. You can specify one explicitly:</p>
<pre><code># -*- coding: utf-8 -*-
do_it()
</code></pre>
<p>Otherwise Python assumes the default encoding, utf-8 in Python 3.</p>
| 2 | 2009-05-27T00:29:10Z | [
"python",
"io",
"tokenize",
"bytesio"
] |
Django forms, inheritance and order of form fields | 913,589 | <p>I'm using Django forms in my website and would like to control the order of the fields.</p>
<p>Here's how I define my forms:</p>
<pre><code>class edit_form(forms.Form):
summary = forms.CharField()
description = forms.CharField(widget=forms.TextArea)
class create_form(edit_form):
name = forms.CharFiel... | 53 | 2009-05-27T01:46:50Z | 913,629 | <p>See the notes in <a href="http://stackoverflow.com/questions/350799/how-does-django-know-the-order-to-render-form-fields">this SO question</a> on the way Django's internals keep track of field order; the answers include suggestions on how to "reorder" fields to your liking (in the end it boils down to messing with t... | 3 | 2009-05-27T02:05:53Z | [
"python",
"django",
"django-forms"
] |
Django forms, inheritance and order of form fields | 913,589 | <p>I'm using Django forms in my website and would like to control the order of the fields.</p>
<p>Here's how I define my forms:</p>
<pre><code>class edit_form(forms.Form):
summary = forms.CharField()
description = forms.CharField(widget=forms.TextArea)
class create_form(edit_form):
name = forms.CharFiel... | 53 | 2009-05-27T01:46:50Z | 1,133,470 | <p>I had this same problem and I found another technique for reordering fields in the <a href="http://code.djangoproject.com/wiki/CookBookNewFormsFieldOrdering">Django CookBook</a>:</p>
<pre><code>class EditForm(forms.Form):
summary = forms.CharField()
description = forms.CharField(widget=forms.TextArea)
cla... | 94 | 2009-07-15T19:29:22Z | [
"python",
"django",
"django-forms"
] |
Django forms, inheritance and order of form fields | 913,589 | <p>I'm using Django forms in my website and would like to control the order of the fields.</p>
<p>Here's how I define my forms:</p>
<pre><code>class edit_form(forms.Form):
summary = forms.CharField()
description = forms.CharField(widget=forms.TextArea)
class create_form(edit_form):
name = forms.CharFiel... | 53 | 2009-05-27T01:46:50Z | 1,703,912 | <p>Alternate methods for changing the field order:</p>
<p>Pop-and-insert:</p>
<pre><code>self.fields.insert(0, 'name', self.fields.pop('name'))
</code></pre>
<p>Pop-and-append:</p>
<pre><code>self.fields['summary'] = self.fields.pop('summary')
self.fields['description'] = self.fields.pop('description')
</code></pre... | 2 | 2009-11-09T21:22:10Z | [
"python",
"django",
"django-forms"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.