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 |
|---|---|---|---|---|---|---|---|---|---|
How does one do the equivalent of "import * from module" with Python's __import__ function? | 147,507 | <p>Given a string with a module name, how do you import everything in the module as if you had called:</p>
<pre><code>from module import *
</code></pre>
<p>i.e. given string S="module", how does one get the equivalent of the following:</p>
<pre><code>__import__(S, fromlist="*")
</code></pre>
<p>This doesn't seem to... | 14 | 2008-09-29T04:28:41Z | 1,350,959 | <p>It appears that you can also use <strong>dict.update()</strong> on module's dictionaries in your case:</p>
<pre><code>config = [__import__(name) for name in names_list]
options = {}
for conf in config:
options.update(conf.__dict__)
</code></pre>
<p><strong>Update:</strong> I think there's a short "functional"... | 1 | 2009-08-29T09:30:01Z | [
"python",
"python-import"
] |
How does one do the equivalent of "import * from module" with Python's __import__ function? | 147,507 | <p>Given a string with a module name, how do you import everything in the module as if you had called:</p>
<pre><code>from module import *
</code></pre>
<p>i.e. given string S="module", how does one get the equivalent of the following:</p>
<pre><code>__import__(S, fromlist="*")
</code></pre>
<p>This doesn't seem to... | 14 | 2008-09-29T04:28:41Z | 3,286,758 | <p>Here's my solution for dynamic naming of local settings files for Django. Note the addition below of a check to not include attributes containing '__' from the imported file. The <code>__name__</code> global was being overwritten with the module name of the local settings file, which caused <code>setup_environ()</... | 5 | 2010-07-20T03:16:33Z | [
"python",
"python-import"
] |
Django VMware appliance | 147,627 | <p>Does anyone know of a Django 1.0 + postgresql + apache + mod_python VMware appliance? A "vanilla" Django 1.0 appliance where postgresql can be installed manually would also do.</p>
| 4 | 2008-09-29T05:25:00Z | 147,687 | <p>Configure and build your appliance at <a href="https://elasticserver.com/" rel="nofollow">Elastic Server On-Demand</a>.</p>
| 6 | 2008-09-29T06:11:05Z | [
"python",
"django",
"vmware"
] |
Django VMware appliance | 147,627 | <p>Does anyone know of a Django 1.0 + postgresql + apache + mod_python VMware appliance? A "vanilla" Django 1.0 appliance where postgresql can be installed manually would also do.</p>
| 4 | 2008-09-29T05:25:00Z | 147,748 | <p>It might be a little too heavy for your requirements, but all of those items (and a whole lot more) are included in the <a href="http://www.vmware.com/appliances/directory/289" rel="nofollow">Python Web Developer Appliance</a>.</p>
| 0 | 2008-09-29T06:51:08Z | [
"python",
"django",
"vmware"
] |
Django VMware appliance | 147,627 | <p>Does anyone know of a Django 1.0 + postgresql + apache + mod_python VMware appliance? A "vanilla" Django 1.0 appliance where postgresql can be installed manually would also do.</p>
| 4 | 2008-09-29T05:25:00Z | 149,688 | <p>Poulsenj is right the <a href="http://es.cohesiveft.com/" rel="nofollow">Elastic Server On-Demand</a> (<a href="http://es.cohesiveft.com/site/django" rel="nofollow">Django Elastic Server Site</a>) is a great place to configure and download a free custom Django VMware image in minutes.</p>
<p>The Elastic Server plat... | 0 | 2008-09-29T17:08:15Z | [
"python",
"django",
"vmware"
] |
Django VMware appliance | 147,627 | <p>Does anyone know of a Django 1.0 + postgresql + apache + mod_python VMware appliance? A "vanilla" Django 1.0 appliance where postgresql can be installed manually would also do.</p>
| 4 | 2008-09-29T05:25:00Z | 968,145 | <p>Another option I've had moderate success with</p>
<p><a href="http://www.turnkeylinux.org/appliances/django" rel="nofollow">TurnKey Linux Django Appliance</a></p>
| 2 | 2009-06-09T04:33:13Z | [
"python",
"django",
"vmware"
] |
Django VMware appliance | 147,627 | <p>Does anyone know of a Django 1.0 + postgresql + apache + mod_python VMware appliance? A "vanilla" Django 1.0 appliance where postgresql can be installed manually would also do.</p>
| 4 | 2008-09-29T05:25:00Z | 6,846,658 | <p>In addition to the other appliances suggested, you may want to take a look at our <a href="http://bitnami.org/stack/djangostack" rel="nofollow">BitNami Django Stack</a> VMWare Appliance.</p>
<p>It is completely free and we keep it up to date, often within hours of each new Django release. In particular, it includes... | 2 | 2011-07-27T15:07:12Z | [
"python",
"django",
"vmware"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 147,768 | <p>Create a new launch configuration (Python Run)</p>
<p><strong>Main tab</strong></p>
<p>Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory)</p>
<p>Don't forget to add the root folder of your application in the PYTHONPATH zone</p>
<p><strong>Argu... | 10 | 2008-09-29T07:03:33Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 1,306,122 | <p>yanjost has it right, just wanted to add that you need to make sure you do not use the --reload option, this will prevent the debugger from properly attaching itself and cause your breakpoints not to work. Just a little thing I ran in to.</p>
| 2 | 2009-08-20T13:17:28Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 2,958,194 | <p>On linux that will probably be /usr/bin/paster or /usr/local/bin/paster for paste script, and for arguments i have: serve ${workspace_loc}${project_path}/development.ini</p>
| 1 | 2010-06-02T13:36:44Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 3,817,880 | <p>I was able to get --reload working by changing the 'Working directory' in the arguments tab to not use default (i.e. select 'Other'->File System->'Root of your Pylons' app where development.ini is stored.</p>
| 2 | 2010-09-29T00:01:12Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 4,467,129 | <p>I also got this working (finally). I used buildout instead of virtualenv to install pylons (instructions at: <a href="http://wiki.pylonshq.com/display/pylonscommunity/Howto+install+Pylons+with+buildout" rel="nofollow">http://wiki.pylonshq.com/display/pylonscommunity/Howto+install+Pylons+with+buildout</a>), so the i... | 1 | 2010-12-17T02:14:05Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 4,618,535 | <p>If you'd rather not include your Python installation in your project's workspace to get paster, you can create a pure-Python driver like:</p>
<pre><code>#!/usr/bin/env python
from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])
</code></pre>
<p>...and run/debug that in Eclip... | 6 | 2011-01-06T18:47:21Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
Debug Pylons application through Eclipse | 147,650 | <p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
| 11 | 2008-09-29T05:41:00Z | 5,829,836 | <p>This doesn't really answer question about how to do it in eclipse. But I've been debugging paster server with winpdb, which is quite nice graphical python debugger (you can install it with easy_install winpdb). </p>
<p>Just start your server e.g.:</p>
<pre><code>winpdb /usr/local/bin/paster serve development.ini
<... | 0 | 2011-04-29T08:34:12Z | [
"python",
"eclipse",
"pylons",
"pydev",
"pyramid"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 147,716 | <pre><code>value = 0xdeadbeef
value &= ~(1<<10)
</code></pre>
| 11 | 2008-09-29T06:34:18Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 147,718 | <p>Have you tried copying and pasting your code into the Python REPL to see what will happen?</p>
<pre><code>>>> value = 0xdeadbeef
>>> value &= ~(1<<10)
>>> hex (value)
'0xdeadbaef'
</code></pre>
| 3 | 2008-09-29T06:34:41Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 147,721 | <p>Omit the 'unsigned long', and the semi-colons are not needed either:</p>
<pre><code>value = 0xDEADBEEF
value &= ~(1<<10)
print value
"0x%08X" % value
</code></pre>
| 3 | 2008-09-29T06:35:58Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 147,722 | <p>Python has C style bit manipulation operators, so your example is literally the same in Python except without type keywords.</p>
<pre><code>value = 0xdeadbeef
value &= ~(1 << 10)
</code></pre>
| 3 | 2008-09-29T06:36:01Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 147,736 | <p>Bitwise operations on Python ints work much like in C. The &, | and ^ operators in Python work just like in C. The ~ operator works as for a signed integer in C; that is, ~x computes -x-1.</p>
<p>You have to be somewhat careful with left shifts, since Python integers aren't fixed-width. Use bit masks to obtain ... | 36 | 2008-09-29T06:45:34Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 150,411 | <p>If you're going to do a lot of bit manipulation ( and you care much more about readability rather than performance for your application ) then you may want to create an integer wrapper to enable slicing like in Verilog or VHDL:</p>
<pre>
import math
class BitVector:
def __init__(self,val):
self._val... | 0 | 2008-09-29T20:05:16Z | [
"python"
] |
How do I manipulate bits in Python? | 147,713 | <p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| 24 | 2008-09-29T06:31:27Z | 152,035 | <p>You should also check out <a href="http://pypi.python.org/pypi/bitarray/0.2.3" rel="nofollow">BitArray</a>, which is a nice interface for dealing with sequences of bits.</p>
| 4 | 2008-09-30T07:04:17Z | [
"python"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,751 | <p>Actually, U+2018 is the Unicode representation of the special character â . If you want, you can convert instances of that character to U+0027 with this code:</p>
<pre><code>text = text.replace (u"\u2018", "'")
</code></pre>
<p>In addition, what are you using to write the file? <code>f1.read()</code> should retu... | 2 | 2008-09-29T06:52:53Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,755 | <p>This is Pythons way do show you unicode encoded strings. But i think you should be able to print the string on the screen or write it into a new file without any problems.</p>
<pre><code>>>> test = u"I don\u2018t like this"
>>> test
u'I don\u2018t like this'
>>> print test
I donât like ... | 1 | 2008-09-29T06:54:22Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,756 | <p>Ref: <a href="http://docs.python.org/howto/unicode">http://docs.python.org/howto/unicode</a></p>
<p><em>Reading Unicode from a file is therefore simple:</em></p>
<pre><code>import codecs
f = codecs.open('unicode.rst', encoding='utf-8')
for line in f:
print repr(line)
</code></pre>
<p><em>It's also possible to... | 87 | 2008-09-29T06:55:23Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,762 | <p>But it really is "I don\u2018t like this" and not "I don't like this". The character u'\u2018' is a completely different character than "'" (and, visually, should correspond more to '`').</p>
<p>If you're trying to convert encoded unicode into plain ASCII, you could perhaps keep a mapping of unicode punctuation tha... | 5 | 2008-09-29T07:00:40Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,790 | <p>There are a few points to consider.</p>
<p>A \u2018 character may appear only as a fragment of representation of a unicode string in Python, e.g. if you write:</p>
<pre><code>>>> text = u'â'
>>> print repr(text)
u'\u2018'
</code></pre>
<p>Now if you simply want to print the unicode string pret... | 8 | 2008-09-29T07:15:17Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 147,799 | <p>There is a possibility that somehow you have a non-unicode string with unicode escape characters, e.g.:</p>
<pre><code>>>> print repr(text)
'I don\\u2018t like this'
</code></pre>
<p>This actually happened to me once before. You can use a <code>unicode_escape</code> codec to decode the string to unicode a... | 1 | 2008-09-29T07:22:21Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
Character reading from file in Python | 147,741 | <p>In a text file, there is a string "I don't like this".</p>
<p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p>
<pre><code>f1 = open (file1, "r")
text = f1.read()
</code></pre>
<p>command to do the reading.</... | 60 | 2008-09-29T06:47:47Z | 154,782 | <p>Leaving aside the fact that your text file is broken (U+2018 is a left quotation mark, not an apostrophe): iconv can be used to transliterate unicode characters to ascii.</p>
<p>You'll have to google for "iconvcodec", since the module seems not to be supported anymore and I can't find a canonical home page for it.<... | 3 | 2008-09-30T20:10:54Z | [
"python",
"unicode",
"encoding",
"ascii"
] |
In Django is there a way to display choices as checkboxes? | 147,752 | <p>In the admin interface and newforms there is the brilliant helper of being able to define choices. You can use code like this:</p>
<pre><code>APPROVAL_CHOICES = (
('yes', 'Yes'),
('no', 'No'),
('cancelled', 'Cancelled'),
)
client_approved = models.CharField(choices=APPROVAL_CHOICES)
</code></pre>
<p>t... | 36 | 2008-09-29T06:53:13Z | 147,793 | <p>In terms of the forms library, you would use the <a href="http://docs.djangoproject.com/en/dev/ref/forms/fields/#multiplechoicefield">MultipleChoiceField</a> field with a <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.CheckboxSelectMultiple">CheckboxSelectMultiple</a> widget to do that... | 66 | 2008-09-29T07:17:46Z | [
"python",
"django"
] |
In Django is there a way to display choices as checkboxes? | 147,752 | <p>In the admin interface and newforms there is the brilliant helper of being able to define choices. You can use code like this:</p>
<pre><code>APPROVAL_CHOICES = (
('yes', 'Yes'),
('no', 'No'),
('cancelled', 'Cancelled'),
)
client_approved = models.CharField(choices=APPROVAL_CHOICES)
</code></pre>
<p>t... | 36 | 2008-09-29T06:53:13Z | 33,897,601 | <p>@JonnyBuchanan gave the right answer.</p>
<p>But if you need this in the django admin for many models, and you're (like me) too lazy to customize a ModelForm and ovverride the right methods inside the ModelAdmin class, you can use this approach:</p>
<p><a href="http://www.abidibo.net/blog/2013/04/10/convert-select... | 0 | 2015-11-24T15:29:37Z | [
"python",
"django"
] |
Preserving signatures of decorated functions | 147,816 | <p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p>
<p>Here is an example:</p>
<pre><code>def args_as_ints(f):
def g(*args, **kwargs):
args = [int(x) for x in args]
... | 71 | 2008-09-29T07:32:55Z | 147,835 | <p>Take a look at the <a href="http://www.phyast.pitt.edu/~micheles/python/documentation.html">decorator</a> module - specifically the <a href="http://www.phyast.pitt.edu/~micheles/python/documentation.html#decorator-is-a-decorator">decorator</a> decorator, which solves this problem.</p>
| 7 | 2008-09-29T07:43:19Z | [
"python",
"decorator"
] |
Preserving signatures of decorated functions | 147,816 | <p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p>
<p>Here is an example:</p>
<pre><code>def args_as_ints(f):
def g(*args, **kwargs):
args = [int(x) for x in args]
... | 71 | 2008-09-29T07:32:55Z | 147,844 | <p>There is a <a href="http://www.phyast.pitt.edu/~micheles/python/documentation.html">decorator module</a> with <code>decorator</code> decorator you can use:</p>
<pre><code>@decorator
def args_as_ints(f, *args, **kwargs):
args = [int(x) for x in args]
kwargs = dict((k, int(v)) for k, v in kwargs.items())
... | 8 | 2008-09-29T07:49:23Z | [
"python",
"decorator"
] |
Preserving signatures of decorated functions | 147,816 | <p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p>
<p>Here is an example:</p>
<pre><code>def args_as_ints(f):
def g(*args, **kwargs):
args = [int(x) for x in args]
... | 71 | 2008-09-29T07:32:55Z | 147,878 | <ol>
<li><p>Install <a href="http://www.phyast.pitt.edu/~micheles/python/documentation.html#the-solution">decorator</a> module:</p>
<pre><code>$ pip install decorator
</code></pre></li>
<li><p>Adapt definition of <code>args_as_ints()</code>:</p>
<pre><code>import decorator
@decorator.decorator
def args_as_ints(f, *a... | 50 | 2008-09-29T08:08:30Z | [
"python",
"decorator"
] |
Preserving signatures of decorated functions | 147,816 | <p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p>
<p>Here is an example:</p>
<pre><code>def args_as_ints(f):
def g(*args, **kwargs):
args = [int(x) for x in args]
... | 71 | 2008-09-29T07:32:55Z | 25,555,400 | <p>Second option:</p>
<ol>
<li>Install wrapt module:</li>
</ol>
<p>$ easy_install wrapt</p>
<p>wrapt have a bonus, preserve class signature.</p>
<p><pre><code>
import wrapt
import inspect</p>
@wrapt.decorator
def args_as_ints(wrapped, instance, args, kwargs):
if instance is None:
if inspect.isclass(wra... | 6 | 2014-08-28T18:15:30Z | [
"python",
"decorator"
] |
Preserving signatures of decorated functions | 147,816 | <p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p>
<p>Here is an example:</p>
<pre><code>def args_as_ints(f):
def g(*args, **kwargs):
args = [int(x) for x in args]
... | 71 | 2008-09-29T07:32:55Z | 31,540,540 | <p>This is solved with Python's standard library <code>functools</code> and specifically <a href="https://docs.python.org/3.5/library/functools.html#functools.wraps" rel="nofollow"><code>functools.wraps</code></a> function, which is designed to "<em>update a wrapper function to look like the wrapped function</em>". It'... | 6 | 2015-07-21T13:31:45Z | [
"python",
"decorator"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 148,048 | <pre><code>if job in ("mechanic", "tech"):
print "awesome"
elif job in ("tool", "rock"):
print "dolt"
</code></pre>
<p>The values in parentheses are a tuple. The <code>in</code> operator checks to see whether the left hand side item occurs somewhere inside the right handle tuple.</p>
<p>Note that when Python ... | 23 | 2008-09-29T09:13:53Z | [
"python",
"comparison",
"boolean"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 148,049 | <pre><code>if job in ("mechanic", "tech"):
print "awesome"
elif job in ("tool", "rock"):
print "dolt"
</code></pre>
| 1 | 2008-09-29T09:14:14Z | [
"python",
"comparison",
"boolean"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 148,050 | <p>While I don't think you can do what you want directly, one alternative is:</p>
<pre><code>if job in [ "mechanic", "tech" ]:
print "awesome"
elif job in [ "tool", "rock" ]:
print "dolt"
</code></pre>
| 1 | 2008-09-29T09:14:18Z | [
"python",
"comparison",
"boolean"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 148,052 | <p>In other languages I'd use a switch/select statement to get the job done. <a href="http://simonwillison.net/2004/May/7/switch/" rel="nofollow">You can do that in python too</a>.</p>
| 0 | 2008-09-29T09:14:54Z | [
"python",
"comparison",
"boolean"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 148,055 | <p>You can use in:</p>
<pre><code>if job in ["mechanic", "tech"]:
print "awesome"
</code></pre>
<p>When checking very large numbers, it may also be worth storing off a set of the items to check, as this will be faster. Eg.</p>
<pre><code>AwesomeJobs = set(["mechanic", "tech", ... lots of others ])
...
def fun... | 3 | 2008-09-29T09:15:53Z | [
"python",
"comparison",
"boolean"
] |
Using OR comparisons with IF statements | 148,042 | <p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p>
<pre><code>if job == "mechanic" or job == "tech":
print "awesome"
elif job == "tool" or job == "rock":
print "dolt"
</code></pre>
<p>Is there a way to make Python accept multiple values when c... | 3 | 2008-09-29T09:12:24Z | 149,493 | <p>Tuples with constant items are stored themselves as constants in the compiled function. They can be loaded with a single instruction. Lists and sets on the other hand, are always constructed anew on each execution.</p>
<p>Both tuples and lists use linear search for the in-operator. Sets uses a hash-based look-up, s... | 1 | 2008-09-29T16:31:06Z | [
"python",
"comparison",
"boolean"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 148,891 | <p>This ActiveState Python recipe might be helpful:
<a href="http://code.activestate.com/recipes/491261/" rel="nofollow">http://code.activestate.com/recipes/491261/</a></p>
| 7 | 2008-09-29T14:25:07Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 149,145 | <p>If you don't mind working at a slightly lower level, httplib2 (<a href="http://code.google.com/p/httplib2/">http://code.google.com/p/httplib2/</a>) is an excellent HTTP library that includes caching functionality.</p>
| 8 | 2008-09-29T15:21:56Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 149,917 | <p>You could use a decorator function such as:</p>
<pre><code>class cache(object):
def __init__(self, fun):
self.fun = fun
self.cache = {}
def __call__(self, *args, **kwargs):
key = str(args) + str(kwargs)
try:
return self.cache[key]
except KeyError:
... | 7 | 2008-09-29T18:03:38Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 549,017 | <p>I was looking for something similar, and came across <a href="http://code.activestate.com/recipes/491261/" rel="nofollow">"Recipe 491261: Caching and throttling for urllib2"</a> which danivo posted. The problem is I <em>really</em> dislike the caching code (lots of duplication, lots of manually joining of file paths... | 3 | 2009-02-14T12:05:00Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 1,591,937 | <p>This article on Yahoo Developer Network - <a href="http://developer.yahoo.com/python/python-caching.html" rel="nofollow">http://developer.yahoo.com/python/python-caching.html</a> - describes how to cache http calls made through urllib to either memory or disk.</p>
| 2 | 2009-10-20T00:57:45Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 4,138,778 | <p>I've always been torn between using httplib2, which does a solid job of handling HTTP caching and authentication, and urllib2, which is in the stdlib, has an extensible interface, and supports HTTP Proxy servers.</p>
<p>The <a href="http://code.activestate.com/recipes/491261/">ActiveState recipe</a> starts to add c... | 5 | 2010-11-09T21:22:44Z | [
"python",
"caching",
"urllib2"
] |
Caching in urllib2? | 148,853 | <p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
| 11 | 2008-09-29T14:17:13Z | 4,379,976 | <p>@dbr: you may need to add also https responses caching with :</p>
<pre><code>def https_response(self, request, response):
return self.http_response(request,response)
</code></pre>
| 1 | 2010-12-07T18:03:29Z | [
"python",
"caching",
"urllib2"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 148,979 | <p>Threads. They're what I always go for because you can do it in every framework you need. </p>
<p>And once you're used to multi-threading and parallel processing in one language/framework, you're good on all frameworks.</p>
| 15 | 2008-09-29T14:40:08Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,006 | <p>Working with Qt/C++ for Win32.</p>
<p>We divide the major work units into different processes. The GUI runs as a separate process and is able to command/receive data from the "worker" processes as needed. Works nicely in todays multi-core world.</p>
| 0 | 2008-09-29T14:45:16Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,017 | <p>Threads or processes depending on the application. Sometimes it's actually best to have the GUI be it's own program and just send asynchronous calls to other programs when it has work to do. You'll still end up having multiple threads in the GUI to monitor for results, but it can simplify things if the work being ... | 1 | 2008-09-29T14:47:14Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,123 | <p>This answer doesn't apply to the OP's question regarding Python, but is more of a meta-response.</p>
<p>The easy way is threads. However, not every platform has pre-emptive threading (e.g. BREW, some other embedded systems) If possibly, simply chunk the work and do it in the IDLE event handler.</p>
<p>Another prob... | 0 | 2008-09-29T15:17:27Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,125 | <p>I use threads so the GUI's main event loop never blocks.</p>
| 0 | 2008-09-29T15:17:47Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,138 | <p>For some types of operations, using separate processes makes a lot of sense. Back in the day, spawning a process incurred a lot of overhead. With modern hardware this overhead is hardly even a blip on the screen. This is especially true if you're spawning a long running process.</p>
<p>One (arguable) advantage is t... | 0 | 2008-09-29T15:20:07Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 149,212 | <p>Definitely threads. Why? The future is multi-core. Almost any new CPU has more than one core or if it has just one, it might support hyperthreading and thus pretending it has more than one. To effectively make use of multi-core CPUs (and Intel is planing to go up to 32 cores in the not so far future), you need multi... | 7 | 2008-09-29T15:34:33Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 150,112 | <p>Threads -
Let's use a simple 2-layer view (GUI, application logic).</p>
<p>The application logic work should be done in a separate Python thread. For Asynchronous events that need to propagate up to the GUI layer, use wx's event system to post custom events. Posting wx events is thread safe so you could conceivab... | 1 | 2008-09-29T18:53:30Z | [
"python",
"user-interface",
"wxpython"
] |
Keeping GUIs responsive during long-running tasks | 148,963 | <p>Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.</p>
<p><a href="http://wiki.wxpython.org/LongRunningTasks">Here's a good discussion</a> of how to do this in wxPython. To summarize, there are 3 ways:</p>
<ol>
<li>Use threads</li>... | 11 | 2008-09-29T14:37:32Z | 378,778 | <p>I think <code>delayedresult</code> is what you are looking for:</p>
<p><a href="http://www.wxpython.org/docs/api/wx.lib.delayedresult-module.html" rel="nofollow">http://www.wxpython.org/docs/api/wx.lib.delayedresult-module.html</a></p>
<p>See the wxpython demo for an example.</p>
| 2 | 2008-12-18T18:40:36Z | [
"python",
"user-interface",
"wxpython"
] |
Is there a way to define which fields in the model are editable in the admin app? | 149,040 | <p>Assume the following:</p>
<p><em>models.py</em></p>
<pre><code>class Entry(models.Model):
title = models.CharField(max_length=50)
slug = models.CharField(max_length=50, unique=True)
body = models.CharField(max_length=200)
</code></pre>
<p><em>admin.py</em></p>
<pre><code>class EntryAdmin(admin.ModelA... | 3 | 2008-09-29T14:55:55Z | 149,067 | <p>I'm not sure what you're asking for IS possible. Your best bet is probably to hide the slug from the admin interface completely by specifying your fieldsets, and than overriding the save method to copy the slug from the tile, and potentially slugifying it...</p>
| 0 | 2008-09-29T15:04:04Z | [
"python",
"django"
] |
Is there a way to define which fields in the model are editable in the admin app? | 149,040 | <p>Assume the following:</p>
<p><em>models.py</em></p>
<pre><code>class Entry(models.Model):
title = models.CharField(max_length=50)
slug = models.CharField(max_length=50, unique=True)
body = models.CharField(max_length=200)
</code></pre>
<p><em>admin.py</em></p>
<pre><code>class EntryAdmin(admin.ModelA... | 3 | 2008-09-29T14:55:55Z | 149,176 | <p>This <a href="http://www.djangosnippets.org/snippets/937/" rel="nofollow">Django Snippet</a> does what you want by defining a custom Read-Only Widget. So you define a custom editor for the field which in fact doesn't allow any editing.</p>
| 0 | 2008-09-29T15:27:55Z | [
"python",
"django"
] |
Is there a way to define which fields in the model are editable in the admin app? | 149,040 | <p>Assume the following:</p>
<p><em>models.py</em></p>
<pre><code>class Entry(models.Model):
title = models.CharField(max_length=50)
slug = models.CharField(max_length=50, unique=True)
body = models.CharField(max_length=200)
</code></pre>
<p><em>admin.py</em></p>
<pre><code>class EntryAdmin(admin.ModelA... | 3 | 2008-09-29T14:55:55Z | 149,295 | <p>For this particular case you can override your save method to slugify (it's built-in method, look at django source) the title and store it in slug field. Also from there you can easily check if this slug is indeed unique and change it somehow if it's not.</p>
<p>Consider this example:</p>
<pre><code>def save(self)... | 3 | 2008-09-29T15:47:49Z | [
"python",
"django"
] |
Is there a way to define which fields in the model are editable in the admin app? | 149,040 | <p>Assume the following:</p>
<p><em>models.py</em></p>
<pre><code>class Entry(models.Model):
title = models.CharField(max_length=50)
slug = models.CharField(max_length=50, unique=True)
body = models.CharField(max_length=200)
</code></pre>
<p><em>admin.py</em></p>
<pre><code>class EntryAdmin(admin.ModelA... | 3 | 2008-09-29T14:55:55Z | 150,229 | <p><a href="http://www.djangosnippets.org/snippets/770/" rel="nofollow">This snippet</a> gives you an AutoSlugField with exactly the behavior you are seeking, and adding it to your model is a one-liner.</p>
| 0 | 2008-09-29T19:20:53Z | [
"python",
"django"
] |
Is there a way to define which fields in the model are editable in the admin app? | 149,040 | <p>Assume the following:</p>
<p><em>models.py</em></p>
<pre><code>class Entry(models.Model):
title = models.CharField(max_length=50)
slug = models.CharField(max_length=50, unique=True)
body = models.CharField(max_length=200)
</code></pre>
<p><em>admin.py</em></p>
<pre><code>class EntryAdmin(admin.ModelA... | 3 | 2008-09-29T14:55:55Z | 150,296 | <p>In addition to overriding <code>save</code> to provide the generated value you want, you can also use the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#exclude" rel="nofollow">exclude</a> option in your <code>ModelAdmin</code> class to prevent the field from being displayed in the admin:</p>
<pre... | 0 | 2008-09-29T19:36:30Z | [
"python",
"django"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 149,317 | <p>GAE is very useful tool to build scalable web applications. Few of the limitations pointed out by many are no support for background tasks, lack of periodic tasks and strict limit on how much time each HTTP request takes, if a request exceeds that time limit the operation is terminated, which makes running time cons... | 5 | 2008-09-29T15:51:15Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 520,685 | <p>Up and coming version of runtime will have some kind of periodic execution engine a'la cron. See <a href="http://groups.google.com/group/google-appengine/msg/9a94aaf4a3b9415f" rel="nofollow">this message</a> on AppEngine group.</p>
<blockquote>
<p>So, all the SDK pieces appear to work, but my testing indicates th... | 2 | 2009-02-06T15:20:34Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 1,030,325 | <p>You may use the <a href="http://code.google.com/appengine/docs/python/taskqueue/">Task Queue Python API</a>. </p>
| 12 | 2009-06-23T02:11:39Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 8,406,775 | <p>Use the Task Queue - <a href="http://code.google.com/appengine/docs/java/taskqueue/overview.html" rel="nofollow">http://code.google.com/appengine/docs/java/taskqueue/overview.html</a></p>
| -3 | 2011-12-06T21:00:49Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 9,588,809 | <p>If you want to run background periodic tasks, see <a href="http://stackoverflow.com/questions/145651/cron-jobs-on-google-appengine">this question</a> (AppEngine cron)</p>
<p>If your tasks are not periodic, see <a href="http://code.google.com/appengine/docs/python/taskqueue/" rel="nofollow">Task Queue Python API</a>... | 0 | 2012-03-06T17:28:21Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 13,182,947 | <p>You can find more about cron jobs in Python App Engine <a href="https://developers.google.com/appengine/docs/python/config/cron" rel="nofollow">here</a>.</p>
| 4 | 2012-11-01T18:03:30Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 18,238,995 | <p>There is a cron facility built into app engine.</p>
<p>Please refer to:
<a href="https://developers.google.com/appengine/docs/python/config/cron?hl=en" rel="nofollow">https://developers.google.com/appengine/docs/python/config/cron?hl=en</a></p>
| 0 | 2013-08-14T18:03:08Z | [
"python",
"google-app-engine",
"cron"
] |
Background tasks on appengine | 149,307 | <p>How to run background tasks on appengine ?</p>
| 6 | 2008-09-29T15:48:55Z | 35,063,902 | <p>Using the <a href="https://cloud.google.com/appengine/articles/deferred?hl=en" rel="nofollow">Deferred Python Library</a> is the easiest way of doing background task on Appengine using Python which is built on top of TaskQueue API.</p>
<pre><code>from google.appengine.ext import deferred
def do_something_expensive... | 1 | 2016-01-28T14:14:57Z | [
"python",
"google-app-engine",
"cron"
] |
Python desktop widgets | 149,559 | <p>I'm interested in making desktop widgets, similar to Apple's Dashboard or what Vista has. I'd like to make them cross-platform, if possible. Opera's widgets are cross-platform but require the user to have Opera installed, so that's a big limitation.</p>
<p>I know most widgets are made with HTML/XML, CSS, and Javasc... | 2 | 2008-09-29T16:44:21Z | 149,670 | <p>You can check out <a href="http://www.pygtk.org/" rel="nofollow">PyGTK</a>, which will allow you to create desktop widgets, but they won't be managed by OSX's Dashboard. If you'd like to <a href="http://developer.apple.com/macosx/dashboard.html" rel="nofollow">develop an OSX widget</a>, you'll want to stick with HT... | 0 | 2008-09-29T17:03:40Z | [
"python",
"desktop",
"widget"
] |
Python desktop widgets | 149,559 | <p>I'm interested in making desktop widgets, similar to Apple's Dashboard or what Vista has. I'd like to make them cross-platform, if possible. Opera's widgets are cross-platform but require the user to have Opera installed, so that's a big limitation.</p>
<p>I know most widgets are made with HTML/XML, CSS, and Javasc... | 2 | 2008-09-29T16:44:21Z | 149,678 | <p>Take a look at pyqt4. It has webkit integration. I was looking into this myself but haven't really had time to dig into the API.</p>
| 0 | 2008-09-29T17:05:28Z | [
"python",
"desktop",
"widget"
] |
Python desktop widgets | 149,559 | <p>I'm interested in making desktop widgets, similar to Apple's Dashboard or what Vista has. I'd like to make them cross-platform, if possible. Opera's widgets are cross-platform but require the user to have Opera installed, so that's a big limitation.</p>
<p>I know most widgets are made with HTML/XML, CSS, and Javasc... | 2 | 2008-09-29T16:44:21Z | 149,719 | <p>You should take a look at what the guys at <a href="http://www.digsby.com/" rel="nofollow">Digsby</a> are doing. Basically, they've written a port of <a href="http://wxwebkit.wxcommunity.com/" rel="nofollow">WebKit to wxWidgets</a>, and then use WebKit to render the interface, and wxPython for writing the rest of th... | 2 | 2008-09-29T17:16:59Z | [
"python",
"desktop",
"widget"
] |
Python desktop widgets | 149,559 | <p>I'm interested in making desktop widgets, similar to Apple's Dashboard or what Vista has. I'd like to make them cross-platform, if possible. Opera's widgets are cross-platform but require the user to have Opera installed, so that's a big limitation.</p>
<p>I know most widgets are made with HTML/XML, CSS, and Javasc... | 2 | 2008-09-29T16:44:21Z | 149,730 | <p>Take a look at <a href="http://www.gdesklets.de/" rel="nofollow">gDesklets</a>. AFAIK they're UNIX only, but mabybe porting them to other platforms make more sense than starting from scratch?</p>
<p>They use python to create widgets (desklets).</p>
| 1 | 2008-09-29T17:21:12Z | [
"python",
"desktop",
"widget"
] |
Python desktop widgets | 149,559 | <p>I'm interested in making desktop widgets, similar to Apple's Dashboard or what Vista has. I'd like to make them cross-platform, if possible. Opera's widgets are cross-platform but require the user to have Opera installed, so that's a big limitation.</p>
<p>I know most widgets are made with HTML/XML, CSS, and Javasc... | 2 | 2008-09-29T16:44:21Z | 28,597,138 | <p><a href="https://launchpad.net/screenlets" rel="nofollow">Screenlets</a> is designed for this task. </p>
<blockquote>
<p>The Screenlets project is both a Python framework to simplify writing Cairo-drawn desktop widgets, similar to those found in the "Dashboard" feature of OS:X.</p>
</blockquote>
<p>Widgets can b... | 0 | 2015-02-19T01:20:18Z | [
"python",
"desktop",
"widget"
] |
BeautifulSoup's Python 3 compatibility | 149,585 | <p>Does BeautifulSoup work with Python 3? </p>
<p>If not, how soon will there be a port? Will there be a port at all?</p>
<p>Google doesn't turn up anything to me (Maybe it's 'coz I'm looking for the wrong thing?)</p>
| 18 | 2008-09-29T16:49:50Z | 149,626 | <p>I'm guessing the answer is "No". According to <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">Python.org</a>:</p>
<blockquote>
<p>Python 3000 (a.k.a. "Py3k", and
released as Python 3.0) is a new
version of the language that is
incompatible with the 2.x line of
releases. The language... | 1 | 2008-09-29T16:57:57Z | [
"python",
"python-3.x",
"beautifulsoup",
"porting"
] |
BeautifulSoup's Python 3 compatibility | 149,585 | <p>Does BeautifulSoup work with Python 3? </p>
<p>If not, how soon will there be a port? Will there be a port at all?</p>
<p>Google doesn't turn up anything to me (Maybe it's 'coz I'm looking for the wrong thing?)</p>
| 18 | 2008-09-29T16:49:50Z | 156,569 | <p>There's a <a href="http://www.python.org/download/releases/3.0/" rel="nofollow">release candidate for Python 3.0</a> available, so you can always test BeautifulSoup's compatibility yourself :)</p>
| 2 | 2008-10-01T07:27:38Z | [
"python",
"python-3.x",
"beautifulsoup",
"porting"
] |
BeautifulSoup's Python 3 compatibility | 149,585 | <p>Does BeautifulSoup work with Python 3? </p>
<p>If not, how soon will there be a port? Will there be a port at all?</p>
<p>Google doesn't turn up anything to me (Maybe it's 'coz I'm looking for the wrong thing?)</p>
| 18 | 2008-09-29T16:49:50Z | 399,710 | <p>About two months after I asked this question, a port has been released:</p>
<p><a href="http://groups.google.com/group/beautifulsoup/browse_thread/thread/f24882cc17a0625e">http://groups.google.com/group/beautifulsoup/browse_thread/thread/f24882cc17a0625e</a></p>
<p>It'll bet BS working, but that's about it. Not ye... | 5 | 2008-12-30T07:19:47Z | [
"python",
"python-3.x",
"beautifulsoup",
"porting"
] |
BeautifulSoup's Python 3 compatibility | 149,585 | <p>Does BeautifulSoup work with Python 3? </p>
<p>If not, how soon will there be a port? Will there be a port at all?</p>
<p>Google doesn't turn up anything to me (Maybe it's 'coz I'm looking for the wrong thing?)</p>
| 18 | 2008-09-29T16:49:50Z | 1,833,048 | <p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">http://www.crummy.com/software/BeautifulSoup/</a> says:</p>
<blockquote>
<p>Download Beautiful Soup</p>
<p>If you're using Python 2.3 through
2.6, the 3.0 series is the best choice. The most recent release in the
3.0 series is 3.0.8, ... | 3 | 2009-12-02T13:54:42Z | [
"python",
"python-3.x",
"beautifulsoup",
"porting"
] |
BeautifulSoup's Python 3 compatibility | 149,585 | <p>Does BeautifulSoup work with Python 3? </p>
<p>If not, how soon will there be a port? Will there be a port at all?</p>
<p>Google doesn't turn up anything to me (Maybe it's 'coz I'm looking for the wrong thing?)</p>
| 18 | 2008-09-29T16:49:50Z | 9,906,160 | <p>Beautiful Soup <strong>4.x</strong> <a href="https://groups.google.com/forum/#!msg/beautifulsoup/VpNNflJ1rPI/sum07jmEwvgJ">officially supports Python 3.</a></p>
<pre><code>pip install beautifulsoup4
</code></pre>
| 17 | 2012-03-28T11:03:10Z | [
"python",
"python-3.x",
"beautifulsoup",
"porting"
] |
What is the difference between __reduce__ and __reduce_ex__? | 150,284 | <p>I understand that these methods are for pickling/unpickling and have no relation to the reduce built-in function, but what's the difference between the 2 and why do we need both?</p>
| 9 | 2008-09-29T19:31:50Z | 150,309 | <p><a href="https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types" rel="nofollow">The docs</a> say that </p>
<blockquote>
<p>If provided, at pickling time
<code>__reduce__()</code> will be called with no
arguments, and it must return either a
string or a tuple.</p>
</blockquote>... | 16 | 2008-09-29T19:41:37Z | [
"python",
"pickle"
] |
What is the difference between __reduce__ and __reduce_ex__? | 150,284 | <p>I understand that these methods are for pickling/unpickling and have no relation to the reduce built-in function, but what's the difference between the 2 and why do we need both?</p>
| 9 | 2008-09-29T19:31:50Z | 150,318 | <p><code>__reduce_ex__</code> is what <code>__reduce__</code> should have been but never became. <code>__reduce_ex__</code> works like <code>__reduce__</code> but the pickle protocol is passed.</p>
| 4 | 2008-09-29T19:42:58Z | [
"python",
"pickle"
] |
How do you break into the debugger from Python source code? | 150,375 | <p>What do you insert into Python source code to have it break into pdb (when execution gets to that spot)? </p>
| 19 | 2008-09-29T19:55:12Z | 150,376 | <pre><code>import pdb; pdb.set_trace()
</code></pre>
<p>See <a href="http://jjinux.blogspot.com/2007/08/python-coding-in-debugger-for-beginners.html">Python: Coding in the Debugger for Beginners</a> for this and more helpful hints.</p>
| 26 | 2008-09-29T19:55:20Z | [
"python",
"debugging",
"breakpoints",
"pdb"
] |
Send file using POST from a Python script | 150,517 | <p>This is an almost-duplicate of <a href="http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script">http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script</a>, but I'd like to add a caveat: I need something that properly handles the encoding of fields and attached ... | 7 | 2008-09-29T20:31:37Z | 151,642 | <p>Best thing I can think of is to encode it yourself. How about this subroutine?</p>
<pre><code>from urllib2 import Request, urlopen
from binascii import b2a_base64
def b64open(url, postdata):
req = Request(url, b2a_base64(postdata), headers={'Content-Transfer-Encoding': 'base64'})
return urlopen(req)
conn = b... | 5 | 2008-09-30T03:22:48Z | [
"python",
"encoding",
"post"
] |
Send file using POST from a Python script | 150,517 | <p>This is an almost-duplicate of <a href="http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script">http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script</a>, but I'd like to add a caveat: I need something that properly handles the encoding of fields and attached ... | 7 | 2008-09-29T20:31:37Z | 151,670 | <p>PyCURL provides an interface to CURL from Python.</p>
<p><a href="http://curl.haxx.se/libcurl/python/" rel="nofollow">http://curl.haxx.se/libcurl/python/</a></p>
<p>Curl will do all you need. It can transfer binary files properly, and supports many encodings. However, you have to make sure that the proper charac... | 1 | 2008-09-30T03:34:54Z | [
"python",
"encoding",
"post"
] |
Send file using POST from a Python script | 150,517 | <p>This is an almost-duplicate of <a href="http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script">http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script</a>, but I'd like to add a caveat: I need something that properly handles the encoding of fields and attached ... | 7 | 2008-09-29T20:31:37Z | 3,786,024 | <p>Just use this library and send in files.</p>
<p><a href="http://github.com/seisen/urllib2_file/" rel="nofollow">http://github.com/seisen/urllib2_file/</a></p>
| 1 | 2010-09-24T10:08:44Z | [
"python",
"encoding",
"post"
] |
How Does One Read Bytes from File in Python | 150,532 | <p>Similar to <a href="http://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python">this</a> question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python.</p>
<p>I first read all ten bytes into a string. I then want to pars... | 8 | 2008-09-29T20:37:34Z | 150,541 | <p>I was going to recommend the <code>struct</code> package but then you said you had tried it. Try this:</p>
<pre><code>self.major_version = struct.unpack('H', self.whole_string[3:5])
</code></pre>
<p>The <code>pack()</code> function convers Python data types to bits, and the <code>unpack()</code> function converts ... | 2 | 2008-09-29T20:40:45Z | [
"python",
"id3"
] |
How Does One Read Bytes from File in Python | 150,532 | <p>Similar to <a href="http://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python">this</a> question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python.</p>
<p>I first read all ten bytes into a string. I then want to pars... | 8 | 2008-09-29T20:37:34Z | 150,584 | <p>If you have a string, with 2 bytes that you wish to interpret as a 16 bit integer, you can do so by:</p>
<pre><code>>>> s = '\0\x02'
>>> struct.unpack('>H', s)
(2,)
</code></pre>
<p>Note that the > is for big-endian (the largest part of the integer comes first). This is the format id3 tags us... | 16 | 2008-09-29T20:50:20Z | [
"python",
"id3"
] |
How Does One Read Bytes from File in Python | 150,532 | <p>Similar to <a href="http://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python">this</a> question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python.</p>
<p>I first read all ten bytes into a string. I then want to pars... | 8 | 2008-09-29T20:37:34Z | 150,586 | <p>Why write your own? (Assuming you haven't checked out these other options.) There's a couple options out there for reading in ID3 tag info from MP3s in Python. Check out my <a href="http://stackoverflow.com/questions/8948/accessing-mp3-meta-data-with-python#102285">answer</a> over at <a href="http://stackoverflow... | 4 | 2008-09-29T20:50:23Z | [
"python",
"id3"
] |
How Does One Read Bytes from File in Python | 150,532 | <p>Similar to <a href="http://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python">this</a> question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python.</p>
<p>I first read all ten bytes into a string. I then want to pars... | 8 | 2008-09-29T20:37:34Z | 150,639 | <blockquote>
<p>I am trying to read in an ID3v2 tag header</p>
</blockquote>
<p>FWIW, there's <a href="http://id3-py.sourceforge.net/" rel="nofollow">already a module</a> for this.</p>
| 2 | 2008-09-29T21:00:56Z | [
"python",
"id3"
] |
Is there any Visual Library alternative to wxPython that supports CSS/Style Sheets? | 150,705 | <p>I've developed a program that extensively uses wxPython - the wxWindow port for python. </p>
<p>Even though it is as mature library it is still very primitive and very programming oriented. Which is time consuming and not flexible at all.</p>
<p>I would love to see if there is something like Flex/Action Script whe... | 1 | 2008-09-29T21:15:09Z | 150,724 | <p>You could try XUL, the language the Firefox GUI uses. It's XML styled with CSS and scripted with Javascript.</p>
<p><a href="http://www.mozilla.org/projects/xul/" rel="nofollow">http://www.mozilla.org/projects/xul/</a><br />
<a href="http://en.wikipedia.org/wiki/XUL" rel="nofollow">http://en.wikipedia.org/wiki/XUL... | 1 | 2008-09-29T21:18:59Z | [
"python",
"wxpython"
] |
Is there any Visual Library alternative to wxPython that supports CSS/Style Sheets? | 150,705 | <p>I've developed a program that extensively uses wxPython - the wxWindow port for python. </p>
<p>Even though it is as mature library it is still very primitive and very programming oriented. Which is time consuming and not flexible at all.</p>
<p>I would love to see if there is something like Flex/Action Script whe... | 1 | 2008-09-29T21:15:09Z | 150,732 | <p><a href="http://wiki.python.org/moin/PyQt" rel="nofollow">PyQt</a> with <a href="http://doc.trolltech.com/4.4/stylesheet.html" rel="nofollow">Qt style sheets</a> might be a good fit. Naturally, you'd need to re-write quite a bit of your GUI layer for the toolkit change.</p>
| 4 | 2008-09-29T21:19:38Z | [
"python",
"wxpython"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 151,211 | <p>If you have two date objects, you can just subtract them.</p>
<pre><code>from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d0 - d1
print delta.days
</code></pre>
<p>The relevant section of the docs:
<a href="https://docs.python.org/library/datetime.html">https://docs.python.org/libra... | 301 | 2008-09-29T23:41:22Z | [
"python",
"date"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 151,212 | <p>Using the power of datetime:</p>
<pre><code>from datetime import datetime
date_format = "%m/%d/%Y"
a = datetime.strptime('8/18/2008', date_format)
b = datetime.strptime('9/26/2008', date_format)
delta = b - a
print delta.days # that's it
</code></pre>
| 55 | 2008-09-29T23:41:59Z | [
"python",
"date"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 151,214 | <p>Days until Christmas:</p>
<pre><code>>>> import datetime
>>> today = datetime.date.today()
>>> someday = datetime.date(2008, 12, 25)
>>> diff = someday - today
>>> diff.days
86
</code></pre>
<p>More arithmetic <a href="https://web.archive.org/web/20061007015511/http://w... | 15 | 2008-09-29T23:43:01Z | [
"python",
"date"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 151,215 | <p>You want the datetime module. </p>
<pre><code>>>> from datetime import datetime
>>> datetime(2008,08,18) - datetime(2008,09,26)
datetime.timedelta(4)
</code></pre>
<p>Or other example:</p>
<pre><code>Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363... | 5 | 2008-09-29T23:43:10Z | [
"python",
"date"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 10,332,036 | <pre><code>from datetime import datetime
start_date = datetime.strptime('8/18/2008', "%m/%d/%Y")
end_date = datetime.strptime('9/26/2008', "%m/%d/%Y")
print abs((end_date-start_date).days)
</code></pre>
| 3 | 2012-04-26T10:58:02Z | [
"python",
"date"
] |
How do I calculate number of days betwen two dates using Python? | 151,199 | <p>If I have two dates (ex. <code>'8/18/2008'</code> and <code>'9/26/2008'</code>) what is the best way to get the difference measured in days?</p>
| 193 | 2008-09-29T23:36:25Z | 36,650,398 | <p></p>
<pre><code>from datetime import date
def d(s):
[month, day, year] = map(int, s.split('/'))
return date(year, month, day)
def days(start, end):
return (d(end) - d(start)).days
print days('8/18/2008', '9/26/2008')
</code></pre>
<p>This assumes, of course, that you've already verified that your dates are i... | 1 | 2016-04-15T14:50:41Z | [
"python",
"date"
] |
Get other running processes window sizes in Python | 151,846 | <p>This isn't as malicious as it sounds, I want to get the current size of their windows, not look at what is in them. The purpose is to figure out that if every other window is fullscreen then I should start up like that too. Or if all the other processes are only 800x600 despite there being a huge resolution then t... | 7 | 2008-09-30T05:20:27Z | 152,094 | <p>Check out the <a href="http://www.devx.com/opensource/Article/37773/1954" rel="nofollow"><code>win32gui</code> module</a> in the Windows extensions for Python. It may provide some of the functionality you're looking for.</p>
| 2 | 2008-09-30T07:35:04Z | [
"python",
"windows",
"winapi",
"pywin32"
] |
Get other running processes window sizes in Python | 151,846 | <p>This isn't as malicious as it sounds, I want to get the current size of their windows, not look at what is in them. The purpose is to figure out that if every other window is fullscreen then I should start up like that too. Or if all the other processes are only 800x600 despite there being a huge resolution then t... | 7 | 2008-09-30T05:20:27Z | 152,454 | <p>Using hints from <a href="http://www.devx.com/opensource/Article/37773/1954">WindowMover article</a> and <a href="http://our.obor.us/?q=node/42">Nattee Niparnan's blog post</a> I managed to create this:</p>
<pre><code>import win32con
import win32gui
def isRealWindow(hWnd):
'''Return True iff given window is a ... | 11 | 2008-09-30T10:02:38Z | [
"python",
"windows",
"winapi",
"pywin32"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.