title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
python, sqlite error? db is locked? but it isnt?
531,711
<p>I get "database table is locked" error in my sqlite3 db. My script is single threaded, no other app is using the program (i did have it open once in "SQLite Database Browser.exe"). I copied the file, del the original (success) and renamed the copy so i know no process is locking it yet when i run my script everythin...
1
2009-02-10T09:50:22Z
531,913
<p>Maybe your application terminated prematurely after a SQLite transaction began. Look for stale <code>-journal</code> files in the directory and delete them.</p> <p>It might be worth skimming through the <a href="http://www.sqlite.org/lockingv3.html" rel="nofollow">documentation</a> as well.</p>
2
2009-02-10T11:22:35Z
[ "python", "sqlite", "locking" ]
python, sqlite error? db is locked? but it isnt?
531,711
<p>I get "database table is locked" error in my sqlite3 db. My script is single threaded, no other app is using the program (i did have it open once in "SQLite Database Browser.exe"). I copied the file, del the original (success) and renamed the copy so i know no process is locking it yet when i run my script everythin...
1
2009-02-10T09:50:22Z
1,027,710
<p>Deleting -journal files sounds like bad advice. See <a href="http://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database/1027493#1027493">this explanation</a>.</p>
2
2009-06-22T15:03:26Z
[ "python", "sqlite", "locking" ]
python, sqlite error? db is locked? but it isnt?
531,711
<p>I get "database table is locked" error in my sqlite3 db. My script is single threaded, no other app is using the program (i did have it open once in "SQLite Database Browser.exe"). I copied the file, del the original (success) and renamed the copy so i know no process is locking it yet when i run my script everythin...
1
2009-02-10T09:50:22Z
6,345,495
<p>I've also seen this error when the db file is on an NFS mounted file system.</p>
0
2011-06-14T14:52:50Z
[ "python", "sqlite", "locking" ]
python, sqlite error? db is locked? but it isnt?
531,711
<p>I get "database table is locked" error in my sqlite3 db. My script is single threaded, no other app is using the program (i did have it open once in "SQLite Database Browser.exe"). I copied the file, del the original (success) and renamed the copy so i know no process is locking it yet when i run my script everythin...
1
2009-02-10T09:50:22Z
6,513,401
<p>I have run into this problem before also. It occurs often when you have a cursor and connection open and then your program crashes before you can close it properly. In some cases the following function can be used to make sure that the database is unlocked, even after it was not properly committed and closed befor...
1
2011-06-28T21:40:13Z
[ "python", "sqlite", "locking" ]
Django: Perform case-insensitive lookups by default
531,892
<p>I need to perform case-insensitive queries on <code>username</code> by default when using the Django Auth framework.</p> <p>I tried fixing the issue by writing a custom subclass of <code>Queryset</code> and overriding the <code>_filter_or_exclude</code> method and then using that subclass in a custom manager for th...
6
2009-02-10T11:16:41Z
532,049
<p>You don't want to mess with internal features of Django classes. That way lies trouble with every upgrade in the future.</p> <p>If you want to change the way people authenticate, write a custom authentication backend.</p> <p>Here are two recipes.</p> <p><a href="http://www.davidcramer.net/code/224/logging-in-wit...
4
2009-02-10T12:08:56Z
[ "python", "django", "django-models", "django-orm" ]
Django: Perform case-insensitive lookups by default
531,892
<p>I need to perform case-insensitive queries on <code>username</code> by default when using the Django Auth framework.</p> <p>I tried fixing the issue by writing a custom subclass of <code>Queryset</code> and overriding the <code>_filter_or_exclude</code> method and then using that subclass in a custom manager for th...
6
2009-02-10T11:16:41Z
532,286
<p>Managers can't be added to classes with simple attribute assignment (<code>User.objects = MyManager()</code>). Look at the ModelBase metaclass (db/models/base.py) to see what all is done for you behind the scenes when you subclass Model. </p> <p>You should be able to make it work with <code>User.add_to_class('obj...
4
2009-02-10T13:17:26Z
[ "python", "django", "django-models", "django-orm" ]
Django: Perform case-insensitive lookups by default
531,892
<p>I need to perform case-insensitive queries on <code>username</code> by default when using the Django Auth framework.</p> <p>I tried fixing the issue by writing a custom subclass of <code>Queryset</code> and overriding the <code>_filter_or_exclude</code> method and then using that subclass in a custom manager for th...
6
2009-02-10T11:16:41Z
18,732,150
<p>Here's a recipe for the auth use case: <a href="http://stackoverflow.com/questions/13190758/django-case-insensitive-matching-of-username-from-auth-user/18731796#18731796">Django : Case insensitive matching of username from auth user?</a> You're probably best off using separate solutions for each of your use cases.</...
0
2013-09-11T03:24:20Z
[ "python", "django", "django-models", "django-orm" ]
Python file indexing and searching
532,312
<p>I have a large set off files (hdf) that I need to enable search for. For Java I would use Lucene for this, as it's a file and document indexing engine. I don't know what the python equivalent would be though.</p> <p>Can anyone recommend which library I should use for indexing a large collection of files for fast se...
9
2009-02-10T13:27:29Z
532,376
<p>I haven't done indexing before, however the following may be helpful :-</p> <ol> <li>pyIndex - <a href="http://rgaucher.info/beta/pyIndex/">http://rgaucher.info/beta/pyIndex/</a> -- File indexing library for Python</li> <li><a href="http://www.xml.com/pub/a/ws/2003/05/13/email.html">http://www.xml.com/pub/a/ws/2003...
5
2009-02-10T13:42:54Z
[ "python", "search", "indexing", "lucene" ]
Python file indexing and searching
532,312
<p>I have a large set off files (hdf) that I need to enable search for. For Java I would use Lucene for this, as it's a file and document indexing engine. I don't know what the python equivalent would be though.</p> <p>Can anyone recommend which library I should use for indexing a large collection of files for fast se...
9
2009-02-10T13:27:29Z
532,426
<p>I'd suggest <a href="http://www.sphinxsearch.com/" rel="nofollow">Sphinx</a>. It's very active, has much more features and seems faster than Lucene.</p>
4
2009-02-10T13:57:01Z
[ "python", "search", "indexing", "lucene" ]
Python file indexing and searching
532,312
<p>I have a large set off files (hdf) that I need to enable search for. For Java I would use Lucene for this, as it's a file and document indexing engine. I don't know what the python equivalent would be though.</p> <p>Can anyone recommend which library I should use for indexing a large collection of files for fast se...
9
2009-02-10T13:27:29Z
533,638
<p>Lupy <a href="http://divmod.org/trac/wiki/WhitherLupy">has been retired</a> and the developers recommend PyLucene instead. As for PyLucene, its mailing list activity may be low, but it is definitely supported. In fact, it just recently became an <a href="http://lucene.apache.org/pylucene/#news20090108">official ap...
8
2009-02-10T18:51:31Z
[ "python", "search", "indexing", "lucene" ]
Python file indexing and searching
532,312
<p>I have a large set off files (hdf) that I need to enable search for. For Java I would use Lucene for this, as it's a file and document indexing engine. I don't know what the python equivalent would be though.</p> <p>Can anyone recommend which library I should use for indexing a large collection of files for fast se...
9
2009-02-10T13:27:29Z
770,090
<p>A popular C++ based information retrieval library that is often used with Python is Xapian <a href="http://xapian.org/" rel="nofollow">http://xapian.org/</a></p> <p>It's incredibly quick and can happily manage large amounts of data, however it's not quite as easily extensible as Lucene.</p>
2
2009-04-20T21:08:59Z
[ "python", "search", "indexing", "lucene" ]
What tools would you used to write a modular database in Python?
532,814
<p>I am building a modular application in python. The plugins are not known until runtime.</p> <p>I envisage that many plugins will create/read/update data, which they themselves care about, and other plugins may care about too.</p> <p>An approach I am considering: </p> <ul> <li>one plugin may be concerned with <cod...
1
2009-02-10T15:31:46Z
532,854
<p>Python is already a dynamic programming environment. The imports are not resolved until run time. Python libraries are already a series of plugins. The essential "duck-typing" means that any compatible version of a library can be plugged in at run time.</p> <p>You don't need to add any more dynamic stuff than Py...
0
2009-02-10T15:44:37Z
[ "python", "database", "design", "modularity" ]
What tools would you used to write a modular database in Python?
532,814
<p>I am building a modular application in python. The plugins are not known until runtime.</p> <p>I envisage that many plugins will create/read/update data, which they themselves care about, and other plugins may care about too.</p> <p>An approach I am considering: </p> <ul> <li>one plugin may be concerned with <cod...
1
2009-02-10T15:31:46Z
532,894
<p>I personally think that such a plug-in architecture might be a good fit for a schemaless, document-oriented solution like CouchDB. You could assign each plugin its own namespace in the document store and allow the plug-in to store whatever documents it wants to based on whatever schema it may need. </p> <p>Howeve...
3
2009-02-10T15:57:11Z
[ "python", "database", "design", "modularity" ]
What tools would you used to write a modular database in Python?
532,814
<p>I am building a modular application in python. The plugins are not known until runtime.</p> <p>I envisage that many plugins will create/read/update data, which they themselves care about, and other plugins may care about too.</p> <p>An approach I am considering: </p> <ul> <li>one plugin may be concerned with <cod...
1
2009-02-10T15:31:46Z
533,497
<p>Here's a nice treatment of plugins in Python, no database thingies included: <a href="http://martyalchin.com/2008/jan/10/simple-plugin-framework/" rel="nofollow">A Simple Plugin Framework</a>.</p>
0
2009-02-10T18:13:39Z
[ "python", "database", "design", "modularity" ]
What tools would you used to write a modular database in Python?
532,814
<p>I am building a modular application in python. The plugins are not known until runtime.</p> <p>I envisage that many plugins will create/read/update data, which they themselves care about, and other plugins may care about too.</p> <p>An approach I am considering: </p> <ul> <li>one plugin may be concerned with <cod...
1
2009-02-10T15:31:46Z
542,544
<p>Here's how I'd do it: Each plugin should create it's own private tables and perform operations by joining the private tables with the host tables.</p> <p>Suppose your host application has a user table like: (users: id, name, password) and someone wants to write a plugin to store and display each user's blog address...
1
2009-02-12T17:56:00Z
[ "python", "database", "design", "modularity" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
532,983
<p>There are some persistence builtins mentioned in the <a href="http://docs.python.org/library/persistence.html" rel="nofollow">python documentation</a> but I don't think any of these is remarkable smaller in the produced filesize.</p> <p>You could alway use the <a href="http://docs.python.org/library/configparser.ht...
1
2009-02-10T16:15:16Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
532,989
<p>"the byte overhead is significant"</p> <p>Why does this matter? It does the job. If you're running low on disk space, I'd be glad to sell you a 1Tb for $500. </p> <p>Have you run it? Is performance a problem? Can you demonstrate that the performance of serialization is <strong>the</strong> problem?</p> <p>"I...
0
2009-02-10T16:15:50Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
533,045
<p>Take a look at <a href="http://docs.python.org/library/json.html">json</a>, at least the generated <code>dumps</code> are readable with many other languages.</p> <blockquote> <p>JSON (JavaScript Object Notation) <a href="http://json.org">http://json.org</a> is a subset of JavaScript syntax (ECMA-262 3rd edition) ...
12
2009-02-10T16:28:58Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
533,150
<p>personally i would use <a href="http://pyyaml.org/wiki/PyYAML">yaml</a>. it's on par with json for encoding size, but it can represent some more complex things (e.g. classes, recursive structures) when necessary. </p> <pre><code>In [1]: import yaml In [2]: x = [1, 2, 3, 'pants'] In [3]: print(yaml.dump(x)) [1, 2, ...
8
2009-02-10T16:47:10Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
533,280
<p>If you need a space efficient solution you can use Google Protocol buffers.</p> <p><a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">Protocol buffers - Encoding</a></p> <p><a href="http://code.google.com/apis/protocolbuffers/docs/pythontutorial.html">Protocol buffers - Python Tutorial</a></p...
6
2009-02-10T17:14:10Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
533,381
<p>Maybe you're not using the right protocol:</p> <pre><code>&gt;&gt;&gt; import pickle &gt;&gt;&gt; a = range(1, 100) &gt;&gt;&gt; len(pickle.dumps(a)) 492 &gt;&gt;&gt; len(pickle.dumps(a, pickle.HIGHEST_PROTOCOL)) 206 </code></pre> <p>See the documentation for <a href="http://docs.python.org/library/pickle.html#dat...
8
2009-02-10T17:39:57Z
[ "python", "serialization", "pickle" ]
Lightweight pickle for basic types in python?
532,934
<p>All I want to do is serialize and unserialize tuples of strings or ints.</p> <p>I looked at pickle.dumps() but the byte overhead is significant. Basically it looks like it takes up about 4x as much space as it needs to. Besides, all I need is basic types and have no need to serialize objects.</p> <p>marshal is a l...
6
2009-02-10T16:03:57Z
1,437,394
<p>Luckily there is solution which uses COMPRESSION, and solves the general problem involving any arbitrary Python object including new classes. Rather than micro-manage mere tuples sometimes it's better to use a DRY tool.<br /> Your code will be more crisp and readily refactored in similar future situations. </p> ...
-1
2009-09-17T08:09:07Z
[ "python", "serialization", "pickle" ]
Extend standard python logging, to include the line number where a log method was invoked
533,048
<p>Is it possible to somehow decorate/extend the python standard logging system, so that when a logging method is invoked it also logs the file and the line number where it was invoked or maybe the method that invoked it.</p>
41
2009-02-10T16:29:23Z
533,077
<p>Sure, check <a href="http://docs.python.org/library/logging.html#formatter-objects">formatters</a> in logging docs. Specifically the lineno and pathname variables.</p> <blockquote> <p><strong>%(pathname)s</strong> Full pathname of the source file where the logging call was issued(if available).</p> <p><stro...
71
2009-02-10T16:33:26Z
[ "python", "logging" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
533,184
<p>Hi From <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/?from=olddocs">here</a></p> <blockquote> <p>For Windows users, who do not have symlinking functionality available, you can copy django-admin.py to a location on your existing path or edit the PATH settings (under Settings - Control Panel - Sys...
5
2009-02-10T16:53:05Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
543,381
<p>Sort of sounds like the windows version of Python is trying to run instead of the cygwin one. What happens if you type this:</p> <pre><code>$ python django-admin.py </code></pre> <p>Here I'm assuming </p> <pre><code>$ which python </code></pre> <p>Finds the cygwin version of python (which will be something like ...
0
2009-02-12T21:28:46Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
543,512
<p>Help us help you. Is there a reason why you are running the windows python interpreter (c:\Python26\python.exe) as oppose to the cygwin python interpreter (/usr/bin/python.exe)? That could be your problem. So to troubleshoot that, you might consider removing the windows native interpreter or simply making sure the c...
0
2009-02-12T21:50:41Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
550,413
<p>Add the location of your django/bin folder (or wherever else you keep django-admin.py) to your PYTHONPATH environment variable.</p>
0
2009-02-15T06:22:40Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
558,172
<p>Like Brian mentioned you are running the Windows version of Python which won't work with the Cygwin installation.</p> <p>A word of warning. When I first started using Django, I tried installing it in Cygwin and had a variety of problems and ended up switching to the regular Windows version of Python. Unfortunately,...
0
2009-02-17T18:34:32Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
791,703
<p>I just ran into the exact same problem. I've found that if you already have the windows version of python installed, it seems to get priority over the cygwin version. I solved the problem by editing /etc/profile and changed:</p> <pre><code>PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH </code></pre> <p>......
4
2009-04-26T22:11:14Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
11,465,527
<p>Just copy the <strong>django-admin.py</strong> to the current location you are working on for e.g</p> <p>on Cygwin:</p> <pre><code>&lt;root&gt;/projects/ </code></pre> <p>on your windows directory it will look like this:</p> <pre><code>C:\cygwin\home\&lt;your computer name&gt;\projects\ </code></pre> <p>once yo...
0
2012-07-13T06:52:37Z
[ "python", "django", "cygwin" ]
How to integrate Django and Cygwin?
533,125
<p>I have a Windows box with cygwin, python and django installed.</p> <p>Now I want to run django-admin, but when I do I get the error:</p> <pre><code>$ django-admin.py c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory </code></pre>
9
2009-02-10T16:42:14Z
11,465,595
<p>As for the step on how to start your django in cygwin</p> <p>first open your windows command prompt then register the python environment by doing this:</p> <pre class="lang-none prettyprint-override"><code>Path %path%;C:\Python27;C:\Python27\Scripts </code></pre> <p>then now go to the installation folder of you...
0
2012-07-13T06:58:35Z
[ "python", "django", "cygwin" ]
What does 'self' refer to in a @classmethod?
533,300
<p>I thought I was starting to get a grip on "the Python way" of programming. Methods of a class accept self as the first parameter to refer to the instance of the class whose context the method is being called in. The @classmethod decorator refers to a method whose functionality is associated with the class, but which...
15
2009-02-10T17:18:53Z
533,315
<p><a href="http://docs.python.org/library/functions.html#classmethod">class itself</a>:</p> <blockquote> <p>A class method receives the class as implicit first argument, just like an instance method receives the instance.</p> </blockquote> <pre><code>class C: @classmethod def f(cls): print(cls.__na...
32
2009-02-10T17:22:58Z
[ "python", "self", "class-method" ]
What does 'self' refer to in a @classmethod?
533,300
<p>I thought I was starting to get a grip on "the Python way" of programming. Methods of a class accept self as the first parameter to refer to the instance of the class whose context the method is being called in. The @classmethod decorator refers to a method whose functionality is associated with the class, but which...
15
2009-02-10T17:18:53Z
533,316
<p>The class object gets passed as the first parameter. For example:</p> <pre><code>class Foo(object): @classmethod def bar(self): return self() </code></pre> <p>Would return an instance of the Foo class.</p> <p><strong>EDIT</strong>:</p> <p>Note that the last line would be self() not self. self w...
1
2009-02-10T17:23:17Z
[ "python", "self", "class-method" ]
What does 'self' refer to in a @classmethod?
533,300
<p>I thought I was starting to get a grip on "the Python way" of programming. Methods of a class accept self as the first parameter to refer to the instance of the class whose context the method is being called in. The @classmethod decorator refers to a method whose functionality is associated with the class, but which...
15
2009-02-10T17:18:53Z
533,331
<p>The first parameter of a classmethod is named <code>cls</code> by convention and refers to the the class object <em>on which the method it was invoked</em>.</p> <pre><code>&gt;&gt;&gt; class A(object): ... @classmethod ... def m(cls): ... print cls is A ... print issubclass(cls, A) &gt;&gt...
12
2009-02-10T17:28:00Z
[ "python", "self", "class-method" ]
What does 'self' refer to in a @classmethod?
533,300
<p>I thought I was starting to get a grip on "the Python way" of programming. Methods of a class accept self as the first parameter to refer to the instance of the class whose context the method is being called in. The @classmethod decorator refers to a method whose functionality is associated with the class, but which...
15
2009-02-10T17:18:53Z
15,393,431
<p>Django does some strange stuff with a class method here:</p> <pre><code>class BaseFormSet(StrAndUnicode): """ A collection of instances of the same Form class. """ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList): ....
0
2013-03-13T18:22:16Z
[ "python", "self", "class-method" ]
Disable pixmap background defined by GTK theme per application
533,321
<p>For our (open source) fullscreen text editor we're changing background colors of <code>gtk.Window</code>, <code>gtk.Fixed</code>, etc. to custom colors. This works fine, but some <a href="http://en.wikipedia.org/wiki/GTK%2B" rel="nofollow">GTK</a> themes (e.g. <a href="http://sourceforge.net/projects/mac4lin/" rel="...
3
2009-02-10T17:25:31Z
534,151
<p>Yes ofcourse Mac4Lin uses pixmaps for more granular appearance to match MAC look. Well to disable those backgroud you dont need to override it.</p> <p>if you want background pixmap as its parent's, set it as</p> <pre><code>bg_pixmap[state] = "&lt;parent&gt;" </code></pre> <p>and to disable set it as</p> <pre><co...
2
2009-02-10T20:50:24Z
[ "python", "gtk", "pygtk" ]
Dynamic/runtime method creation (code generation) in Python
533,382
<p>I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring.</p> <p>I came up with a solution combining <code>exec</code> and <code>setattr</code>, here's a dummy example:</p> <pre><code>class Viking(object): def __init__(self): code = ''' ...
32
2009-02-10T17:40:05Z
533,581
<p>Python will let you declare a function in a function, so you don't have to do the <code>exec</code> trickery.</p> <pre><code>def __init__(self): def dynamo(self, arg): """ dynamo's a dynamic method! """ self.weight += 1 return arg * self.weight self.weight = 50 setattr(...
6
2009-02-10T18:38:43Z
[ "python", "metaprogramming", "exec" ]
Dynamic/runtime method creation (code generation) in Python
533,382
<p>I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring.</p> <p>I came up with a solution combining <code>exec</code> and <code>setattr</code>, here's a dummy example:</p> <pre><code>class Viking(object): def __init__(self): code = ''' ...
32
2009-02-10T17:40:05Z
533,583
<p>Function docstrings and names are mutable properties. You can do anything you want in the inner function, or even have multiple versions of the inner function that makedynamo() chooses between. No need to build any code out of strings.</p> <p>Here's a snippet out of the interpreter:</p> <pre><code>&gt;&gt;&gt; def...
9
2009-02-10T18:38:47Z
[ "python", "metaprogramming", "exec" ]
Dynamic/runtime method creation (code generation) in Python
533,382
<p>I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring.</p> <p>I came up with a solution combining <code>exec</code> and <code>setattr</code>, here's a dummy example:</p> <pre><code>class Viking(object): def __init__(self): code = ''' ...
32
2009-02-10T17:40:05Z
534,597
<p>Based on Theran's code, but extending it to methods on classes:</p> <pre> <code> class Dynamo(object): pass def add_dynamo(cls,i): def innerdynamo(self): print "in dynamo %d" % i innerdynamo.__doc__ = "docstring for dynamo%d" % i innerdynamo.__name__ = "dynamo%d" % i setattr(cls,innerd...
54
2009-02-10T22:46:31Z
[ "python", "metaprogramming", "exec" ]
Dynamic/runtime method creation (code generation) in Python
533,382
<p>I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring.</p> <p>I came up with a solution combining <code>exec</code> and <code>setattr</code>, here's a dummy example:</p> <pre><code>class Viking(object): def __init__(self): code = ''' ...
32
2009-02-10T17:40:05Z
2,539,707
<p>Pardon me for my bad English.</p> <p>I recently need to generate dynamic function to bind each menu item to open particular frame on wxPython. Here is what i do.</p> <p>first, i create a list of mapping between the menu item and the frame.</p> <pre><code>menus = [(self.menuItemFile, FileFrame), (self.menuItemEdit...
0
2010-03-29T16:51:41Z
[ "python", "metaprogramming", "exec" ]
In python 2.4, how can I execute external commands with csh instead of bash?
533,398
<p>Without using the new 2.6 subprocess module, how can I get either os.popen or os.system to execute my commands using the tcsh instead of bash? I need to source some scripts which are written in tcsh before executing some other commands and I need to do this within python2.4.</p> <p>EDIT Thanks for answers using 't...
2
2009-02-10T17:44:23Z
533,422
<p>How about:</p> <pre><code>&gt;&gt;&gt; os.system("tcsh your_own_script") </code></pre> <p>Or just write the script and add</p> <pre><code>#!/bin/tcsh </code></pre> <p>at the beginning of the file and let the OS take care of that.</p>
5
2009-02-10T17:50:02Z
[ "python", "shell", "csh", "tcsh" ]
In python 2.4, how can I execute external commands with csh instead of bash?
533,398
<p>Without using the new 2.6 subprocess module, how can I get either os.popen or os.system to execute my commands using the tcsh instead of bash? I need to source some scripts which are written in tcsh before executing some other commands and I need to do this within python2.4.</p> <p>EDIT Thanks for answers using 't...
2
2009-02-10T17:44:23Z
533,435
<p>Just prefix the shell as part of your command. I don't have tcsh installed but with zsh:</p> <pre><code>&gt;&gt;&gt; os.system ("zsh -c 'echo $0'") zsh 0 </code></pre>
10
2009-02-10T17:53:19Z
[ "python", "shell", "csh", "tcsh" ]
In python 2.4, how can I execute external commands with csh instead of bash?
533,398
<p>Without using the new 2.6 subprocess module, how can I get either os.popen or os.system to execute my commands using the tcsh instead of bash? I need to source some scripts which are written in tcsh before executing some other commands and I need to do this within python2.4.</p> <p>EDIT Thanks for answers using 't...
2
2009-02-10T17:44:23Z
533,479
<p>Just set the shell to use to be <code>tcsh</code>:</p> <pre><code>&gt;&gt;&gt; os.environ['SHELL'] = 'tcsh' &gt;&gt;&gt; os.environ['SHELL'] 'tcsh' &gt;&gt;&gt; os.system("echo $SHELL") tcsh </code></pre>
-1
2009-02-10T18:06:53Z
[ "python", "shell", "csh", "tcsh" ]
In python 2.4, how can I execute external commands with csh instead of bash?
533,398
<p>Without using the new 2.6 subprocess module, how can I get either os.popen or os.system to execute my commands using the tcsh instead of bash? I need to source some scripts which are written in tcsh before executing some other commands and I need to do this within python2.4.</p> <p>EDIT Thanks for answers using 't...
2
2009-02-10T17:44:23Z
534,049
<p><code>os.system()</code> calls <code>system(3)</code> directly, and this system call is the one that "chooses" the shell. I put that in quotes, because <code>system(3)</code> will always execute <code>/bin/sh</code>.</p> <p>Thus, if you want Python to use a different shell, you have several options:</p> <ul> <li><...
-2
2009-02-10T20:27:51Z
[ "python", "shell", "csh", "tcsh" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
533,675
<p>First, you should note that mixins only exist in multiple-inheritance languages. You can't do a mixin in Java or C#. </p> <p>Basically, a mixin is a stand-alone base type that provides limited functionality and polymorphic resonance for a child class. If you're thinking in C#, think of an interface that you don't h...
152
2009-02-10T19:00:51Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
533,714
<p>Maybe an example from ruby can help:</p> <p>You can include the mixin <code>Comparable</code> and define one function <code>"&lt;=&gt;(other)"</code>, the mixin provides all those functions:</p> <pre><code>&lt;(other) &gt;(other) ==(other) &lt;=(other) &gt;=(other) between?(other) </code></pre> <p>It does this by...
6
2009-02-10T19:08:50Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
533,768
<p>I'd advise against mix-ins in new Python code, if you can find any other way around it (such as composition-instead-of-inheritance, or just monkey-patching methods into your own classes) that isn't much more effort.</p> <p>In old-style classes you could use mix-ins as a way of grabbing a few methods from another cl...
9
2009-02-10T19:21:19Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
534,284
<p>Perhaps a couple of examples will help.</p> <p>If you're building a class and you want it to act like a dictionary, you can define all the various <code>__ __</code> methods necessary. But that's a bit of a pain. As an alternative, you can just define a few, and inherit (in addition to any other inheritance) from...
6
2009-02-10T21:27:41Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
547,714
<p>A mixin is a special kind of multiple inheritance. There are two main situations where mixins are used:</p> <ol> <li>You want to provide a lot of optional features for a class.</li> <li>You want to use one particular feature in a lot of different classes.</li> </ol> <p>For an example of number one, consider <a hr...
386
2009-02-13T21:15:17Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
560,204
<p>It's not a Python example but in <a href="http://www.digitalmars.com/d/1.0/template-mixin.html" rel="nofollow">the D programing language</a> the term <a href="http://www.digitalmars.com/d/1.0/template-mixin.html" rel="nofollow"><code>mixin</code></a> is used to refer to a construct used much the same way; adding a p...
5
2009-02-18T08:00:23Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
5,403,666
<p>I read that you have a c# background. So a good starting point might be a mixin implementation for .NET.</p> <p>You might want to check out the codeplex project at <a href="http://remix.codeplex.com/" rel="nofollow">http://remix.codeplex.com/</a></p> <p>Watch the lang.net Symposium link to get an overview. There i...
1
2011-03-23T10:16:56Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
11,008,499
<p>Mixins is a concept in Programming in which the class provides functionalities but it is not meant to be used for instantiation. Main purpose of Mixins is to provide functionalities which are standalone and it would be best if the mixins itself do not have inheritance with other mixins and also avoid state. In langu...
12
2012-06-13T05:06:32Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
11,739,457
<p>mixin gives a way to add functionality in a class, i.e you can interact with methods defined in a module by including the module inside the desired class. Though ruby doesn't supports multiple inheritance but provides mixin as an alternative to achieve that.</p> <p>here is an example that explains how multiple inhe...
3
2012-07-31T11:49:59Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
15,372,409
<p>I just used a python mixin to implement unit testing for python milters. Normally, a milter talks to an MTA, making unit testing difficult. The test mixin overrides methods that talk to the MTA, and create a simulated environment driven by test cases instead.</p> <p>So, you take an unmodified milter application, ...
3
2013-03-12T21:22:43Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
17,491,186
<p>I think of them as a disciplined way of using multiple inheritance - because ultimately a mixin is just another python class that (might) follow the conventions about classes that are called mixins.</p> <p>My understanding of the conventions that govern something you would call a Mixin are that a Mixin:</p> <ul> <...
17
2013-07-05T14:26:37Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
20,022,860
<p>This answer aims to explain mixins <strong>with examples</strong> that are:</p> <ul> <li><p><strong>self-contained</strong>: short, with no need to know any libraries to understand the example.</p></li> <li><p><strong>in Python</strong>, not in other languages.</p> <p>It is understandable that there were examples ...
77
2013-11-16T19:36:03Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
25,871,340
<p>Re Ciro Santilli: It is actually possible to use your second definition of mixins in C++ using interfaces</p> <pre><code>#include &lt;iostream&gt; struct Interface { virtual int method() const = 0; }; class HasMethod1 : public virtual Interface { int method() const {return 1;} }; class HasMethod2 : publi...
1
2014-09-16T14:23:14Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
27,653,307
<p>I think there have been some good explanations here but I wanted to provide another perspective.</p> <p>In Scala, you can do mixins as has been described here but what is very interesting is that the mixins are actually 'fused' together to create a new kind of class to inherit from. In essence, you do not inherit f...
6
2014-12-26T05:54:36Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
What is a mixin, and why are they useful?
533,631
<p>In "<a href="http://rads.stackoverflow.com/amzn/click/0596009259">Programming Python</a>", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin? </p> <p>Reading between the lines of <a href="http://books.google.com/books?id=5zYVUIl7F0QC&amp;pg=RA1-PA584&a...
540
2009-02-10T18:50:42Z
36,222,493
<blockquote> <h1>What separates a mixin from multiple inheritance? Is it just a matter of semantics?</h1> </blockquote> <p>A mixin is a limited form of multiple inheritance. In some languages the mechanism for adding a mixin to a class is slightly different (in terms of syntax) from that of inheritance.</p> <p>In t...
1
2016-03-25T15:05:09Z
[ "python", "oop", "multiple-inheritance", "mixins" ]
How do I use the the Django ORM to query this many-to-many example?
533,726
<p>I have the following models:</p> <pre><code>class Author(models.Model): author_name = models.CharField() class Book(models.Model): book_name = models.CharField() class AuthorBook(models.Model): author_id = models.ForeignKeyField(Author) book_id = models.ForeignKeyField(Book) </code></pre> <p>With that be...
5
2009-02-10T19:12:06Z
533,770
<p>You should be able to do:</p> <pre><code>books = Book.objects.filter(authorbook__author_id=1) </code></pre> <p>to get a QuerySet of Book objects matching your author_id restriction.</p> <p>The nice thing about Django is you can cook this up and play around with it in the shell. You may also find <a href="http:/...
14
2009-02-10T19:21:36Z
[ "python", "django", "django-orm" ]
How do I use the the Django ORM to query this many-to-many example?
533,726
<p>I have the following models:</p> <pre><code>class Author(models.Model): author_name = models.CharField() class Book(models.Model): book_name = models.CharField() class AuthorBook(models.Model): author_id = models.ForeignKeyField(Author) book_id = models.ForeignKeyField(Book) </code></pre> <p>With that be...
5
2009-02-10T19:12:06Z
533,799
<p>"AuthorBook" seems not correctly modeled.</p> <p>You should use a <code>ManyToManyField</code>:</p> <pre><code>class Book(models.Model): name = models.CharField() authors = models.ManyToManyField(Author) </code></pre> <p>Then you can do:</p> <pre><code>books = Book.objects.filter(authors__id=1) </code></pre>...
14
2009-02-10T19:28:58Z
[ "python", "django", "django-orm" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
533,917
<p>In Python 2.6+</p> <pre><code>import itertools for element in itertools.product(*somelists): print element </code></pre> <p>Documentation: <a href="https://docs.python.org/2/library/itertools.html#itertools.product">Python 2 - itertools.product</a></p>
159
2009-02-10T19:58:01Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
533,919
<pre><code>import itertools &gt;&gt;&gt; for i in itertools.product([1,2,3],['a','b'],[4,5]): ... print i ... (1, 'a', 4) (1, 'a', 5) (1, 'b', 4) (1, 'b', 5) (2, 'a', 4) (2, 'a', 5) (2, 'b', 4) (2, 'b', 5) (3, 'a', 4) (3, 'a', 5) (3, 'b', 4) (3, 'b', 5) &gt;&gt;&gt; </code></pre>
42
2009-02-10T19:58:31Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
533,928
<p>with <a href="http://docs.python.org/library/itertools.html#itertools.permutations">itertools.product</a>:</p> <pre><code>import itertools result = list(itertools.product(*somelists)) </code></pre>
7
2009-02-10T20:01:26Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
533,934
<p>In Python 2.6 and above you can use 'itertools.product`. In older versions of Python you can use the following (almost -- see documentation) equivalent <a href="http://docs.python.org/library/itertools.html#itertools.product">code from the documentation</a>:</p> <pre><code>def product(*args, **kwds): # product(...
9
2009-02-10T20:02:47Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
534,085
<p>For Python 2.5 and older:</p> <pre><code>&gt;&gt;&gt; [(a, b, c) for a in [1,2,3] for b in ['a','b'] for c in [4,5]] [(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5), (2, 'b', 4), (2, 'b', 5), (3, 'a', 4), (3, 'a', 5), (3, 'b', 4), (3, 'b', 5)] </code></pre> <p>Here's a recursive v...
24
2009-02-10T20:38:16Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
17,102,114
<p>Here is a recursive generator, which doesn't store any temporary lists</p> <pre><code>def product(ar_list): if not ar_list: yield () else: for a in ar_list[0]: for prod in product(ar_list[1:]): yield (a,)+prod print list(product([[1,2],[3,4],[5,6]])) </code></pre...
2
2013-06-14T06:08:27Z
[ "python", "list" ]
Get the cartesian product of a series of lists in Python
533,905
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p> <p>Input: </p> <pre><code>somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] </code></pre> <p>Desired output:</p> <pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]...
131
2009-02-10T19:54:17Z
33,425,736
<p>Just to add a bit to what has already been said: if you use sympy, you can use symbols rather than strings which makes them mathematically useful.</p> <pre><code>import itertools import sympy x, y = sympy.symbols('x y') somelist = [[x,y], [1,2,3], [4,5]] somelist2 = [[1,2], [1,2,3], [4,5]] for element in itertoo...
1
2015-10-29T22:28:11Z
[ "python", "list" ]
Python Golf: what's the most concise way of turning this list of lists into a dictionary:
534,608
<p>I have a list of lists that looks like this:</p> <pre><code>[['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']] </code></pre> <p>and I want to turn it into a dictionary where each key is a name and each value is a number corresponding to the position of its sublist in the list:</p> <pre><code>{'Tom': 0, 'Dick':...
3
2009-02-10T22:49:02Z
534,615
<pre><code>names_dict = dict((name,index) for index,lst in enumerate(names) for name in lst) </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; names = [['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']] &gt;&gt;&gt; names_dict = dict((name,index) ... for ind...
14
2009-02-10T22:51:09Z
[ "python", "code-golf" ]
Python Golf: what's the most concise way of turning this list of lists into a dictionary:
534,608
<p>I have a list of lists that looks like this:</p> <pre><code>[['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']] </code></pre> <p>and I want to turn it into a dictionary where each key is a name and each value is a number corresponding to the position of its sublist in the list:</p> <pre><code>{'Tom': 0, 'Dick':...
3
2009-02-10T22:49:02Z
534,686
<p>Same idea as MizardX, but slightly smaller and prettier in Python 3.0 using <a href="http://www.python.org/dev/peps/pep-0274/" rel="nofollow">dict comprehensions:</a></p> <pre><code>&gt;&gt;&gt; names = [['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']] &gt;&gt;&gt; names_dict = {name:index for index, lst in enu...
19
2009-02-10T23:09:25Z
[ "python", "code-golf" ]
Python Golf: what's the most concise way of turning this list of lists into a dictionary:
534,608
<p>I have a list of lists that looks like this:</p> <pre><code>[['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']] </code></pre> <p>and I want to turn it into a dictionary where each key is a name and each value is a number corresponding to the position of its sublist in the list:</p> <pre><code>{'Tom': 0, 'Dick':...
3
2009-02-10T22:49:02Z
4,673,778
<p>python 2.6</p> <pre><code>dict([(t,l.index(x)) for x in l for t in x]) </code></pre> <p>python3.0</p> <pre><code>{t:l.index(x) for x in l for t in x} </code></pre> <p>if l is the list of names</p>
1
2011-01-12T20:39:19Z
[ "python", "code-golf" ]
How to create a GUID/UUID in Python
534,839
<p>How do I create a GUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?</p>
245
2009-02-10T23:51:21Z
534,847
<p>"The uuid module, in Python 2.5 and up, provides RFC compliant UUID generation. See the module docs and the RFC for details."</p> <p>Docs:</p> <ul> <li>Python 2: <a href="http://docs.python.org/2/library/uuid.html">http://docs.python.org/2/library/uuid.html</a></li> <li>Python 3: <a href="https://docs.python.org/...
169
2009-02-10T23:54:26Z
[ "python", "guid", "uuid" ]
How to create a GUID/UUID in Python
534,839
<p>How do I create a GUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?</p>
245
2009-02-10T23:51:21Z
534,851
<p>If you're using Python 2.5 or later, the <a href="https://docs.python.org/2/library/uuid.html#module-uuid"><strong>uuid module</strong></a> is already included with the Python standard distribution.</p> <p>Ex: </p> <pre><code>&gt;&gt;&gt; import uuid &gt;&gt;&gt; uuid.uuid4() UUID('5361a11b-615c-42bf-9bdb-e2c3790a...
242
2009-02-10T23:55:52Z
[ "python", "guid", "uuid" ]
How to create a GUID/UUID in Python
534,839
<p>How do I create a GUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?</p>
245
2009-02-10T23:51:21Z
10,984,286
<p>I use GUIDs as random keys for database type operations.</p> <p>The hexadecimal form, with the dashes and extra characters seem unnecessarily long to me. But I also like that strings representing hexadecimal numbers are very safe in that they do not contain characters that can cause problems in some situations such...
19
2012-06-11T16:47:53Z
[ "python", "guid", "uuid" ]
How to create a GUID/UUID in Python
534,839
<p>How do I create a GUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?</p>
245
2009-02-10T23:51:21Z
27,302,466
<p>Copied from : <a href="https://docs.python.org/2/library/uuid.html">https://docs.python.org/2/library/uuid.html</a> (Since the links posted were not active and they keep updating)</p> <pre><code>&gt;&gt;&gt; import uuid &gt;&gt;&gt; # make a UUID based on the host ID and current time &gt;&gt;&gt; uuid.uuid1() UUID...
43
2014-12-04T19:34:05Z
[ "python", "guid", "uuid" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,862
<p>If you have two lists called 'a' and 'b', you can do: <code>[m - n for m,n in zip(a,b)]</code></p>
2
2009-02-10T23:59:49Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,866
<p>If this is something you end up doing frequently, and with different operations, you should probably create a class to handle cases like this, or better use some library like <a href="http://numpy.scipy.org/">Numpy</a>.</p> <p>Otherwise, look for <a href="http://docs.python.org/tutorial/datastructures.html#list-com...
77
2009-02-11T00:00:52Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,872
<p>Check out the <a href="http://numpy.scipy.org/">NumPy</a> package for python.</p>
7
2009-02-11T00:01:51Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,876
<p>If you plan on performing more than simple one liners, it would be better to implement your own class and override the appropriate operators as they apply to your case.</p> <p>Taken from <a href="http://www.math.okstate.edu/~ullrich/PyPlug/" rel="nofollow">Mathematics in Python</a>:</p> <pre><code>class Vector: ...
3
2009-02-11T00:03:52Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,910
<p>If your lists are a and b, you can do:</p> <pre><code>map(int.__sub__, a, b) </code></pre> <p>But you probably shouldn't. No one will know what it means.</p>
2
2009-02-11T00:17:55Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
534,914
<p>Here's an alternative to list comprehensions. Map iterates through the list(s) (the latter arguments), doing so simulataneously, and passes their elements as arguments to the function (the first arg). It returns the resulting list.</p> <pre><code>map(operator.sub, a, b) </code></pre> <p>This code because has les...
49
2009-02-11T00:19:03Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
535,220
<p>A slightly different Vector class.</p> <pre><code>class Vector( object ): def __init__(self, *data): self.data = data def __repr__(self): return repr(self.data) def __add__(self, other): return tuple( (a+b for a,b in zip(self.data, other.data) ) ) def __sub__(self, other):...
3
2009-02-11T02:44:23Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
535,830
<p>I'd have to recommend <a href="http://numpy.scipy.org/">NumPy</a> as well</p> <p>Not only is it faster for doing vector math, but it also has a ton of convenience functions.</p> <p>If you want something even faster for 1d vectors, try <a href="http://www.excamera.com/articles/25/vop.html">vop</a></p> <p>It's simi...
5
2009-02-11T07:59:28Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
1,543,384
<p>Try this:</p> <pre><code>list(array([1,2,3])-1) </code></pre>
-1
2009-10-09T12:03:44Z
[ "python", "list", "tuples", "vector" ]
Subtracting 2 lists in Python
534,855
<p>Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like</p> <pre><code>[2,2,2] - [1,1,1] = [1,1,1] </code></pre> <p>Should I use tuples?</p> <p>If none of them defines these operands on these types, can I define it instead?</p> <p>If not, should I cre...
33
2009-02-10T23:57:22Z
23,389,512
<p>If you want the result in list :</p> <pre><code>list(numpy.array(list1)-numpy.array(list2)) </code></pre> <p>if not remove list.</p>
0
2014-04-30T13:31:36Z
[ "python", "list", "tuples", "vector" ]
practice with threads in python
535,331
<p>I know that Python has a <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">global lock</a> and i've read Glyph's explaination of <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming/204150#204150">python...
2
2009-02-11T03:42:33Z
535,347
<p>If the sobel operator is CPU-bound, then you won't get any benefit from multiple threads because python does not take advantage of multiple cores.</p> <p>Conceivably you could spin off multiple processes, though I'm not sure if that would be practical for working on a single image.</p> <p>10 seconds doesn't seem l...
3
2009-02-11T03:50:21Z
[ "python", "multithreading", "image-manipulation" ]
practice with threads in python
535,331
<p>I know that Python has a <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">global lock</a> and i've read Glyph's explaination of <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming/204150#204150">python...
2
2009-02-11T03:42:33Z
535,399
<p>Python 2.6 now includes the <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow"><strong>mulitprocessing</strong></a> module (formerly <a href="http://pyprocessing.berlios.de/doc/index.html" rel="nofollow"><strong>processing</strong></a> module on older versions of Python). </p> <p>It has es...
7
2009-02-11T04:10:34Z
[ "python", "multithreading", "image-manipulation" ]
practice with threads in python
535,331
<p>I know that Python has a <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">global lock</a> and i've read Glyph's explaination of <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming/204150#204150">python...
2
2009-02-11T03:42:33Z
535,431
<p>Bulk matrix operations like the Sobel operator will definitely realize significant speed gains by (correctly) using <a href="http://www.mathworks.com/company/newsletters/news_notes/clevescorner/winter2000.cleve.html" rel="nofollow">Matlab/Octave</a>. It is possible that <a href="http://www.scipy.org/NumPy_for_Matla...
0
2009-02-11T04:24:28Z
[ "python", "multithreading", "image-manipulation" ]
practice with threads in python
535,331
<p>I know that Python has a <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">global lock</a> and i've read Glyph's explaination of <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming/204150#204150">python...
2
2009-02-11T03:42:33Z
535,819
<p>I recommend using NumPy as well. Not only will it probably be faster, but if you use threads with it, there won't be a global lock.</p> <p>I'll also suggest using multiprocessing as Jay suggests.</p> <p>Anyways, if you really want to practice threading, I'd suggest playing around with PThreads in C. PThreads are ...
2
2009-02-11T07:50:58Z
[ "python", "multithreading", "image-manipulation" ]
practice with threads in python
535,331
<p>I know that Python has a <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">global lock</a> and i've read Glyph's explaination of <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming/204150#204150">python...
2
2009-02-11T03:42:33Z
545,887
<p>Python mutliprocessing is the right choice if you want to practice parallel programming with Python. If you don't have Python 2.6 (which you don't if you're using Ubuntu for example), you can use the <a href="http://code.google.com/p/python-multiprocessing/" rel="nofollow">Google code backported</a> version of multi...
0
2009-02-13T13:18:03Z
[ "python", "multithreading", "image-manipulation" ]
Python libraries to construct classes from a relational database? (ORM in reverse)
535,426
<p>Are there any Python object-relational mapping libraries that, given a database schema, can generate a set of Python classes? I know that the major libraries such as <a href="http://www.sqlobject.org/" rel="nofollow">SQLObject</a>, <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, and <a href="http...
3
2009-02-11T04:22:19Z
535,437
<p><a href="http://code.google.com/p/sqlautocode/" rel="nofollow">SQLAlchemy extension to create a python code model from an existing database</a></p>
11
2009-02-11T04:27:42Z
[ "python", "database", "orm" ]
Python libraries to construct classes from a relational database? (ORM in reverse)
535,426
<p>Are there any Python object-relational mapping libraries that, given a database schema, can generate a set of Python classes? I know that the major libraries such as <a href="http://www.sqlobject.org/" rel="nofollow">SQLObject</a>, <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, and <a href="http...
3
2009-02-11T04:22:19Z
535,451
<p><a href="http://www.aminus.net/geniusql" rel="nofollow">Geniusql</a> (and <a href="http://www.aminus.net/dejavu" rel="nofollow">Dejavu</a>, its big federated brother) can do that quite well. See "<a href="http://www.aminus.net/geniusql/chrome/common/doc/trunk/modeling.html" rel="nofollow">Automatic Table Classes</a>...
3
2009-02-11T04:40:16Z
[ "python", "database", "orm" ]
Python libraries to construct classes from a relational database? (ORM in reverse)
535,426
<p>Are there any Python object-relational mapping libraries that, given a database schema, can generate a set of Python classes? I know that the major libraries such as <a href="http://www.sqlobject.org/" rel="nofollow">SQLObject</a>, <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, and <a href="http...
3
2009-02-11T04:22:19Z
535,498
<p>Django had an <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb" rel="nofollow">inspectdb</a> command that creates models.py files out of your database.</p>
6
2009-02-11T05:07:00Z
[ "python", "database", "orm" ]
Python libraries to construct classes from a relational database? (ORM in reverse)
535,426
<p>Are there any Python object-relational mapping libraries that, given a database schema, can generate a set of Python classes? I know that the major libraries such as <a href="http://www.sqlobject.org/" rel="nofollow">SQLObject</a>, <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, and <a href="http...
3
2009-02-11T04:22:19Z
535,536
<p>SQLAlchemy can actually do what you want. You can either define the mappings yourself manually using the mapper facility, or auto-generate them using <a href="http://www.sqlalchemy.org/docs/05/metadata.html#reflecting-tables">reflection</a>.</p> <p>It's not absolutely necessary to build the database using the metad...
5
2009-02-11T05:31:21Z
[ "python", "database", "orm" ]
How can I create a tag in Jinja that contains values from later in the template?
535,743
<p>I'm using Jinja2, and I'm trying to create a couple tags that work together, such that if I have a template that looks something like this:</p> <pre><code>{{ my_summary() }} ... arbitrary HTML ... {{ my_values('Tom', 'Dick', 'Harry') }} ... arbitrary HTML ... {{ my_values('Fred', 'Barney') }} </code></pre> <p>I'd ...
3
2009-02-11T07:12:34Z
536,315
<p>Disclaimer: I do not know Jinja.</p> <p>My guess is that you cannot (easily) accomplish this.</p> <p>I would suggest the following alternative:</p> <ul> <li>Pass the Tom, Dick, etc. values as variables to the template from the outside.</li> <li>Let your custom tags take the values as arguments.</li> <li>I do not ...
4
2009-02-11T10:55:22Z
[ "python", "templating", "jinja2" ]
python sleep == IDE lock up
535,973
<p>When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing </p> <pre><code>for i in range(0, timeInSeconds): time.sleep(1) </code></pr...
1
2009-02-11T08:57:38Z
536,024
<p>I'm assuming you are running your code from within the IDE?</p> <p>Your IDE is probably blocking while running your code. Look for a setting of some sort which might control that behaviour, otherwise I think your only choice would be to change IDE. (Or, run your code from outside the IDE)</p>
2
2009-02-11T09:10:55Z
[ "python", "ide", "lockup" ]
python sleep == IDE lock up
535,973
<p>When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing </p> <pre><code>for i in range(0, timeInSeconds): time.sleep(1) </code></pr...
1
2009-02-11T08:57:38Z
536,041
<p>Can you configure to run your script externally? I don't know about the specific IDEs, but I would try to spawn a different process for the debugged script and not run them under the IDE. If that doesn't help, then it is a problem of the IDEs.</p>
0
2009-02-11T09:16:57Z
[ "python", "ide", "lockup" ]
python sleep == IDE lock up
535,973
<p>When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing </p> <pre><code>for i in range(0, timeInSeconds): time.sleep(1) </code></pr...
1
2009-02-11T08:57:38Z
536,054
<p>The problem is your IDE not python. I don't use sleep that often, I've just tried it on the <a href="http://eric-ide.python-projects.org/" rel="nofollow">Eric IDE</a> and you can <em>use</em> your IDE while your code is running, and sleeping. If can't set your IDE to do so and you need it then consider to change IDE...
0
2009-02-11T09:19:59Z
[ "python", "ide", "lockup" ]
python sleep == IDE lock up
535,973
<p>When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing </p> <pre><code>for i in range(0, timeInSeconds): time.sleep(1) </code></pr...
1
2009-02-11T08:57:38Z
536,924
<p>Personally, I think you should never ever ever execute code in the same loop as your IDE. Since most IDEs run a GUI mainloop, blocking this will cause complete freeze of the user interface. It is just asking for trouble, and I would take out bug reports against both those IDEs.</p>
0
2009-02-11T14:05:59Z
[ "python", "ide", "lockup" ]
python sleep == IDE lock up
535,973
<p>When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing </p> <pre><code>for i in range(0, timeInSeconds): time.sleep(1) </code></pr...
1
2009-02-11T08:57:38Z
544,395
<p>I suspect the problem the IDE is sitting in a loop waiting for the script to finish. </p> <p>That in itself is not a problem, provided any user generated messages are still processed while the IDE is in this loop. </p> <p>But what I suspect is going wrong in this case is the IDE is just running the loop without pr...
0
2009-02-13T01:38:46Z
[ "python", "ide", "lockup" ]