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 |
|---|---|---|---|---|---|---|---|---|---|
assertRaises just catches base exception | 2,013,018 | <p>I'm running into a strange problem when using <code>unittest.assertRaises</code>. When executing the code below I get the following output:</p>
<pre><code>E
======================================================================
ERROR: testAssertRaises (__main__.Test)
------------------------------------------------... | 0 | 2010-01-06T12:59:59Z | 2,013,081 | <p>The problem is probably that your <code>BaseClass.get()</code> method is returning you another class. By the way, that method is horrible in itself, I wonder why you're doing this.</p>
| 0 | 2010-01-06T13:11:42Z | [
"python",
"unit-testing",
"assertraises"
] |
assertRaises just catches base exception | 2,013,018 | <p>I'm running into a strange problem when using <code>unittest.assertRaises</code>. When executing the code below I get the following output:</p>
<pre><code>E
======================================================================
ERROR: testAssertRaises (__main__.Test)
------------------------------------------------... | 0 | 2010-01-06T12:59:59Z | 2,013,096 | <p>When you run derived.py, it is run as the <code>__main__</code> module (since you ran it directly rather than importing it). When you later import it explicitly, another copy of the module is created, this time under the name <code>derived</code>. So <code>__main__.MyError</code> is not the same as <code>derived.MyE... | 1 | 2010-01-06T13:13:48Z | [
"python",
"unit-testing",
"assertraises"
] |
assertRaises just catches base exception | 2,013,018 | <p>I'm running into a strange problem when using <code>unittest.assertRaises</code>. When executing the code below I get the following output:</p>
<pre><code>E
======================================================================
ERROR: testAssertRaises (__main__.Test)
------------------------------------------------... | 0 | 2010-01-06T12:59:59Z | 2,014,909 | <p>As <a href="http://stackoverflow.com/questions/2013018/assertraises-just-catches-base-exception/2013096#2013096">mentioned</a>, the issue is modules <em>__main__</em> and <em>derived</em> are not one and the same; this answer is about how you fix that.</p>
<p><em>Don't</em> mix module code and script code. Start t... | 2 | 2010-01-06T17:36:31Z | [
"python",
"unit-testing",
"assertraises"
] |
attribute assignment order in class definition | 2,013,067 | <p>Hi my problem is that:
I want to define a class in this way:</p>
<pre><code>class List(Base):
hp = Column(int,...)
name = Column(str,...)
</code></pre>
<p>This class represents a list, I can define/modify/code the <code>Base</code> and the <code>Column</code> class.
There's a way to know the order in whic... | 4 | 2010-01-06T13:09:09Z | 2,013,153 | <p>I think you want something like this:</p>
<pre><code>import inspect
class List(Base):
hp = Column(int,...)
name = Column(str,...)
def show(self):
public_bits = [(x, getattr(self, x)) for x in dir(self) if not x.startswith('__')]
return [(x, y) for (x, y) in public_bits if not inspect.i... | 0 | 2010-01-06T13:23:25Z | [
"python"
] |
attribute assignment order in class definition | 2,013,067 | <p>Hi my problem is that:
I want to define a class in this way:</p>
<pre><code>class List(Base):
hp = Column(int,...)
name = Column(str,...)
</code></pre>
<p>This class represents a list, I can define/modify/code the <code>Base</code> and the <code>Column</code> class.
There's a way to know the order in whic... | 4 | 2010-01-06T13:09:09Z | 2,014,002 | <p>Internally, attribute definitions are stored in a dictionary, which does not retain the order of the elements. You could probably change the attribute handling in the Base class, or you store the creation order, like this:</p>
<pre><code>class Column:
creation_counter = 0
def __init__(self):
se... | 7 | 2010-01-06T15:29:50Z | [
"python"
] |
attribute assignment order in class definition | 2,013,067 | <p>Hi my problem is that:
I want to define a class in this way:</p>
<pre><code>class List(Base):
hp = Column(int,...)
name = Column(str,...)
</code></pre>
<p>This class represents a list, I can define/modify/code the <code>Base</code> and the <code>Column</code> class.
There's a way to know the order in whic... | 4 | 2010-01-06T13:09:09Z | 2,014,152 | <p>Class and instance attributes are inherently unordered since they are stored in a dictionary.</p>
<p>There are a few options though:</p>
<p>1) classes defined with <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow"><code>__slots__</code></a> do not use a dictionary, and the space for at... | 0 | 2010-01-06T15:50:53Z | [
"python"
] |
Suppressing Cherrypy's output when running unit tests using Nose | 2,013,191 | <p>I'm using cherrypy to implement a web server and I use nose to run my unit tests. However, there is a lot of debug noise that nose catches and prints to stdout, even when I use the --nologcapture, particularly cherrypy's logging messages. That makes the testing output quite difficult to read.</p>
<p>I've thought th... | 3 | 2010-01-06T13:27:43Z | 2,016,607 | <p>You did not mention which version of CherryPy you were using, but assuming 3.x based on what you are experiencing. I believe you need to add the following config option:</p>
<pre><code>cherrypy.config.update({ "environment": "embedded" })
</code></pre>
<p>I was recently faced with the same issue when I was <a href... | 4 | 2010-01-06T22:02:22Z | [
"python",
"cherrypy",
"nose"
] |
Suppressing Cherrypy's output when running unit tests using Nose | 2,013,191 | <p>I'm using cherrypy to implement a web server and I use nose to run my unit tests. However, there is a lot of debug noise that nose catches and prints to stdout, even when I use the --nologcapture, particularly cherrypy's logging messages. That makes the testing output quite difficult to read.</p>
<p>I've thought th... | 3 | 2010-01-06T13:27:43Z | 9,004,447 | <p>I was experiencing this problem with CherryPy 3.1.2. I switched to 3.2.2 and the problem went away without needing any code changes.</p>
| 1 | 2012-01-25T14:37:28Z | [
"python",
"cherrypy",
"nose"
] |
How to move into multiple directories Python | 2,013,204 | <p>I am creating several directories a day. After seven days I am going to drop a sandbox in these directories and delete them. I use a time stamp to name them. I have got some code below to show you what I have got.</p>
<pre><code>today = datetime.date.today() # Today's date Binary
todaystr = datetime.date.today().is... | 0 | 2010-01-06T13:30:14Z | 2,013,286 | <blockquote>
<p><code>old_folders = minus_seven + '*'</code></p>
</blockquote>
<p>This does not do what you think it does. This gives you the name of a folder that literally ends in a <code>*</code>. Later, <code>os.path.exists()</code> will return <code>False</code>.</p>
<p>What you need to do is loop through th... | 3 | 2010-01-06T13:41:57Z | [
"python"
] |
How to move into multiple directories Python | 2,013,204 | <p>I am creating several directories a day. After seven days I am going to drop a sandbox in these directories and delete them. I use a time stamp to name them. I have got some code below to show you what I have got.</p>
<pre><code>today = datetime.date.today() # Today's date Binary
todaystr = datetime.date.today().is... | 0 | 2010-01-06T13:30:14Z | 2,013,305 | <p>" I want to know how to enter each folder"</p>
<p>Are you asking about <code>os.path.join</code> to create the full path name?</p>
<p><a href="http://docs.python.org/library/os.path.html#os.path.join" rel="nofollow">http://docs.python.org/library/os.path.html#os.path.join</a> </p>
<p>or <code>os.chdir</code> to c... | 0 | 2010-01-06T13:44:49Z | [
"python"
] |
How to move into multiple directories Python | 2,013,204 | <p>I am creating several directories a day. After seven days I am going to drop a sandbox in these directories and delete them. I use a time stamp to name them. I have got some code below to show you what I have got.</p>
<pre><code>today = datetime.date.today() # Today's date Binary
todaystr = datetime.date.today().is... | 0 | 2010-01-06T13:30:14Z | 2,014,437 | <p>You have two options:</p>
<p>Use <em>os.walk</em> </p>
<pre><code>for root, dirs, files in os.walk('your root'):
for dir in dirs:
os.chdir(os.path.join(root, dir))
delete_sandbox()
</code></pre>
<p>Use <em>os.path.walk</em> then change delete_sandbox to be used as the callback.</p>
<pre><code>def... | 0 | 2010-01-06T16:30:41Z | [
"python"
] |
Django, create_user giving error, manually creating user gives different error | 2,013,230 | <p>Working with Django 1.1 on Python 2.6.4, trying to execute the following:</p>
<pre><code>user = User.objects.create_user(username, email, password)
</code></pre>
<p>The three values are from form.cleaned_data, and have already been validated. i get this error:</p>
<pre><code>'dict' object has no attribute 'strip'... | 0 | 2010-01-06T13:33:56Z | 2,013,250 | <p>Seems like email_address is not really a string ('dict' object has no attribute 'strip'), can you dump for us the values of username, email and password?</p>
| 2 | 2010-01-06T13:36:52Z | [
"python",
"django"
] |
Commands for breakpoints in a .pdbrc file | 2,013,698 | <p>I'd like to save the commands for a breakpoint in a <code>.pdbrc</code>, something like: </p>
<pre><code>b 81
commands 1
pp foo.attr1
pp foo.attr2
end
b 108
commands 2
pp bar.attr1
pp bar.attr2
end
</code></pre>
<p>This would automate setting the environment for the debugging session. However, this does ... | 3 | 2010-01-06T14:51:52Z | 2,014,367 | <p>My first thought was that the command must be defined on one line:</p>
<pre><code>commands 1;; pp foo.attr1;; pp foo.attr2;; end;;
</code></pre>
<p>However, it appears that this will only work at the prompt, and you will incorrectly get:</p>
<pre><code>Usage : commands [bnum]
...
end
</code></pre>... | 0 | 2010-01-06T16:21:27Z | [
"python",
"debugging"
] |
Commands for breakpoints in a .pdbrc file | 2,013,698 | <p>I'd like to save the commands for a breakpoint in a <code>.pdbrc</code>, something like: </p>
<pre><code>b 81
commands 1
pp foo.attr1
pp foo.attr2
end
b 108
commands 2
pp bar.attr1
pp bar.attr2
end
</code></pre>
<p>This would automate setting the environment for the debugging session. However, this does ... | 3 | 2010-01-06T14:51:52Z | 7,920,382 | <p>You probably don't want this set every time you use pdb anywhere. My recommendation would be to set up an alias, such as:</p>
<pre><code>alias setup_myproj b 81;; commands 1;; pp foo.attr1;; pp foo.attr2;; end
</code></pre>
<p>Then you can run <code>setup_myproj</code> when appropriate.</p>
| 0 | 2011-10-27T18:13:53Z | [
"python",
"debugging"
] |
Is it possible to create an end-user facing site using Django admin alone? | 2,013,736 | <p>I'm very new to Django, having never developed on it. </p>
<p>I'm trying to develop a site which has functionality exposed only to authenticated users (typical enterprise thing: for this discussion, let's say it's a private blogging platform). </p>
<p>The functionality I'm looking for is:</p>
<ul>
<li>Users can c... | 3 | 2010-01-06T14:56:40Z | 2,013,798 | <p><strong>Revised</strong>. Up until you want per-object permission, the answer is yes.</p>
<p>As soon as you want permission on a Blog, where a blog is just a row, you're going to have to do some coding.</p>
<p>You can totally reuse the admin interface elements. You have all the source, which you can read. </p>
... | 2 | 2010-01-06T15:04:01Z | [
"python",
"django",
"django-admin"
] |
Is it possible to create an end-user facing site using Django admin alone? | 2,013,736 | <p>I'm very new to Django, having never developed on it. </p>
<p>I'm trying to develop a site which has functionality exposed only to authenticated users (typical enterprise thing: for this discussion, let's say it's a private blogging platform). </p>
<p>The functionality I'm looking for is:</p>
<ul>
<li>Users can c... | 3 | 2010-01-06T14:56:40Z | 2,014,321 | <p>As for row-level permissions in the admin, in the SVN version of Django you can override the <code>has_add_permission</code>, <code>has_change_permission</code>, and <code>has_delete_permission</code> methods on the <code>ModelAdmin</code> object to implement the custom permissions logic yourself in a way that will ... | 0 | 2010-01-06T16:14:47Z | [
"python",
"django",
"django-admin"
] |
Is it possible to create an end-user facing site using Django admin alone? | 2,013,736 | <p>I'm very new to Django, having never developed on it. </p>
<p>I'm trying to develop a site which has functionality exposed only to authenticated users (typical enterprise thing: for this discussion, let's say it's a private blogging platform). </p>
<p>The functionality I'm looking for is:</p>
<ul>
<li>Users can c... | 3 | 2010-01-06T14:56:40Z | 2,014,338 | <p>As a point of sense you really shouldn't be basing a potentially large scale project on Django-Admin. It's kind of silly, and so many people are fascinated with Django-Admin that they literally have a chapter in their books about when and when not to use it for evil.</p>
<p>It seems to me that for all the hacking y... | 0 | 2010-01-06T16:17:41Z | [
"python",
"django",
"django-admin"
] |
Got Django and Buildout working, but what about PIL and Postgres? | 2,013,789 | <p>I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on setting up Django with Buildout: <a href="http://jacobian.org/writing/django-apps-with-buildout/" rel="nofollow">http://jacobian.org/writing/django-apps-with-buildout/</a></p>
<p>Finally, I have got this Buildout to work! ...but I'm now needing P... | 5 | 2010-01-06T15:03:04Z | 2,087,050 | <p>In theory, you should just be able to add <code>PIL</code> and <code>psycopg2</code> to your <code>eggs</code> directive:</p>
<pre><code>eggs = myproject
PIL
psycopg2
</code></pre>
<p>This works on some systems and in some situations.</p>
<p>However, there are two problems that can prevent it from w... | 8 | 2010-01-18T15:29:00Z | [
"python",
"postgresql",
"python-imaging-library",
"buildout"
] |
Got Django and Buildout working, but what about PIL and Postgres? | 2,013,789 | <p>I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on setting up Django with Buildout: <a href="http://jacobian.org/writing/django-apps-with-buildout/" rel="nofollow">http://jacobian.org/writing/django-apps-with-buildout/</a></p>
<p>Finally, I have got this Buildout to work! ...but I'm now needing P... | 5 | 2010-01-06T15:03:04Z | 4,566,262 | <p>expanding on (2) above</p>
<p>PIL works with additional components that can be installed with below steps.</p>
<p>JPG</p>
<pre><code>wget http://www.ijg.org/files/jpegsrc.v8b.tar.gz
tar xzf jpegsrc.v8b.tar.gz
cd jpeg-8b/
./configure
make
sudo make install
</code></pre>
<p>Freetype</p>
<pre><code>http://so... | 0 | 2010-12-30T21:03:55Z | [
"python",
"postgresql",
"python-imaging-library",
"buildout"
] |
Is it possible to use KHTMLPart completely from console? | 2,013,795 | <p>I'm using the KHTMLPart component from the PyKDE (in Python) library to download some webpages in the background and return sizes of certain elements in pixels. I don't really need any visual output from this script, indeed I will probably run it on a server without X installed. The problem is that when I tell my ap... | 0 | 2010-01-06T15:03:43Z | 2,013,946 | <p>If all else fails, you could try using the <a href="http://en.wikipedia.org/wiki/Xvfb" rel="nofollow">X Virtual Framebuffer</a> to provide a fake X display to your application, allowing it to run without displaying anywhere.</p>
| 1 | 2010-01-06T15:24:33Z | [
"python",
"kde",
"pykde"
] |
Is it possible to use KHTMLPart completely from console? | 2,013,795 | <p>I'm using the KHTMLPart component from the PyKDE (in Python) library to download some webpages in the background and return sizes of certain elements in pixels. I don't really need any visual output from this script, indeed I will probably run it on a server without X installed. The problem is that when I tell my ap... | 0 | 2010-01-06T15:03:43Z | 2,013,956 | <p>I doubt it. Most browsers separate the download, the creation of the DOM model and the rendering in different parts of the code. This allows them to download the data in threads, convert it and then use an optimized renderer to display it. This is an expensive operation so they only do it when necessary.</p>
<p>The... | 1 | 2010-01-06T15:25:35Z | [
"python",
"kde",
"pykde"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 2,013,860 | <p>I think you should store it in a decimal format and format it to 00.00 format <strong>only</strong> then sending it to PayPal, like this:</p>
<pre><code>pricestr = "%01.2f" % price
</code></pre>
<p>If you want, you can add a method to your model:</p>
<pre><code>def formattedprice(self):
return "%01.2f" % self... | 18 | 2010-01-06T15:13:05Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 2,013,866 | <p>I suggest to avoid mixing representation with storage. Store the data as a decimal value with 2 places.</p>
<p>In the UI layer, display it in a form which is suitable for the user (so maybe omit the ".00").</p>
<p>When you send the data to PayPal, format it as the interface requires.</p>
| 8 | 2010-01-06T15:14:10Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 2,013,893 | <p>You store it as a DecimalField and manually add the decimals if you need to, as Valya said, using basic formatting techniques.</p>
<p>You can even add a Model Method to you product or transaction model that will spit out the DecimalField as an appropriately formatted string.</p>
| 1 | 2010-01-06T15:17:00Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 2,014,635 | <p>You might want to use the <code>.quantize()</code> method. This will round a decimal value to a certain number of places, the argument you provide specifies the number of places:</p>
<pre><code>>>> from decimal import Decimal
>>> Decimal("12.234").quantize(Decimal("0.00"))
Decimal("12.23")
</code>... | 58 | 2010-01-06T16:58:09Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 11,611,863 | <p>Money should be stored in money field, which sadly does not exist. Since money is two dimensional value (amount, currency).</p>
<p>There is <strong>python-money</strong> lib, that has many forks, yet I haven't found working one.</p>
<hr>
<p>Recommendations:</p>
<p><strong>python-money</strong> probably the best ... | 9 | 2012-07-23T11:43:48Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 13,176,000 | <p>In my experience and also from <a href="http://www.databasesandlife.com/store-currency-amounts-as-number-of-cents-pence-etc/" rel="nofollow">others</a>, money is best stored as combination of currency and the amount in cents. </p>
<p>It's very easy to handle and calculate with it.</p>
| 3 | 2012-11-01T11:22:57Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 13,185,959 | <p>Building on @Will_Hardy's answer, here it is so you don't have to specify max_digits and decimal_places every time:</p>
<pre><code>from django.db import models
from decimal import Decimal
class CurrencyField(models.DecimalField):
__metaclass__ = models.SubfieldBase
def __init__(self, verbose_name=None, name=... | 4 | 2012-11-01T21:43:22Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Django: How should I store a money value? | 2,013,835 | <p>I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:</p>
<p><strong>PayPal requires 2 decimal places</strong>, so if I have a product that is 49 dollars even, PayPal wants to ... | 53 | 2010-01-06T15:09:00Z | 16,471,927 | <p>My late to the party version that adds South migrations.</p>
<pre><code>from decimal import Decimal
from django.db import models
try:
from south.modelsinspector import add_introspection_rules
except ImportError:
SOUTH = False
else:
SOUTH = True
class CurrencyField(models.DecimalField):
__metaclass... | 13 | 2013-05-09T22:06:29Z | [
"python",
"django",
"django-models",
"decimal",
"money"
] |
Difficulty getting flup fcgi script to work | 2,013,936 | <p>I'm building a site for a client using django. It's been hosted on shared hosting and mod_wsgi can't be used. In the old year, I got it working using fcgi, but when I got back, it was broken.</p>
<p>I have replaced the fcgi script with a simple hello world script:</p>
<pre><code>#!/usr/bin/python
def myapp(environ... | 1 | 2010-01-06T15:22:54Z | 2,038,563 | <p>The exit status 116 and 118 were coming from suexec. By reading the <a href="http://svn.apache.org/viewvc/httpd/httpd/trunk/support/suexec.c?view=markup#l526" rel="nofollow">source code</a>, I found that these errors are caused by the file/dir being writable by group or others, which suexec considers as a security i... | 2 | 2010-01-10T20:51:36Z | [
"python",
"django",
"fastcgi",
"flup"
] |
Difficulty getting flup fcgi script to work | 2,013,936 | <p>I'm building a site for a client using django. It's been hosted on shared hosting and mod_wsgi can't be used. In the old year, I got it working using fcgi, but when I got back, it was broken.</p>
<p>I have replaced the fcgi script with a simple hello world script:</p>
<pre><code>#!/usr/bin/python
def myapp(environ... | 1 | 2010-01-06T15:22:54Z | 2,038,638 | <p>Hey, thanks! I'll just paste the comments.</p>
<ul>
<li>What server are you using to run mymembers.fcgi ? â Tobu</li>
<li>Debian Etch, Apache 1.3 The url is mymembers.co.za â Gary van der Merwe</li>
<li>I suspect mod_fastcgi is misconfigured. Please post or pastebin the relevant parts of your apache config. â... | 0 | 2010-01-10T21:12:37Z | [
"python",
"django",
"fastcgi",
"flup"
] |
Python: How do you format a string % number with str.format() | 2,014,012 | <p>How can I format a string like this</p>
<pre><code>"%01.2f" % pr"%01.2f" % some_number
</code></pre>
<p>but using the str.format() style? I'm used to this:</p>
<pre><code>'{0} {1}'.format(somevalue1, somevalue2)
</code></pre>
<p>Is there a way to use that function style vs the old % style, and still achieve this... | 2 | 2010-01-06T15:31:06Z | 2,014,053 | <p>It would be like <code>{0:01.2f}</code>, I believe. See <a href="http://docs.python.org/library/string.html#format-string-syntax" rel="nofollow">http://docs.python.org/library/string.html#format-string-syntax</a>.</p>
<p><strong>Edit</strong>: added in your zero-padding.</p>
| 4 | 2010-01-06T15:37:50Z | [
"python",
"string"
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,141 | <p>Couldn't you do a try except? The Pythonic way says <a href="http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Exceptions" rel="nofollow">It is Easier to Ask for Forgiveness than Permission</a>.</p>
<p>So:</p>
<pre><code>try:
if foo.bar.baz == 42:
shiny_happy(...)
except AttributeError:
pass... | 13 | 2010-01-06T15:49:07Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,142 | <p>I don't think it's a good idea. Here's why. suppose you have</p>
<pre><code>foo.getValue()
</code></pre>
<p>Suppose <code>getValue()</code> returns a number, or <code>None</code> if not found.
Now suppose <code>foo</code> was none by accident or a bug. As a result, it would return <code>None</code>, and continue, ... | 3 | 2010-01-06T15:49:20Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,148 | <p>Here's why I don't think that's a good idea:</p>
<pre><code>foo = Foo() // now foo is None
// if foo is None, I want to raise an exception because that is an error condition.
// The normal case is that I expect a foo back whose bar property may or may not be filled in.
// If it's not filled in, I want to set it my... | 2 | 2010-01-06T15:50:29Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,173 | <p>Personally I believe throwing an exception is what should happen. Lets say for some reason you are writing software for missiles in Python. Imagine the atomic bomb and lets say there was a method called explode(timeToExplode) and timeToExplode got passed in as None. I think you would be unhappy at the end of the ... | 1 | 2010-01-06T15:53:49Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,404 | <p>The handiness comes at the expense of dumb mistakes not being detected at the earliest possible time, as close to the buggy line of code as possible.</p>
<p>I think the handiness of this particular feature would be occasional at best, whereas dumb mistakes happen <em>all the time</em>.</p>
<hr>
<p>Certainly a SQL... | 10 | 2010-01-06T16:25:42Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,423 | <p><a href="http://www.python.org/dev/peps/pep-0336/" rel="nofollow">PEP 336 - Make None Callable</a> proposed a similar feature:</p>
<blockquote>
<p>None should be a callable object that when called with any arguments
has no side effect and returns None.</p>
</blockquote>
<p>The reason for why it was rejected wa... | 19 | 2010-01-06T16:28:21Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,508 | <pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>The above can be cleaned up using the fact that None resolves to False:</p>
<pre><code>if foo.bar and foo.bar.baz == 42:
shiny_happy(...)
else:
not_happy(...)
</code></pre>
| 1 | 2010-01-06T16:40:15Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,589 | <p>I'm sorry, but that code is pythonic. I think most would agree that "explicit is better than implicit" in Python. Python is a language that is easy to read compared to most, and people should not defeat that by writing cryptic code. Make the meaning very clear.</p>
<pre><code>foo = Foo()
...
if foo.bar is not None ... | 13 | 2010-01-06T16:51:20Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,662 | <p>I am not a python programmer (just starting to learn the language) but this seems like the never-ending discussion on when to return error or throw exception, and the fact is that (of course this is only an opinion) it depends.</p>
<p>Exceptions should be used for exceptional conditions, and as such move the checks... | 1 | 2010-01-06T17:00:49Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,720 | <p>While I wholeheartedly agree with other answers here that say that it's a good thing that <code>None</code> raises an exception when asked for a member, this is a little pattern I sometimes use:</p>
<pre><code>getattr(foo.bar, 'baz', default_value)
</code></pre>
| 2 | 2010-01-06T17:08:33Z | [
"python",
"error-handling",
null
] |
Null pattern in Python underused? | 2,014,105 | <p>Every now and then I come across code like this:</p>
<pre><code>foo = Foo()
...
if foo.bar is not None and foo.bar.baz == 42:
shiny_happy(...)
</code></pre>
<p>Which seems, well, unpythonic, to me.</p>
<p>In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite h... | 17 | 2010-01-06T15:44:21Z | 2,014,897 | <p>As others have said, PEP 336 describes why this is the behavior.</p>
<p>Adding something like Groovy's "<a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29" rel="nofollow">safe navigation operator</a>" (<code>?.</code>) could perhaps make things more elegant in some cases:</p>
... | 4 | 2010-01-06T17:34:49Z | [
"python",
"error-handling",
null
] |
zooming pictures with wx.image | 2,014,209 | <p>im doing a software that paints over images and save them ( for commenting propose ) .
i used the code below to display image to be drown upon.
the problem is:
<br>how can i zoom in and out ? . <br>
or should i use another way to display that image ?
<br>
<code><br>
bitmap=wx.bitmap(path,wx.BITMAP_TYPE_ANY)
buffer ... | 1 | 2010-01-06T16:00:08Z | 2,014,334 | <p>Try <a href="http://docs.wxwidgets.org/2.6/wx_wxdc.html#wxdcsetuserscale" rel="nofollow">dc.SetUserScaling</a></p>
| 2 | 2010-01-06T16:17:09Z | [
"python",
"image",
"wxpython",
"zoom"
] |
PHP Bayesian Classifier | 2,014,432 | <p>I'm looking for a Naive Bayesian Classifier for PHP, ideally something equivalent to the Reverend Bayes version written in Python. Does anyone know of such a library?</p>
<p>Basically I need to be able to train it with a set of labels and words i.e. GOOD = okay, happy, fun; BAD = wrong, rubbish, awful etc and then ... | 3 | 2010-01-06T16:29:29Z | 2,014,458 | <p><a href="http://www.ibm.com/developerworks/library/wa-bayes1/" rel="nofollow">This</a> looks like a nice set of tutorials on the subject. A similar question has been asked <a href="http://stackoverflow.com/questions/1310478/implementing-bayesian-classifier-in-php">previously</a> and the only real answer pointed to t... | 3 | 2010-01-06T16:33:45Z | [
"php",
"python"
] |
Force python mechanize/urllib2 to only use A requests? | 2,014,534 | <p>Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: <a href="http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests">http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests</a>... | 10 | 2010-01-06T16:43:31Z | 2,034,923 | <p>The DNS server 8.8.8.8 (Google DNS) replies immediately when asked about the AAAA of python.org. Therefore, the fact we do not see this reply in the trace you post probably indicate that this packet did not come back (which happens with UDP). If this loss is random, it is normal. If it is systematic, it means there ... | 2 | 2010-01-09T20:56:08Z | [
"python",
"mechanize",
"ipv6",
"urllib"
] |
Force python mechanize/urllib2 to only use A requests? | 2,014,534 | <p>Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: <a href="http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests">http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests</a>... | 10 | 2010-01-06T16:43:31Z | 2,035,686 | <p>No answer, but a few datapoints. The DNS resolution appears to be originating from <code>httplib.py</code> in <code>HTTPConnection.connect()</code> (line 670 on my python 2.5.4 stdlib) </p>
<p>The code flow is roughly:</p>
<pre><code>for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
... | 4 | 2010-01-10T01:19:32Z | [
"python",
"mechanize",
"ipv6",
"urllib"
] |
Force python mechanize/urllib2 to only use A requests? | 2,014,534 | <p>Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: <a href="http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests">http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests</a>... | 10 | 2010-01-06T16:43:31Z | 6,319,043 | <p>Suffering from the same problem, here is an ugly hack (use at your own risk..) based on the information given by J.J. . </p>
<p>This basically forces the <code>family</code> parameter of <code>socket.getaddrinfo(..)</code> to <code>socket.AF_INET</code> instead of using <code>socket.AF_UNSPEC</code> (zero, which is... | 14 | 2011-06-11T23:03:20Z | [
"python",
"mechanize",
"ipv6",
"urllib"
] |
Force python mechanize/urllib2 to only use A requests? | 2,014,534 | <p>Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: <a href="http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests">http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests</a>... | 10 | 2010-01-06T16:43:31Z | 13,678,468 | <p>Most likely cause of this is a <a href="http://serverfault.com/q/411165/126632">broken egress firewall</a>. Juniper firewalls can cause this, for instance, though they have a <a href="http://kb.juniper.net/InfoCenter/index?page=content&id=KB12312&actp=RSS" rel="nofollow">workaround</a> available.</p>
<p>If ... | 1 | 2012-12-03T06:50:46Z | [
"python",
"mechanize",
"ipv6",
"urllib"
] |
Find the newest folder in a directory in Python | 2,014,554 | <p>I am trying to have an automated script that enters into the most recently created folder.</p>
<p>I have some code below</p>
<pre><code>import datetime, os, shutil
today = datetime.datetime.now().isoformat()
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*'))
if file_time < today:
... | 12 | 2010-01-06T16:46:29Z | 2,014,678 | <p>here's one way to find latest directory</p>
<pre><code>import os
import time
import operator
alist={}
now = time.time()
directory=os.path.join("/home","path")
os.chdir(directory)
for file in os.listdir("."):
if os.path.isdir(file):
timestamp = os.path.getmtime( file )
# get timestamp and directo... | 1 | 2010-01-06T17:02:22Z | [
"python"
] |
Find the newest folder in a directory in Python | 2,014,554 | <p>I am trying to have an automated script that enters into the most recently created folder.</p>
<p>I have some code below</p>
<pre><code>import datetime, os, shutil
today = datetime.datetime.now().isoformat()
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*'))
if file_time < today:
... | 12 | 2010-01-06T16:46:29Z | 2,014,682 | <pre><code>import os, datetime, operator
dir = "/"
folders = [(f,os.path.getmtime('%s/%s'%(dir,f))) for f in os.listdir(dir) if os.path.isdir(f)]
(newest_folder, mtime) = sorted(folders, key=operator.itemgetter(1), reverse=True)[0]
</code></pre>
| 0 | 2010-01-06T17:03:03Z | [
"python"
] |
Find the newest folder in a directory in Python | 2,014,554 | <p>I am trying to have an automated script that enters into the most recently created folder.</p>
<p>I have some code below</p>
<pre><code>import datetime, os, shutil
today = datetime.datetime.now().isoformat()
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*'))
if file_time < today:
... | 12 | 2010-01-06T16:46:29Z | 2,014,704 | <p>There is no actual trace of the "time created" in most OS / filesystems: what you get as <code>mtime</code> is the time a file or directory was <strong>modified</strong> (so for example creating a file in a directory updates the directory's mtime) -- and from <code>ctime</code>, when offered, the time of the latest ... | 27 | 2010-01-06T17:06:24Z | [
"python"
] |
Find the newest folder in a directory in Python | 2,014,554 | <p>I am trying to have an automated script that enters into the most recently created folder.</p>
<p>I have some code below</p>
<pre><code>import datetime, os, shutil
today = datetime.datetime.now().isoformat()
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*'))
if file_time < today:
... | 12 | 2010-01-06T16:46:29Z | 17,348,201 | <p>And a quick one-liner:</p>
<pre><code>directory = 'some/path/to/the/main/dir'
max([os.path.join(directory,d) for d in os.listdir(directory)], key=os.path.getmtime)
</code></pre>
| 1 | 2013-06-27T16:15:08Z | [
"python"
] |
Find the newest folder in a directory in Python | 2,014,554 | <p>I am trying to have an automated script that enters into the most recently created folder.</p>
<p>I have some code below</p>
<pre><code>import datetime, os, shutil
today = datetime.datetime.now().isoformat()
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*'))
if file_time < today:
... | 12 | 2010-01-06T16:46:29Z | 32,093,754 | <p>One liner to find latest</p>
<pre><code># Find latest
import os; import glob
max(glob.glob(os.path.join(directory, '*/')), key=os.path.getmtime)
</code></pre>
<p>One liner to find n'th latest</p>
<pre><code># Find n'th latest
import os; import glob
sorted(glob.glob(os.path.join(directory, '*/')), key=os.path.getm... | 2 | 2015-08-19T11:06:38Z | [
"python"
] |
Forcing tuples within tuples? | 2,014,767 | <p>I've got a python function that should loop through a tuple of coordinates and print their contents:</p>
<pre><code>def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
</code></pre>
<p>When y is run through the function, it outputs (5,5) and (4,4), the desired result. H... | 2 | 2010-01-06T17:16:02Z | 2,014,782 | <p>Use a trailing comma for singleton tuples.</p>
<pre><code>x = ((5, 5),)
</code></pre>
| 10 | 2010-01-06T17:17:47Z | [
"python",
"list",
"tuples"
] |
Forcing tuples within tuples? | 2,014,767 | <p>I've got a python function that should loop through a tuple of coordinates and print their contents:</p>
<pre><code>def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
</code></pre>
<p>When y is run through the function, it outputs (5,5) and (4,4), the desired result. H... | 2 | 2010-01-06T17:16:02Z | 2,014,783 | <pre><code>x=((5,5),)
</code></pre>
<p>(<em>x</em>) is an expression (<em>x</em>,) is a singleton tuple.</p>
| 6 | 2010-01-06T17:17:50Z | [
"python",
"list",
"tuples"
] |
Forcing tuples within tuples? | 2,014,767 | <p>I've got a python function that should loop through a tuple of coordinates and print their contents:</p>
<pre><code>def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
</code></pre>
<p>When y is run through the function, it outputs (5,5) and (4,4), the desired result. H... | 2 | 2010-01-06T17:16:02Z | 2,014,788 | <p>This is an old and infuriating quirk of python syntax. You have to include a trailing comma to make Python see a tuple:</p>
<pre><code>x = ((5,5),)
</code></pre>
| 3 | 2010-01-06T17:18:25Z | [
"python",
"list",
"tuples"
] |
Forcing tuples within tuples? | 2,014,767 | <p>I've got a python function that should loop through a tuple of coordinates and print their contents:</p>
<pre><code>def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
</code></pre>
<p>When y is run through the function, it outputs (5,5) and (4,4), the desired result. H... | 2 | 2010-01-06T17:16:02Z | 2,014,789 | <p>You need to add a comma after your first tuple.
<code>((5,5),)</code> should work.</p>
| 2 | 2010-01-06T17:18:30Z | [
"python",
"list",
"tuples"
] |
Forcing tuples within tuples? | 2,014,767 | <p>I've got a python function that should loop through a tuple of coordinates and print their contents:</p>
<pre><code>def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
</code></pre>
<p>When y is run through the function, it outputs (5,5) and (4,4), the desired result. H... | 2 | 2010-01-06T17:16:02Z | 2,014,797 | <p>Simply add a comma:</p>
<pre><code>x=((5,5),)
</code></pre>
| 2 | 2010-01-06T17:19:26Z | [
"python",
"list",
"tuples"
] |
Word Wrap in PyGTK TreeView | 2,014,804 | <p>How can I word wrap text inside a PyGTK TreeView?</p>
| 4 | 2010-01-06T17:20:43Z | 2,014,888 | <p>It seems this isn't a built-in feature of GTK, however you can create your own TreeCellRenderer, as detailed below:</p>
<p><a href="http://danielwould.wordpress.com/2010/01/02/maemo-custom-cell-renderer-for-gtk-treeview-python/" rel="nofollow">http://danielwould.wordpress.com/2010/01/02/maemo-custom-cell-renderer-f... | 1 | 2010-01-06T17:33:34Z | [
"python",
"pygtk",
"word-wrap"
] |
Word Wrap in PyGTK TreeView | 2,014,804 | <p>How can I word wrap text inside a PyGTK TreeView?</p>
| 4 | 2010-01-06T17:20:43Z | 2,018,587 | <p>Text in a gtk.TreeView is rendered using a gtk.CellRendererText, and wrapping text comes down to setting the right properties on your cell renderer. In order to get text to wrap, you need to set the <code>wrap-width</code> property (in pixels) on the cell renderer. You probably also want to set the <code>wrap-mode</... | 6 | 2010-01-07T06:19:21Z | [
"python",
"pygtk",
"word-wrap"
] |
Word Wrap in PyGTK TreeView | 2,014,804 | <p>How can I word wrap text inside a PyGTK TreeView?</p>
| 4 | 2010-01-06T17:20:43Z | 2,342,415 | <p>The answer directing at my blog post, was from before I figured out how to do it 'properly'
as Kai already answered just setting wrap width and wrap mode works on a TextCellRenderer
in my current custom renderer I use:</p>
<pre><code>layout = cairo_context.create_layout()
font = pango.FontDescription("Sans")
font.s... | 1 | 2010-02-26T14:52:32Z | [
"python",
"pygtk",
"word-wrap"
] |
How does one do async ajax calls using cherrypy? | 2,015,065 | <p>I'm using cherrypy's standalone server (cherrypy.quickstart()) and sqlite3 for a database.</p>
<p>I was wondering how one would do ajax/jquery asynchronous calls to the database while using cherrypy?</p>
| 1 | 2010-01-06T17:57:47Z | 2,015,344 | <p>The same way you would do them using any other webserver - by getting your javascript to call a URL which is handled by the server-side application.</p>
| 2 | 2010-01-06T18:47:52Z | [
"jquery",
"python",
"ajax",
"asynchronous",
"cherrypy"
] |
How does one do async ajax calls using cherrypy? | 2,015,065 | <p>I'm using cherrypy's standalone server (cherrypy.quickstart()) and sqlite3 for a database.</p>
<p>I was wondering how one would do ajax/jquery asynchronous calls to the database while using cherrypy?</p>
| 1 | 2010-01-06T17:57:47Z | 2,040,679 | <p>If you are using CherryPy <a href="http://www.cherrypy.org/browser/tags/cherrypy-3.2.0rc1">3.2.0-rc1</a> then you can use the decorators <code>@json_in</code> and <code>@json_out</code> (<a href="http://www.cherrypy.org/wiki/WhatsNewIn32#Tools">see here</a>).</p>
<p>Thus:</p>
<pre><code>@cherrypy.expose
@tools.jso... | 9 | 2010-01-11T08:42:11Z | [
"jquery",
"python",
"ajax",
"asynchronous",
"cherrypy"
] |
How does this formatting code work? | 2,015,117 | <p>I always have to know why, rather than just how, so here I go:</p>
<p>How does this work:</p>
<pre><code>'{0:01.2f}'.format(5.555) #returns '5.55'
'{0:01.1f}'.format(5.555) #returns '5.5'
'{0:1.2f}'.format(5.555) #returns '5.55' again
'{0:1.1f}'.format(5.555) #returns '5.5' again
</code></pre>
<p>Why doe... | 0 | 2010-01-06T18:03:28Z | 2,015,142 | <p>Its because the 0 character enables zero-padding, but you have a width of 1 set. Set the width to 2 (like <code>'{0:02.1f}'</code> and you will see a leading 0.</p>
<p><strong>Edit</strong> - actually, I'm not sure if 2 will suffice, because I don't know how it behaves with more digits after the decimal point. So... | 5 | 2010-01-06T18:08:52Z | [
"python",
"string"
] |
How does this formatting code work? | 2,015,117 | <p>I always have to know why, rather than just how, so here I go:</p>
<p>How does this work:</p>
<pre><code>'{0:01.2f}'.format(5.555) #returns '5.55'
'{0:01.1f}'.format(5.555) #returns '5.5'
'{0:1.2f}'.format(5.555) #returns '5.55' again
'{0:1.1f}'.format(5.555) #returns '5.5' again
</code></pre>
<p>Why doe... | 0 | 2010-01-06T18:03:28Z | 2,015,169 | <p>You should specify a width taking into account all the characters, including the decimals and the dot. If you want 05.55 that's 5 characters, so:</p>
<pre><code>>>>'{0:05.2f}'.format(5.555)
'05.55'
</code></pre>
| 2 | 2010-01-06T18:14:41Z | [
"python",
"string"
] |
How to create class instance inside that class method? | 2,015,306 | <p>I want to create class instance inside itself. I tried to it by this way:</p>
<pre><code>class matrix:
(...)
def det(self):
(...)
m = self(sz-1, sz-1)
(...)
(...)
</code></pre>
<p>but I got error:</p>
<blockquote>
<pre><code>m = self(sz-1, sz-1)
</code></pre>
<p>AttributeE... | 5 | 2010-01-06T18:40:50Z | 2,015,324 | <pre><code>m = self.__class__(sz-1, sz-1)
</code></pre>
<p>or</p>
<pre><code>m = type(self)(sz-1, sz-1)
</code></pre>
| 9 | 2010-01-06T18:43:52Z | [
"python",
"class",
"instance"
] |
What's the difference between quantize() and str.format()? | 2,015,359 | <p>I don't mean what's the technical difference, but rather, what's the faster/more logical or Pythonic, etc. way to do this:</p>
<pre><code> def __quantized_price(self):
TWOPLACES = Decimal(10) ** -2
return self.price.quantize(TWOPLACES)
</code></pre>
<p>or</p>
<pre><code> def __formatted_pric... | 3 | 2010-01-06T18:49:11Z | 2,015,477 | <p><code>Decimal.quantize</code> returns a new <code>Decimal</code> that has a different value.</p>
<p><code>''.format()</code> formats a string. </p>
<p>In this particular case printing the result yields the same output. Other than that they are totally different operations returning totally different types. </p>
| 7 | 2010-01-06T19:11:11Z | [
"python",
"django",
"string",
"quantization"
] |
Using a list objects to look up items in a dictionary in Python | 2,015,385 | <p>I have a a wxPython checklist box that returns a list of integers. I want to use the integers to look up items in a dictionary. I am not really sure the best way to do this. Any suggestions?</p>
| 0 | 2010-01-06T18:53:48Z | 2,015,405 | <p>Are you asking for</p>
<pre><code>[ someDict[k] for k in someList ]
</code></pre>
<p>?</p>
| 7 | 2010-01-06T18:56:56Z | [
"python",
"list",
"dictionary"
] |
Custom Django template tag to look up a string username and return it as a user object | 2,015,740 | <p>I use some third-party template tags in my Django Application (maintained elsewhere) that return a username as a string I can access in my templates like this.</p>
<pre><code>{% for user in gr.user.foll.list %}
{{user}}
</code></pre>
<p>Trouble is because {{user}} is returned as a string - I need to convert into... | 0 | 2010-01-06T19:53:40Z | 2,016,060 | <p>use a template filter like so:</p>
<pre><code>{{username|get_user}}
</code></pre>
<p>in your user_template_tags.py:</p>
<pre><code>from django import template
from django.contrib.auth.models import User
register = template.Library()
########################
def get_user(username):
try:
user = User.... | 3 | 2010-01-06T20:39:30Z | [
"python",
"django",
"django-templates"
] |
wxpython systray icon menu | 2,015,969 | <p>I'm designing an application that I want to run in the background. There isn't any user interaction necessary, so I want the app to run invisibly save for a systray icon. I want that icon to have a menu that just opens the config/help files in notepad. Could someone point me in the right direction or provide an exam... | 1 | 2010-01-06T20:27:00Z | 2,016,022 | <p>Have you considered running this application as a windows service? Many users will consider a system tray icon with little to no functionality a nuisance. You could still provide links to help/config files as a start menu entry.</p>
<p>The python <a href="http://starship.python.net/crew/mhammond/win32/Downloads.h... | 3 | 2010-01-06T20:33:55Z | [
"python",
"wxpython"
] |
wxpython systray icon menu | 2,015,969 | <p>I'm designing an application that I want to run in the background. There isn't any user interaction necessary, so I want the app to run invisibly save for a systray icon. I want that icon to have a menu that just opens the config/help files in notepad. Could someone point me in the right direction or provide an exam... | 1 | 2010-01-06T20:27:00Z | 2,016,090 | <p>You want the wx.TaskBarIcon:</p>
<p><a href="http://docs.wxwidgets.org/stable/wx_wxtaskbaricon.html" rel="nofollow">http://docs.wxwidgets.org/stable/wx_wxtaskbaricon.html</a></p>
<p>The wxPython Demo has example code you can look at.</p>
| 2 | 2010-01-06T20:44:27Z | [
"python",
"wxpython"
] |
wxpython systray icon menu | 2,015,969 | <p>I'm designing an application that I want to run in the background. There isn't any user interaction necessary, so I want the app to run invisibly save for a systray icon. I want that icon to have a menu that just opens the config/help files in notepad. Could someone point me in the right direction or provide an exam... | 1 | 2010-01-06T20:27:00Z | 2,090,684 | <p>You can probably do this more cleanly but I have using some samples a while back I was able to create myself a class to handle the basic contruction of a taskbar icon.</p>
<p>TaskBarIcon.py</p>
<pre><code>import wx
ID_SHOW_OPTION = wx.NewId()
ID_EDIT_OPTION = wx.NewId()
class Icon(wx.TaskBarIcon):
def __i... | 5 | 2010-01-19T02:31:12Z | [
"python",
"wxpython"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,024 | <p>I don't think break; throws a StopIteration. </p>
<p>You generally don't want to use exceptions for flow control like that.</p>
| 0 | 2010-01-06T20:34:24Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,047 | <p>Go through each file once, adding each record to a hash with value equal to 1. Then make sure that the keys of the first hash are a subset of the keys of the second.</p>
<pre><code>hashes = []
for f in ["file1.txt","file2.txt"]:
lines = open(f,"r").readlines()
hash = {}
for line in lines:
hash[... | 0 | 2010-01-06T20:37:20Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,064 | <p>Use sets instead:</p>
<pre><code>set1=set(line[:6] for line in open('file1.txt'))
set2=set(line[:6] for line in open('file2.txt'))
not_found = set1 - set2
if not_found:
print "Some keys not found: " + ', '.join(not_found)
</code></pre>
| 3 | 2010-01-06T20:40:28Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,087 | <p>I think this might be closer to what you want:</p>
<pre><code>unvalues = dict((line[:6], line[6:14]) for line in open("file1.txt", "r"))
newfunds = [line for line in open("file2.txt", "r")]
for i, line in enumerate(newfunds):
key = line.strip()
if key in unvalues:
v = unvalues[key]
print "%s... | 0 | 2010-01-06T20:44:17Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,102 | <pre><code>first_file=open("file1.txt","r")
#save all items from first file into a set
first_file_items=set(line.strip() for line in first_file)
second_file=open("file2.txt","r")
for line in second_file:
if line[:6] in first_file_items:
#if this is item from the first file, remove it from the set
first... | 2 | 2010-01-06T20:46:19Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,138 | <p>You cannot (and need not) catch the StopIteration exception that occurs when the iterator is finished, because it gets caught by the for loop automatically. To do what you appear to be trying to do, you could use an else block after your for block, e.g. you could replace your inner loop with this:</p>
<pre><code>fo... | 0 | 2010-01-06T20:52:07Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,209 | <pre><code>from collections import defaultdict
unvalues = open("file1.txt", "r").readlines()
newfunds = open("file2.txt", "r").readlines()
unvals = defaultdict(int)
for val in unvalues:
unvals[val] = 0
for line in newfunds:
line = line.strip()
if line[:6] in unvals.keys():
unvals[line[:6]] += 1... | 0 | 2010-01-06T21:02:28Z | [
"python"
] |
Search a file for strings from a second file | 2,016,006 | <p>I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may ... | 2 | 2010-01-06T20:31:58Z | 2,016,322 | <p>Another approach using sets</p>
<pre><code>keys = set(line[:6] for line in open('file.txt'))
missing = set(value[:6] for value in open('file2.txt') if value[:6] not in keys)
if missing:
print "Keys Missing " + ', '.join(missing)
</code></pre>
| 0 | 2010-01-06T21:18:47Z | [
"python"
] |
Trick code completion with PyDev like with PDT? | 2,016,269 | <p>Is there a way to help PyDev code completion by telling it the type of a variable?</p>
<p>With PDT, you can use PHPDoc-like syntax for such purpose:</p>
<pre><code>/* @var $my_var MyClass */
$my_var = myFunction();
// PDT is able to figure out that $my_var is a MyClass object.
</code></pre>
<p>But till now, I can... | 3 | 2010-01-06T21:11:52Z | 2,016,820 | <p>Nope (see the <a href="http://github.com/aptana/Pydev/blob/master/plugins/com.python.pydev.docs/features/code_completion.txt" rel="nofollow">docs</a>). It looks like PyDev does completion of imported stuff and language keywords. </p>
<p>It doesn't seem like this would come up a lot though. The variable in question ... | 1 | 2010-01-06T22:30:55Z | [
"python",
"pydev",
"code-completion"
] |
Trick code completion with PyDev like with PDT? | 2,016,269 | <p>Is there a way to help PyDev code completion by telling it the type of a variable?</p>
<p>With PDT, you can use PHPDoc-like syntax for such purpose:</p>
<pre><code>/* @var $my_var MyClass */
$my_var = myFunction();
// PDT is able to figure out that $my_var is a MyClass object.
</code></pre>
<p>But till now, I can... | 3 | 2010-01-06T21:11:52Z | 2,066,903 | <p>Actually, you can if you do an assert isinstance()</p>
<p>E.g.:</p>
<pre><code>a = function()
assert isinstance(a, MyClass)
a. <- would get the proper completions
</code></pre>
<p>Note that Pydev does analyze the return of the functions, so, it's possible that it knows that on a number of cases.</p>
<p>Also, ... | 3 | 2010-01-14T19:25:28Z | [
"python",
"pydev",
"code-completion"
] |
Trick code completion with PyDev like with PDT? | 2,016,269 | <p>Is there a way to help PyDev code completion by telling it the type of a variable?</p>
<p>With PDT, you can use PHPDoc-like syntax for such purpose:</p>
<pre><code>/* @var $my_var MyClass */
$my_var = myFunction();
// PDT is able to figure out that $my_var is a MyClass object.
</code></pre>
<p>But till now, I can... | 3 | 2010-01-06T21:11:52Z | 7,442,513 | <p>The assert trick does not seem to work for me with PyDev 2.2.2 ; it is still supposed to ?</p>
<p>However another trick I tried and that work is the following :</p>
<pre><code>class Foo(object):
def __init__(self, bar):
self.bar = bar
# Tricking PyDev
if (not self.bar):
self.bar ... | 3 | 2011-09-16T09:18:22Z | [
"python",
"pydev",
"code-completion"
] |
Python/Django: If 5 and 5.00 are different values (when expressed in Decimal), then | 2,016,292 | <p>If 5 and 5.00 and 5.000 are all different, then why does Django's decimal field save without the .00 even when I have decimal_places=2</p>
<p>?</p>
<p>More importantly, how can I save a value 5.00 as 5.00 in Django without using String.</p>
| 0 | 2010-01-06T21:14:15Z | 2,016,387 | <p>I think it would be more correct to say those are different <em>representations</em> of the same value '5'. </p>
<p>Internally, the value saved (unless you're actually storing a string) is 5.</p>
<p>When the value is displayed, ie converted to a string representation for the screen, it might be shown as 5, 5.00 or... | 3 | 2010-01-06T21:28:54Z | [
"python",
"django",
"decimal"
] |
Python/Django: If 5 and 5.00 are different values (when expressed in Decimal), then | 2,016,292 | <p>If 5 and 5.00 and 5.000 are all different, then why does Django's decimal field save without the .00 even when I have decimal_places=2</p>
<p>?</p>
<p>More importantly, how can I save a value 5.00 as 5.00 in Django without using String.</p>
| 0 | 2010-01-06T21:14:15Z | 2,016,478 | <p>You have an argument that Django ought to enforce a certain precision on its Python objects, but <code>decimal_places</code> is probably more about maximum precision. I believe precision is not stored in the database, so it will be lost in any case.</p>
<p>In any case, if you want to enforce precision, use somethin... | 2 | 2010-01-06T21:42:59Z | [
"python",
"django",
"decimal"
] |
Creating several profile classes in django | 2,016,452 | <p>I'm getting started with django and I'd like to extend the basic <code>django.contrib.auth.models.User</code> class to create my own site profile(s). <a href="http://docs.djangoproject.com/en/1.1/topics/auth/#storing-additional-information-about-users" rel="nofollow">Here</a> is described how to do it, got that.</p>... | 0 | 2010-01-06T21:38:19Z | 2,016,519 | <p>There can be only one profile class. I guess I don't understand the scenario where you would want to split them up. In any case,</p>
<pre><code>AUTH_PROFILE_MODULE = "UserProfileExtended"
</code></pre>
<p>should handle the inheritance correctly for the simple example you give.</p>
| 1 | 2010-01-06T21:47:54Z | [
"python",
"django",
"profile"
] |
python imaplib ssl error using celeryd queue | 2,016,516 | <p>I'm having a problem using imaplib on python 2.6 with the latest django svn. I want to download imap emails in a queue (using celeryd). I'm able to connect/download emails from the command line, but when i offload the task through django to celeryd i get this error: "SSLError: [Errno 1] _ssl.c:1325: error:1408F10B:S... | 2 | 2010-01-06T21:47:37Z | 2,016,546 | <p>You're connecting to a port that is not speaking TLS. Are you trying to talk to a TLS/SSL enabled mail server, or is celery trying to use TLS for its AMQP connection?</p>
| 0 | 2010-01-06T21:51:47Z | [
"python",
"django",
"celery"
] |
python imaplib ssl error using celeryd queue | 2,016,516 | <p>I'm having a problem using imaplib on python 2.6 with the latest django svn. I want to download imap emails in a queue (using celeryd). I'm able to connect/download emails from the command line, but when i offload the task through django to celeryd i get this error: "SSLError: [Errno 1] _ssl.c:1325: error:1408F10B:S... | 2 | 2010-01-06T21:47:37Z | 2,027,091 | <p>If it only breaks when run inside the celery worker, there might be something with amqplib (which uses the ssl module) or it could be something with multiprocessing and forking (a global variable that was initialized before the fork that is no longer alive)</p>
<p>Could you please include the task you're trying to ... | 1 | 2010-01-08T11:03:48Z | [
"python",
"django",
"celery"
] |
python imaplib ssl error using celeryd queue | 2,016,516 | <p>I'm having a problem using imaplib on python 2.6 with the latest django svn. I want to download imap emails in a queue (using celeryd). I'm able to connect/download emails from the command line, but when i offload the task through django to celeryd i get this error: "SSLError: [Errno 1] _ssl.c:1325: error:1408F10B:S... | 2 | 2010-01-06T21:47:37Z | 2,125,016 | <p>According to the creator of celeryd:</p>
<p>Celery no longer does its own detaching as of 01a8a0e. There has been far too many problems with it, and since it works when detaching using start-stop-daemon, supervisord, launchd and so on, you are encouraged to use those tools instead.</p>
| 1 | 2010-01-23T22:27:14Z | [
"python",
"django",
"celery"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,620 | <p>Sounds like something like Adobe Air, Microsoft's Silverlight, or Appcelerators Titanium is what you want.</p>
| 3 | 2010-01-06T22:05:24Z | [
"php",
"python",
"mysql",
"widget"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,628 | <p>Or <a href="http://widgets.yahoo.com/tools/" rel="nofollow">Yahoo Widgets</a>. <strong>now discontinued</strong></p>
| 0 | 2010-01-06T22:06:04Z | [
"php",
"python",
"mysql",
"widget"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,639 | <p>Should it be OS independent? Widgets for Apple's dashboard are just HTML, CSS and Javascript.</p>
| 0 | 2010-01-06T22:09:19Z | [
"php",
"python",
"mysql",
"widget"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,648 | <p>Adobe Air is the popular solution to this problem these days</p>
| 2 | 2010-01-06T22:10:37Z | [
"php",
"python",
"mysql",
"widget"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,666 | <p>Check out <a href="http://www.activestate.com/activetcl/" rel="nofollow">Tcl</a>. Then use <a href="http://www.equi4.com/starkit/" rel="nofollow">starkit/starpack</a> or <a href="http://freewrap.sourceforge.net/" rel="nofollow">freewrap</a> to generate your stand-alone app. Tcl gets little love from the general deve... | 0 | 2010-01-06T22:13:42Z | [
"php",
"python",
"mysql",
"widget"
] |
What programs are used to build standalone desktop widgets that interact with online php and mysql? | 2,016,609 | <p>I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must.</p>
<p>This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up o... | 0 | 2010-01-06T22:02:30Z | 2,016,684 | <p>The others here are basically right. You don't specify what the platform you want to put this on. You have a couple of options:</p>
<ol>
<li>Native program. This can be made to require no installation. This would be Win32/MFC and C/C++, or Cocoa and Objective-C. Not necessarily easy to program (fetching a web page ... | 1 | 2010-01-06T22:15:54Z | [
"php",
"python",
"mysql",
"widget"
] |
Problem while building a PyQt script with py2exe (QtCore) | 2,016,658 | <p>I'm trying to make a simple hello-world executable python gui app in windows using pyqt. So I've made the <code>pyqt.py</code> file</p>
<pre><code>import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()
</code></pre>
<p>I tried to use py... | 1 | 2010-01-06T22:12:22Z | 2,016,895 | <p>Add <code>from PyQt4.QtCore import *</code> to pyqt.py.</p>
<p>I'm not sure why it wasn't auto-included, but I think it has something to do with QtCore only being used by QtGui, which is a C++ lib... Like, py2exe only auto-detects python dependencies... So you have to import it manually.</p>
| 2 | 2010-01-06T22:40:45Z | [
"python",
"pyqt",
"py2exe"
] |
Problem while building a PyQt script with py2exe (QtCore) | 2,016,658 | <p>I'm trying to make a simple hello-world executable python gui app in windows using pyqt. So I've made the <code>pyqt.py</code> file</p>
<pre><code>import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()
</code></pre>
<p>I tried to use py... | 1 | 2010-01-06T22:12:22Z | 2,022,589 | <p>You can do something like this, you don't need import *. </p>
<pre><code>py2exe_opciones = {'py2exe': {"includes":["sip"]}}
script = [{"script":"pyqt.py"}]
setup(windows=script,options=py2exe_opciones)
</code></pre>
<p>And now will the program should work. I had the same error.</p>
<p><a href="http://www.py2exe.... | 3 | 2010-01-07T18:20:50Z | [
"python",
"pyqt",
"py2exe"
] |
Problem while building a PyQt script with py2exe (QtCore) | 2,016,658 | <p>I'm trying to make a simple hello-world executable python gui app in windows using pyqt. So I've made the <code>pyqt.py</code> file</p>
<pre><code>import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()
</code></pre>
<p>I tried to use py... | 1 | 2010-01-06T22:12:22Z | 37,532,411 | <p>this is an example</p>
<pre><code>from setuptools import setup
import py2exe
from glob import glob
SETUP_DICT = {
'windows': [{
'script': 'main.py',
}],
'zipfile': 'lib/library.zip',
'data_files': (
('', glob(r'C:\Windows\SYSTEM32\msvcp100.dll')),
('', glob(r'C:\Windows\SY... | 0 | 2016-05-30T19:19:21Z | [
"python",
"pyqt",
"py2exe"
] |
Have writen a program to extract text from a PDF in python, and now need to make it run for every PDF in the folder and save as a text file | 2,016,777 | <p>So far here is the code I have (it is working and extracting text as it should.)</p>
<pre><code>import pyPdf
def getPDFContent(path):
content = ""
# Load PDF into pyPDF
pdf = pyPdf.PdfFileReader(file(path, "rb"))
# Iterate pages
for i in range(0, pdf.getNumPages()):
# Extract text from ... | 0 | 2010-01-06T22:26:18Z | 2,016,821 | <p>Take a look at <a href="http://docs.python.org/library/os.html" rel="nofollow"><code>os.walk()</code></a></p>
| 4 | 2010-01-06T22:31:02Z | [
"python",
"pdf",
"csv"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.