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 |
|---|---|---|---|---|---|---|---|---|---|
Django MTMField: limit_choices_to = other_ForeignKeyField_on_same_model? | 345,401 | <p>I've got a couple django models that look like this:</p>
<pre><code>from django.contrib.sites.models import Site
class Photo(models.Model):
title = models.CharField(max_length=100)
site = models.ForeignKey(Site)
file = models.ImageField(upload_to=get_site_profile_path)
def __unicode__(self):
... | 5 | 2008-12-05T22:32:52Z | 345,419 | <p>According to the <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield" rel="nofollow">docs</a>, "limit_choices_to has no effect when used on a ManyToManyField with an intermediate table". By my reading, that means it has no effect at all, because ManyToManyFields use intermediate tables.... | 0 | 2008-12-05T22:41:04Z | [
"python",
"django",
"foreign-keys",
"manytomanyfield",
"limit-choices-to"
] |
Django MTMField: limit_choices_to = other_ForeignKeyField_on_same_model? | 345,401 | <p>I've got a couple django models that look like this:</p>
<pre><code>from django.contrib.sites.models import Site
class Photo(models.Model):
title = models.CharField(max_length=100)
site = models.ForeignKey(Site)
file = models.ImageField(upload_to=get_site_profile_path)
def __unicode__(self):
... | 5 | 2008-12-05T22:32:52Z | 345,529 | <p>I would delete <code>site</code> field on my <code>Photo</code> model and add a <code>ForeignKey</code> to <code>Gallery</code>. I would remove <code>limit_choices_to</code> from <code>photos</code> fields on <code>Gallery</code> model.</p>
<p>Because you are using <code>ForeignKey</code>s to <code>Site</code>s, th... | 1 | 2008-12-05T23:41:56Z | [
"python",
"django",
"foreign-keys",
"manytomanyfield",
"limit-choices-to"
] |
Django MTMField: limit_choices_to = other_ForeignKeyField_on_same_model? | 345,401 | <p>I've got a couple django models that look like this:</p>
<pre><code>from django.contrib.sites.models import Site
class Photo(models.Model):
title = models.CharField(max_length=100)
site = models.ForeignKey(Site)
file = models.ImageField(upload_to=get_site_profile_path)
def __unicode__(self):
... | 5 | 2008-12-05T22:32:52Z | 1,881,187 | <p>Yes. You need to override the form that admin uses for the <code>Gallery</code> model, then limit the queryset of the <code>photos</code> field in that form:</p>
<pre><code>class GalleryAdminForm(django.forms.ModelForm):
class Meta:
model = Gallery
def __init__(self, *args, **kwargs):
sup... | 3 | 2009-12-10T14:03:46Z | [
"python",
"django",
"foreign-keys",
"manytomanyfield",
"limit-choices-to"
] |
Is this idiom pythonic? (someBool and "True Result" or "False Result") | 345,745 | <p>I just came across this idiom in some open-source Python, and I choked on my drink.</p>
<p>Rather than:</p>
<pre><code>if isUp:
return "Up"
else:
return "Down"
</code></pre>
<p>or even:</p>
<pre><code>return "Up" if isUp else "Down"
</code></pre>
<p>the code read:</p>
<pre><code>return isUp and "Up" or... | 7 | 2008-12-06T01:57:04Z | 345,752 | <p>That code is a big fugly and clever for my tastes, but I suppose there's not anything wrong with it per se. I think this is really just a case of "make it all fit in one line" syndrome.</p>
<p>I personally would have opted for the first form though.</p>
| 0 | 2008-12-06T02:03:13Z | [
"coding-style",
"python"
] |
Is this idiom pythonic? (someBool and "True Result" or "False Result") | 345,745 | <p>I just came across this idiom in some open-source Python, and I choked on my drink.</p>
<p>Rather than:</p>
<pre><code>if isUp:
return "Up"
else:
return "Down"
</code></pre>
<p>or even:</p>
<pre><code>return "Up" if isUp else "Down"
</code></pre>
<p>the code read:</p>
<pre><code>return isUp and "Up" or... | 7 | 2008-12-06T01:57:04Z | 345,764 | <p>No, it is not.</p>
<p>I had a somehow <a href="http://stackoverflow.com/questions/331767">similar question</a> the other day. </p>
<p>if the construct </p>
<pre><code>val if cond else alt
</code></pre>
<p>Was not very welcome ( at least by the SO community ) and the preferred one was:</p>
<pre><code>if cond:
... | -1 | 2008-12-06T02:10:02Z | [
"coding-style",
"python"
] |
Is this idiom pythonic? (someBool and "True Result" or "False Result") | 345,745 | <p>I just came across this idiom in some open-source Python, and I choked on my drink.</p>
<p>Rather than:</p>
<pre><code>if isUp:
return "Up"
else:
return "Down"
</code></pre>
<p>or even:</p>
<pre><code>return "Up" if isUp else "Down"
</code></pre>
<p>the code read:</p>
<pre><code>return isUp and "Up" or... | 7 | 2008-12-06T01:57:04Z | 345,773 | <p>The "a and b or c" idiom was the canonical way to express the ternary arithmetic if in Python, before <a href="http://www.python.org/dev/peps/pep-0308/" rel="nofollow">PEP 308</a> was written and implemented. This idiom fails the "b" answer is false itself; to support the general case, you could write</p>
<pre><cod... | 17 | 2008-12-06T02:14:46Z | [
"coding-style",
"python"
] |
Is this idiom pythonic? (someBool and "True Result" or "False Result") | 345,745 | <p>I just came across this idiom in some open-source Python, and I choked on my drink.</p>
<p>Rather than:</p>
<pre><code>if isUp:
return "Up"
else:
return "Down"
</code></pre>
<p>or even:</p>
<pre><code>return "Up" if isUp else "Down"
</code></pre>
<p>the code read:</p>
<pre><code>return isUp and "Up" or... | 7 | 2008-12-06T01:57:04Z | 345,774 | <p>Yikes. Not readable at all. For me pythonic means easy to read.</p>
<pre><code>return isUp and "Up" or "Down"
</code></pre>
<p>Sounds something you would do in perl.</p>
| -1 | 2008-12-06T02:15:53Z | [
"coding-style",
"python"
] |
Is this idiom pythonic? (someBool and "True Result" or "False Result") | 345,745 | <p>I just came across this idiom in some open-source Python, and I choked on my drink.</p>
<p>Rather than:</p>
<pre><code>if isUp:
return "Up"
else:
return "Down"
</code></pre>
<p>or even:</p>
<pre><code>return "Up" if isUp else "Down"
</code></pre>
<p>the code read:</p>
<pre><code>return isUp and "Up" or... | 7 | 2008-12-06T01:57:04Z | 345,775 | <p>You should read <a href="http://www.diveintopython.net/power_of_introspection/and_or.html" rel="nofollow">Using the and-or trick</a> (section 4.6.1) of <i>Dive Into Python</i> by Mark Pilgrim. It turns out that the and-or trick has major pitfalls you should be aware of.</p>
| 9 | 2008-12-06T02:20:46Z | [
"coding-style",
"python"
] |
Refactoring python module configuration to avoid relative imports | 345,746 | <p>This is related to a <a href="http://stackoverflow.com/questions/343517/how-do-i-work-with-multiple-git-branches-of-a-python-module">previous question</a> of mine.</p>
<p>I understand how to store and read configuration files. There are choices such as <a href="http://www.python.org/doc/2.5.2/lib/module-ConfigParse... | 3 | 2008-12-06T01:57:34Z | 345,790 | <p>require statement from <a href="http://peak.telecommunity.com/DevCenter/PkgResources#basic-workingset-methods" rel="nofollow">pkg_resources</a> maybe what you need. </p>
| 0 | 2008-12-06T02:35:54Z | [
"python",
"configuration",
"module"
] |
Refactoring python module configuration to avoid relative imports | 345,746 | <p>This is related to a <a href="http://stackoverflow.com/questions/343517/how-do-i-work-with-multiple-git-branches-of-a-python-module">previous question</a> of mine.</p>
<p>I understand how to store and read configuration files. There are choices such as <a href="http://www.python.org/doc/2.5.2/lib/module-ConfigParse... | 3 | 2008-12-06T01:57:34Z | 345,799 | <p>As I understand it from this and previous questions you only need one path to be in <code>sys.path</code>. If we are talking about <code>git</code> as VCS (mentioned in previous question) when only one branch is checked out at any time (single working directory). You can switch, merge branches as frequently as you l... | 0 | 2008-12-06T02:41:41Z | [
"python",
"configuration",
"module"
] |
Refactoring python module configuration to avoid relative imports | 345,746 | <p>This is related to a <a href="http://stackoverflow.com/questions/343517/how-do-i-work-with-multiple-git-branches-of-a-python-module">previous question</a> of mine.</p>
<p>I understand how to store and read configuration files. There are choices such as <a href="http://www.python.org/doc/2.5.2/lib/module-ConfigParse... | 3 | 2008-12-06T01:57:34Z | 345,921 | <p>I'm thinking of something along the lines of a more 'push-based' kind of solution. Instead of importing the shared objects (be they for configuration, or utility functions of some sort), have the top-level <strong>init</strong> export it, and each intermediate <strong>init</strong> import it from the layer above, an... | 0 | 2008-12-06T04:38:19Z | [
"python",
"configuration",
"module"
] |
Refactoring python module configuration to avoid relative imports | 345,746 | <p>This is related to a <a href="http://stackoverflow.com/questions/343517/how-do-i-work-with-multiple-git-branches-of-a-python-module">previous question</a> of mine.</p>
<p>I understand how to store and read configuration files. There are choices such as <a href="http://www.python.org/doc/2.5.2/lib/module-ConfigParse... | 3 | 2008-12-06T01:57:34Z | 346,330 | <p>"imports ... require your module to be on your PYTHONPATH"</p>
<p>Right. </p>
<p>So, what's wrong with setting <code>PYTHONPATH</code>?</p>
| 2 | 2008-12-06T14:41:43Z | [
"python",
"configuration",
"module"
] |
Refactoring python module configuration to avoid relative imports | 345,746 | <p>This is related to a <a href="http://stackoverflow.com/questions/343517/how-do-i-work-with-multiple-git-branches-of-a-python-module">previous question</a> of mine.</p>
<p>I understand how to store and read configuration files. There are choices such as <a href="http://www.python.org/doc/2.5.2/lib/module-ConfigParse... | 3 | 2008-12-06T01:57:34Z | 347,027 | <p>You can trick the import mechanism, by adding each subdirectory to <code>egg/__init__.py</code>:</p>
<pre><code>__path__.append(__path__[0]+"\\common")
__path__.append(__path__[0]+"\\foo")
</code></pre>
<p>then, you simply import all modules from the egg namespace; e.g. <code>import egg.bar</code> (provided you ha... | 0 | 2008-12-07T00:19:24Z | [
"python",
"configuration",
"module"
] |
Python - No handlers could be found for logger "OpenGL.error" | 345,991 | <p>Okay, what is it, and why does it occur on Win2003 server, but not on WinXP.</p>
<p>It doesn't seem to affect my application at all, but I get this error message when I close the application. And it's annoying (as errors messages should be).</p>
<p>I am using pyOpenGl and wxPython to do the graphics stuff. Unfor... | 64 | 2008-12-06T05:59:43Z | 346,501 | <p>Looks like OpenGL is trying to report some error on Win2003, however you've not configured your system where to output logging info.</p>
<p>You can add the following to the beginning of your program and you'll see details of the error in stderr.</p>
<pre><code>import logging
logging.basicConfig()
</code></pre>
<p... | 156 | 2008-12-06T17:18:34Z | [
"python",
"logging",
"opengl",
"wxpython",
"pyopengl"
] |
Python - No handlers could be found for logger "OpenGL.error" | 345,991 | <p>Okay, what is it, and why does it occur on Win2003 server, but not on WinXP.</p>
<p>It doesn't seem to affect my application at all, but I get this error message when I close the application. And it's annoying (as errors messages should be).</p>
<p>I am using pyOpenGl and wxPython to do the graphics stuff. Unfor... | 64 | 2008-12-06T05:59:43Z | 369,184 | <p>After adding the Logging above, I was able to see that the problem was caused by missing TConstants class, which I was excluding in the py2exe setup.py file. </p>
<p>After removing the "Tconstants" from the excluded list, I no longer had problems.</p>
| 2 | 2008-12-15T17:52:46Z | [
"python",
"logging",
"opengl",
"wxpython",
"pyopengl"
] |
Python - No handlers could be found for logger "OpenGL.error" | 345,991 | <p>Okay, what is it, and why does it occur on Win2003 server, but not on WinXP.</p>
<p>It doesn't seem to affect my application at all, but I get this error message when I close the application. And it's annoying (as errors messages should be).</p>
<p>I am using pyOpenGl and wxPython to do the graphics stuff. Unfor... | 64 | 2008-12-06T05:59:43Z | 19,071,788 | <p>The <a href="https://code.google.com/p/rainforce/wiki/WartsOfPython#Logging_hidden_magic_%282.x_tested,_3.x_unknown%29" rel="nofollow">proper way</a> to get rid of this message is to configure NullHandler for the root level logger of your library (OpenGL).</p>
| 3 | 2013-09-28T21:19:40Z | [
"python",
"logging",
"opengl",
"wxpython",
"pyopengl"
] |
Postgres - how to return rows with 0 count for missing data? | 346,132 | <p>I have unevenly distributed data(wrt date) for a few years (2003-2008). I want to query data for a given set of start and end date, grouping the data by any of the supported intervals (day, week, month, quarter, year) in PostgreSQL 8.3 (<a href="http://www.postgresql.org/docs/8.3/static/functions-datetime.html#FUNCT... | 9 | 2008-12-06T09:32:04Z | 346,187 | <p>You could create a temporary table at runtime and left join on that. That seems to make the most sense.</p>
| 0 | 2008-12-06T10:54:50Z | [
"python",
"database",
"postgresql"
] |
Postgres - how to return rows with 0 count for missing data? | 346,132 | <p>I have unevenly distributed data(wrt date) for a few years (2003-2008). I want to query data for a given set of start and end date, grouping the data by any of the supported intervals (day, week, month, quarter, year) in PostgreSQL 8.3 (<a href="http://www.postgresql.org/docs/8.3/static/functions-datetime.html#FUNCT... | 9 | 2008-12-06T09:32:04Z | 346,195 | <p>You can create the list of all first days of the last year (say) with</p>
<pre><code>select distinct date_trunc('month', (current_date - offs)) as date
from generate_series(0,365,28) as offs;
date
------------------------
2007-12-01 00:00:00+01
2008-01-01 00:00:00+01
2008-02-01 00:00:00+01
2008-03-01... | 16 | 2008-12-06T11:30:40Z | [
"python",
"database",
"postgresql"
] |
Postgres - how to return rows with 0 count for missing data? | 346,132 | <p>I have unevenly distributed data(wrt date) for a few years (2003-2008). I want to query data for a given set of start and end date, grouping the data by any of the supported intervals (day, week, month, quarter, year) in PostgreSQL 8.3 (<a href="http://www.postgresql.org/docs/8.3/static/functions-datetime.html#FUNCT... | 9 | 2008-12-06T09:32:04Z | 15,733,103 |
<p><sup>This question is old. But since fellow users picked it as master for a new duplicate I am adding a proper answer.</sup></p>
<h3>Proper solution</h3>
<pre class="lang-sql prettyprint-override"><code>SELECT *
FROM (
SELECT day::date
FROM generate_series(timestamp '2007-12-01'
... | 9 | 2013-03-31T18:44:22Z | [
"python",
"database",
"postgresql"
] |
Read file object as string in python | 346,230 | <p>I'm using <code>urllib2</code> to read in a page. I need to do a quick regex on the source and pull out a few variables but <code>urllib2</code> presents as a file object rather than a string.</p>
<p>I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert this ... | 26 | 2008-12-06T12:41:36Z | 346,237 | <p>You can use Python in interactive mode to search for solutions.</p>
<p>if <code>f</code> is your object, you can enter <code>dir(f)</code> to see all methods and attributes. There's one called <code>read</code>. Enter <code>help(f.read)</code> and it tells you that <code>f.read()</code> is the way to retrieve a str... | 73 | 2008-12-06T12:47:18Z | [
"python",
"file",
"urllib2"
] |
Read file object as string in python | 346,230 | <p>I'm using <code>urllib2</code> to read in a page. I need to do a quick regex on the source and pull out a few variables but <code>urllib2</code> presents as a file object rather than a string.</p>
<p>I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert this ... | 26 | 2008-12-06T12:41:36Z | 346,255 | <p>From the doc <a href="http://docs.python.org/library/stdtypes.html#file.read">file.read()</a> (my emphasis):</p>
<blockquote>
<p>file.read([size])</p>
<p>Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes). If the size argument is negative or omitted, read all data ... | 12 | 2008-12-06T13:07:39Z | [
"python",
"file",
"urllib2"
] |
Read file object as string in python | 346,230 | <p>I'm using <code>urllib2</code> to read in a page. I need to do a quick regex on the source and pull out a few variables but <code>urllib2</code> presents as a file object rather than a string.</p>
<p>I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert this ... | 26 | 2008-12-06T12:41:36Z | 346,260 | <p>Michael Foord, aka Voidspace has an excellent tutorial on urllib2 which you can find here:
<a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml">urllib2 - The Missing Manual</a></p>
<p>What you are doing should be pretty straightforward, observe this sample code:</p>
<pre><code>import urllib2
import... | 5 | 2008-12-06T13:17:59Z | [
"python",
"file",
"urllib2"
] |
Python regex | 346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ..... | 3 | 2008-12-06T13:31:05Z | 346,276 | <p>I would try <code>findall</code> or <code>finditer</code> instead of <code>match</code>.</p>
<p>Edit by Oli: Yeah <code>findall</code> work brilliantly but I had to simplify the regex to:</p>
<pre><code>r"'(?P<main>\d+)\[(?P<thumb>\d+)\]',?"
</code></pre>
| 5 | 2008-12-06T13:38:54Z | [
"python",
"regex"
] |
Python regex | 346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ..... | 3 | 2008-12-06T13:31:05Z | 346,281 | <p>Modifying your regexp a little,</p>
<pre><code>>>> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]"
>>> imgRegex = re.compile(r"'(?P<main>\d+)\[(?P<thumb>\d+)\]',?")
>>> print imgRegex.findall(str)
[('813702104', '813702106'), ('813702141', '81370214... | 1 | 2008-12-06T13:44:13Z | [
"python",
"regex"
] |
Python regex | 346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ..... | 3 | 2008-12-06T13:31:05Z | 346,284 | <p>I've got something that seems to work on your data set:</p>
<pre><code>In [19]: str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
In [20]: ptr = re.compile( r"'(?P<one>\d+)\[(?P<two>\d+)\]'" )
In [21]: ptr.findall( str )
Out [23]:
[('813702104', '813702106'),
('813702141', '8... | 1 | 2008-12-06T13:50:55Z | [
"python",
"regex"
] |
Python regex | 346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ..... | 3 | 2008-12-06T13:31:05Z | 346,292 | <p>I think I will not go for regex for this task. Python list comprehension is quite powerful for this</p>
<pre><code>In [27]: s = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
In [28]: d=[[int(each1.strip(']\'')) for each1 in each.split('[')] for each in s.split(',')]
In [29]: d[0][1]
Out[2... | 3 | 2008-12-06T13:54:34Z | [
"python",
"regex"
] |
Python regex | 346,267 | <p>I have a string like this that I need to parse into a 2D array:</p>
<pre><code> str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'"
</code></pre>
<p>the array equiv would be:</p>
<pre><code>arr[0][0] = 813702104
arr[0][1] = 813702106
arr[1][0] = 813702141
arr[1][1] = 813702143
#... etc ..... | 3 | 2008-12-06T13:31:05Z | 369,036 | <p>Alternatively, you could use Python's [<em>statement</em> for <em>item</em> in <em>list</em>] syntax for building lists. You should find this to be considerably faster than a regex, particularly for small data sets. Larger data sets will show a less marked difference (it only has to load the regular expressions en... | 1 | 2008-12-15T17:04:40Z | [
"python",
"regex"
] |
Installation problems with django-tagging | 346,426 | <p>I am having problems using <a href="http://code.google.com/p/django-tagging/" rel="nofollow">django-tagging</a>. I try to follow the <a href="http://code.google.com/p/django-tagging/source/browse/trunk/docs/overview.txt" rel="nofollow">documentation</a> but it fails at the second step</p>
<blockquote>
<p>Once you... | 1 | 2008-12-06T16:06:42Z | 346,435 | <p><a href="http://code.djangoproject.com/ticket/7680" rel="nofollow">http://code.djangoproject.com/ticket/7680</a></p>
<p>parse_lookup has been removed. Not sure how this will affect tagging. Might want to do some searching. </p>
<p>Update: apparently it's been fixed in the trunk version of tagging. Download the la... | 4 | 2008-12-06T16:16:15Z | [
"python",
"django",
"django-tagging"
] |
Installation problems with django-tagging | 346,426 | <p>I am having problems using <a href="http://code.google.com/p/django-tagging/" rel="nofollow">django-tagging</a>. I try to follow the <a href="http://code.google.com/p/django-tagging/source/browse/trunk/docs/overview.txt" rel="nofollow">documentation</a> but it fails at the second step</p>
<blockquote>
<p>Once you... | 1 | 2008-12-06T16:06:42Z | 346,441 | <p>I had the same bug me recently. I checked out the trunk release which seems to work fine. </p>
<pre><code>In [1]: import tagging; tagging.VERSION
Out[1]: (0, 3, 'pre')
</code></pre>
| 0 | 2008-12-06T16:22:13Z | [
"python",
"django",
"django-tagging"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 346,476 | <p>Well I couldn't find a Django way, but I did find a python way from inside my model:</p>
<pre><code>def format_price(self):
import locale
locale.setlocale(locale.LC_ALL, '')
return locale.format('%d', self.price, True)
</code></pre>
| 2 | 2008-12-06T16:56:39Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 346,633 | <p>If you don't want to get involved with locales here is a function that formats numbers:</p>
<pre><code>def int_format(value, decimal_points=3, seperator=u'.'):
value = str(value)
if len(value) <= decimal_points:
return value
# say here we have value = '12345' and the default params above
... | 11 | 2008-12-06T19:21:33Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 347,560 | <p>Django's contributed <a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#ref-contrib-humanize">humanize</a> application does this:</p>
<pre><code>{% load humanize %}
{{ my_num|intcomma }}
</code></pre>
<p>Be sure to add <code>'django.contrib.humanize'</code> to your <code>INSTALLED_APPS</code> list... | 162 | 2008-12-07T13:10:22Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 350,896 | <p>Be aware that changing locale is process-wide and not thread safe (iow., can have side effects or can affect other code executed within the same process).</p>
<p>My proposition: check out the <a href="http://babel.edgewall.org/" rel="nofollow">Babel</a> package. Some means of integrating with Django templates are a... | 1 | 2008-12-08T21:07:53Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 2,180,209 | <p>Regarding Ned Batchelder's solution, here it is with 2 decimal points and a dollar sign.</p>
<pre><code>from django.contrib.humanize.templatetags.humanize import intcomma
def currency(dollars):
dollars = round(float(dollars), 2)
return "$%s%s" % (intcomma(int(dollars)), ("%0.2f" % dollars)[-3:])
</code></p... | 47 | 2010-02-01T21:26:44Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 9,015,743 | <p>The <a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#ref-contrib-humanize" rel="nofollow">humanize app</a> offers a nice and a quick way of formatting a number but if you need to use a separator different from the comma, it's simple to just reuse <a href="https://code.djangoproject.com/browser/dja... | 2 | 2012-01-26T08:57:42Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 10,859,264 | <p>Building on other answers, to extend this to floats, you can do:</p>
<pre><code>{% load humanize %}
{{ floatvalue|floatformat:2|intcomma }}
</code></pre>
| 54 | 2012-06-02T02:02:31Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 15,121,424 | <p>The <a href="https://docs.djangoproject.com/en/dev/ref/contrib/humanize/">humanize</a> solution is fine if your website is in English. For other languages, you need another solution: I recommend using <a href="http://babel.edgewall.org/">Babel</a>. One solution is to create a custom template tag to display numbers... | 5 | 2013-02-27T20:11:20Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 21,868,438 | <p><em>Slightly off topic:</em></p>
<p>I found this question while looking for a way to format a number as currency, like so:</p>
<pre><code>$100
($50) # negative numbers without '-' and in parens
</code></pre>
<p>I ended up doing:</p>
<pre><code>{% if var >= 0 %} ${{ var|stringformat:"d" }}
{% elif var < ... | 2 | 2014-02-19T00:21:20Z | [
"python",
"django"
] |
Format numbers in django templates | 346,467 | <p>I'm trying to format numbers. Examples:</p>
<pre><code>1 => 1
12 => 12
123 => 123
1234 => 1,234
12345 => 12,345
</code></pre>
<p>It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.</p>
<p>Edit: If you've a generic Python way to do this, I'm h... | 83 | 2008-12-06T16:46:49Z | 37,607,860 | <p>Try adding the following line in settings.py:</p>
<pre><code>USE_THOUSAND_SEPARATOR = True
</code></pre>
<p>This should work.</p>
<p>Refer to <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-THOUSAND_SEPARATOR" rel="nofollow">documentation</a>.</p>
| 2 | 2016-06-03T06:56:37Z | [
"python",
"django"
] |
Is it more efficient to use "import <module>" or "from <module> import <func>"? | 346,723 | <p>Say I only needed to use findall() from the re module, is it more efficient to do:</p>
<pre><code>from re import findall
</code></pre>
<p>or </p>
<pre><code>import re
</code></pre>
<p>Is there actually any difference in speed/memory usage etc?</p>
| 3 | 2008-12-06T20:25:05Z | 346,741 | <p>There is no difference, except for what names from re are visible in you local namespace after the import.</p>
| 3 | 2008-12-06T20:35:50Z | [
"python",
"import"
] |
Is it more efficient to use "import <module>" or "from <module> import <func>"? | 346,723 | <p>Say I only needed to use findall() from the re module, is it more efficient to do:</p>
<pre><code>from re import findall
</code></pre>
<p>or </p>
<pre><code>import re
</code></pre>
<p>Is there actually any difference in speed/memory usage etc?</p>
| 3 | 2008-12-06T20:25:05Z | 346,753 | <p>There is no difference on the import, however there is a small difference on access.</p>
<p>When you access the function as</p>
<pre><code>re.findall()
</code></pre>
<p>python will need to first find the module in the global scope and then find findall in modules dict. May make a difference if you are calling it... | 10 | 2008-12-06T20:45:37Z | [
"python",
"import"
] |
Is it more efficient to use "import <module>" or "from <module> import <func>"? | 346,723 | <p>Say I only needed to use findall() from the re module, is it more efficient to do:</p>
<pre><code>from re import findall
</code></pre>
<p>or </p>
<pre><code>import re
</code></pre>
<p>Is there actually any difference in speed/memory usage etc?</p>
| 3 | 2008-12-06T20:25:05Z | 346,967 | <p>When in doubt, time it:</p>
<pre><code>from timeit import Timer
print Timer("""re.findall(r"\d+", "fg12f 1414 21af 144")""", "import re").timeit()
print Timer("""findall(r"\d+", "fg12f 1414 21af 144")""", "from re import findall").timeit()
</code></pre>
<p>I get the following results, using the minimum of 5 repet... | 8 | 2008-12-06T23:20:18Z | [
"python",
"import"
] |
Ticking function grapher | 346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed wid... | 2 | 2008-12-06T21:40:27Z | 346,873 | <p>Using deltaX</p>
<p>if deltax between 2 and 10 half increment
if deltax between 10 and 20 unit increment
if smaller than 2 we multiply by 10 and test again
if larger than 20 we divide
Then we get the position of the first unit or half increment on the width using xmin.</p>
<p>I still need to test this solution.</... | 0 | 2008-12-06T22:08:20Z | [
"python",
"algorithm",
"math"
] |
Ticking function grapher | 346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed wid... | 2 | 2008-12-06T21:40:27Z | 347,271 | <p>One way to do this would be to "normalise" the difference between the minimum and maximum and do a case distinction on that value. In python:</p>
<pre><code>delta = maximum - minimum
factor = 10**math.ceil(math.log(delta,10)) # smallest power of 10 greater than delta
normalised_delta = delta / factor # 0... | 4 | 2008-12-07T05:17:48Z | [
"python",
"algorithm",
"math"
] |
Ticking function grapher | 346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed wid... | 2 | 2008-12-06T21:40:27Z | 347,367 | <p>You might want to take a look at <a href="http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.html" rel="nofollow">Jgraph</a>, which solves a complementary problem: it is a data grapher rather than a function grapher. But there are a lot of things in common such as dealing with major and minor tick marks, axis labels,... | 0 | 2008-12-07T07:55:15Z | [
"python",
"algorithm",
"math"
] |
Ticking function grapher | 346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed wid... | 2 | 2008-12-06T21:40:27Z | 347,579 | <p>This seems to do what i was expecting.</p>
<p>import math</p>
<p>def main():
getTickGap(-1,1.5)</p>
<p>def next_multiple(x, y):
return math.ceil(x/y)*y</p>
<p>def getTickGap(xmin, xmax):
xdelta = xmax -xmin
width = 250
# smallest power of 10 greater than delta
factor = 10**math.ceil(math.... | 0 | 2008-12-07T13:33:36Z | [
"python",
"algorithm",
"math"
] |
Ticking function grapher | 346,823 | <p>I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.</p>
<p>Now I am working on the background and the ticking of X, Y axes (if any axes are shown).</p>
<p>I worked out the following.
I have a fixed wid... | 2 | 2008-12-06T21:40:27Z | 347,771 | <p>On range -1, 0</p>
<p>i get </p>
<pre><code>normalised_delta 1.0
step_size 0.1
Total steps 10.0
Range [ -1 , 0 ]
firstInc -1.0 tick at 0.0
start at 0.0 0.0
inc -0.9 tick at 25.0
inc -0.8 tick at 50.0
inc -0.7 tick at 75.0
inc -0.6 tick at 100.0
inc -0.5 tick at 125.0
inc -0.4 tick at 150.0
inc -0.3... | 0 | 2008-12-07T16:48:50Z | [
"python",
"algorithm",
"math"
] |
Django.contrib.flatpages without models | 346,840 | <p>I have some flatpages with empty <code>content</code> field and their content inside the template (given with <code>template_name</code> field).</p>
<h3>Why I am using <code>django.contrib.flatpages</code></h3>
<ul>
<li>It allows me to serve (mostly) static pages with minimal URL configuration.</li>
<li>I don't ha... | 6 | 2008-12-06T21:48:55Z | 346,877 | <p>Using the <a href="https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-simple-direct-to-template" rel="nofollow"><code>direct_to_template</code></a> generic view would be a lot simpler. You could use the passed in parameters on one view to specify the actual template in urls.py, if you don... | 9 | 2008-12-06T22:08:59Z | [
"python",
"django",
"templates",
"django-flatpages"
] |
Questions for python->scheme conversion | 347,010 | <p>I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.</p>
<p>I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algo... | 4 | 2008-12-06T23:58:08Z | 347,059 | <p>I wrote an 8-puzzle solver in Lisp about a year ago. I just used a list of 3 lists, each sublist with 3 elements being the numbers. It's not constant time, but it is portable.</p>
<p>Anyways, if you are really interested in doing this functionally (Scheme doesn't require you to) what is easiest to do is to create s... | 2 | 2008-12-07T00:56:32Z | [
"python",
"arrays",
"scheme"
] |
Questions for python->scheme conversion | 347,010 | <p>I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.</p>
<p>I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algo... | 4 | 2008-12-06T23:58:08Z | 347,181 | <p>You identified that your initial problem was trying to write C semantics in Lisp. Is it not repeating the mistake to try to write scheme semantics in python? I always try to learn language X as a paradigm as much as a language and write in the most x-ish way.</p>
<p>It might be justifiable if this was a business ap... | 4 | 2008-12-07T03:25:05Z | [
"python",
"arrays",
"scheme"
] |
Questions for python->scheme conversion | 347,010 | <p>I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.</p>
<p>I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algo... | 4 | 2008-12-06T23:58:08Z | 347,357 | <p>Cool, thanks for the lisp code. I'll need to study it to make sure I get it.</p>
<p>As for the first answer, the first time I was "writing c" in lisp because that's the only way I knew how to program and didn't have a clue why anyone would use lisp. This time around, I've been playing around with scheme, but want... | 0 | 2008-12-07T07:40:26Z | [
"python",
"arrays",
"scheme"
] |
Questions for python->scheme conversion | 347,010 | <p>I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.</p>
<p>I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algo... | 4 | 2008-12-06T23:58:08Z | 348,367 | <p>Here's one way to achieve it. Recreate the list using a function which will apply the appropriate mapping.</p>
<pre><code>def swap(p, (r1,c1), (r2,c2)):
def getitem(r,c):
if (r,c) == (r1,c1): return p[r2][c2]
elif (r,c) == (r2,c2): return p[r1][c1]
return p[r][c]
return [ [getitem(r... | 1 | 2008-12-07T23:59:49Z | [
"python",
"arrays",
"scheme"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,065 | <p>You will only have a first language for a little while. Pick any direction that interests you, and follow it. There is no way around the introduction "Drink from the Firehose" experience.</p>
<p>Keep early project simple, and tangible. Build useful things and the motivation will be there.</p>
<p>Web / desktop / mo... | 7 | 2008-12-07T00:58:04Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,066 | <blockquote>
<blockquote>
<p>The reason I settled in on Web Development as my course to learning programming is because I actually have a task to implement rather then aimlessly reading reference books etc.</p>
</blockquote>
</blockquote>
<p>This is exactly the course to follow. I think most of us get into pr... | 2 | 2008-12-07T00:58:23Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,074 | <p>One of pragmatic programmer's advice is to learn a new language per year. Possibly, a completely different one each time (see <a href="http://martinfowler.com/bliki/OneLanguage.html" rel="nofollow">Martin Fowler's opinion</a> on this matter).</p>
<p>Back to your specifics, you have chosen the way of programming bec... | 2 | 2008-12-07T01:03:37Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,076 | <p>Don't worry so much about the direction you're going, just make sure that:</p>
<p>a) You are enjoying it, and are understanding what you are doing. You don't have to initially understand concepts like polymorphism for example, but you should be understanding the basics of what you are doing. Just can't wrap your mi... | 0 | 2008-12-07T01:09:04Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,120 | <p>I find some of my junior colleagues (atleast the ones that are very passionate about CS) asking similar questions (sometimes I find myself asking this too, even though I am now 12+ yrs into the industry). One advice I give them (and to myself too), which helped me, is - </p>
<ul>
<li><p>Focus on the job that is alr... | 0 | 2008-12-07T02:13:31Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,121 | <p>Thanks for the thoughtful responses</p>
<p>That seemed to be another distraction from learning programming for me anyway. I spent more time chasing apparent fixes for upgraded packages and such. Mostly things that were already working and it just seemed to not make much sense to spend time recreating the wheel so t... | 0 | 2008-12-07T02:13:51Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,129 | <p>This is a ruff business. Technology churn keeps everyone busy and workers who want to excel at their craft can become constantly busy in a sea of new technology. But, in the end all of these technologies follow the same patterns and practices to one degree or another. Becoming an expert in the fundamentals will g... | 0 | 2008-12-07T02:22:41Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,348 | <p>Really all you need to do is make sure you take baby steps and are doing something you are enjoying.</p>
<p>I started off programming in visual basic on a little game. Not the best language, but it was a good starting point for me at the time. My point is, you don't need to pick the best language/operating system/a... | 0 | 2008-12-07T07:20:41Z | [
"php",
"asp.net",
"python",
"linux"
] |
Where do I go from here -- regarding programming? | 347,054 | <p>I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.</p>
<p>I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the who... | 3 | 2008-12-07T00:49:52Z | 347,353 | <p>I had the same issue for a little while myself. I was getting bored of just being in PHP and wanted to be able to do more. I ended up settling on C# since it not only fulfilled the 'necessary evil' argument, but allows me to do anything I want in the MS realm, and is the closest syntax wise to another language (Java... | 0 | 2008-12-07T07:27:35Z | [
"php",
"asp.net",
"python",
"linux"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 347,175 | <p>You could use a metaclass to dynamically insert the tests. This works fine for me:</p>
<pre><code>import unittest
class UnderTest(object):
def f1(self, i):
return i + 1
def f2(self, i):
return i + 2
class TestMeta(type):
def __new__(cls, name, bases, attrs):
funcs = [t for ... | 4 | 2008-12-07T03:17:47Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 347,499 | <p>Metaclasses is one option. Another option is to use a <code>TestSuite</code>:</p>
<pre><code>import unittest
import numpy
import funcs
# get references to functions
# only the functions and if their names start with "matrixOp"
functions_to_test = [v for k,v in funcs.__dict__ if v.func_name.startswith('matrixOp')]
... | 1 | 2008-12-07T11:43:39Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 347,607 | <p>Here's my favorite approach to the "family of related tests". I like explicit subclasses of a TestCase that expresses the common features.</p>
<pre><code>class MyTestF1( unittest.TestCase ):
theFunction= staticmethod( f1 )
def setUp(self):
self.matrix1 = numpy.ones((5,10))
self.matrix2 = nu... | 11 | 2008-12-07T14:07:12Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 373,107 | <blockquote>
<p>The problem with this approach is that
if any element of the list fails the
test, the later elements don't get
tested.</p>
</blockquote>
<p>If you look at it from the point of view that, if a test fails, that is critical and your entire package is invalid, then it doesn't matter that other elem... | -1 | 2008-12-16T23:13:24Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 373,625 | <p>If you're already using nose (and some of your comments suggest you are), why don't you just use <a href="http://somethingaboutorange.com/mrl/projects/nose/#test-generators">Test Generators</a>, which are the most straightforward way to implement parametric tests I've come across:</p>
<p>For example:</p>
<pre><cod... | 5 | 2008-12-17T04:05:43Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 1,320,299 | <p>The above metaclass code has trouble with nose because nose's wantMethod in its selector.py is looking at a given test method's <code>__name__</code>, not the attribute dict key.</p>
<p>To use a metaclass defined test method with nose, the method name and dictionary key must be the same, and prefixed to be detected... | 1 | 2009-08-24T02:59:01Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 1,974,927 | <p>You don't have to use Meta Classes here. A simple loop fits just fine. Take a look at the example below:</p>
<pre><code>import unittest
class TestCase1(unittest.TestCase):
def check_something(self, param1):
self.assertTrue(param1)
def _add_test(name, param1):
def test_method(self):
self.che... | 5 | 2009-12-29T14:37:07Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 5,026,270 | <p>I've read the above metaclass example, and I liked it, but it was missing two things:</p>
<ol>
<li>How to drive it with a data structure?</li>
<li>How to make sure that the test function is written correctly?</li>
</ol>
<p>I wrote this more complete example, which is data-driven, and in which the test function is ... | 0 | 2011-02-17T07:42:46Z | [
"python",
"unit-testing"
] |
How do I concisely implement multiple similar unit tests in the Python unittest framework? | 347,109 | <p>I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape.</p>
<p>I would like to write unit tests to test the entire family of functions for this property, without having to write an individual te... | 14 | 2008-12-07T01:59:49Z | 30,290,106 | <p>I see that this question is old. I'm not sure about back then, but today maybe you could use some "data-driven testing" packages:</p>
<ul>
<li><a href="https://github.com/wolever/nose-parameterized" rel="nofollow">https://github.com/wolever/nose-parameterized</a></li>
<li><a href="http://ddt.readthedocs.org/en/late... | 2 | 2015-05-17T17:51:22Z | [
"python",
"unit-testing"
] |
Can I use Python to intercept global keystrokes in KDE? | 347,475 | <p>I want to make a simple app, ideally in Python, that would run in the background on KDE, listening to all keystrokes being done by the user, so that the app goes to the foreground if a specific combination of keys is pressed. Is that doable? Can anyone point me to such resource?</p>
| 0 | 2008-12-07T11:03:17Z | 348,676 | <p>A quick google found this:</p>
<p><a href="http://sourceforge.net/projects/pykeylogger/" rel="nofollow">http://sourceforge.net/projects/pykeylogger/</a></p>
<p>You might be able to use some of the source code.</p>
| 1 | 2008-12-08T04:50:24Z | [
"python",
"kde"
] |
Emitting headers from a tiny Python web-framework | 347,497 | <p>I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code <a href="http://github.com/dbr/pyerweb/tree/master" rel="nofollow">on github</a></p>
<p>Basically it's written to be as simple to use as possible. An example ... | 3 | 2008-12-07T11:41:34Z | 347,509 | <p>You should reconsider the notion of returning <a href="http://en.wikipedia.org/wiki/Html" rel="nofollow">HTML</a> - headers are part of <a href="http://en.wikipedia.org/wiki/Http" rel="nofollow">HTTP</a>.
If you build your framework around an HTTP stream, the headers are simply lines that precede the HTML payload.</... | 1 | 2008-12-07T12:04:44Z | [
"python",
"frameworks"
] |
Emitting headers from a tiny Python web-framework | 347,497 | <p>I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code <a href="http://github.com/dbr/pyerweb/tree/master" rel="nofollow">on github</a></p>
<p>Basically it's written to be as simple to use as possible. An example ... | 3 | 2008-12-07T11:41:34Z | 347,545 | <p>you could use that idea of returning a dict or a string, but add a new decorator, so the 'evolution' for a user would be:</p>
<p>simple html:</p>
<pre><code>@GET("/")
def index():
return "<html><body>...</body></html>"
</code></pre>
<p>with constant headers (one @HEADER for each one, or a ... | 3 | 2008-12-07T12:53:39Z | [
"python",
"frameworks"
] |
Emitting headers from a tiny Python web-framework | 347,497 | <p>I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code <a href="http://github.com/dbr/pyerweb/tree/master" rel="nofollow">on github</a></p>
<p>Basically it's written to be as simple to use as possible. An example ... | 3 | 2008-12-07T11:41:34Z | 347,588 | <p>Look at <a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">PEP 333</a> for an excellent design pattern for a very lightweight web server. If your server has this exact API, you can reuse it in a lot of context with a lot of other products.</p>
<p>PEP 333 (WSGI) suggests that you don't directly retur... | 5 | 2008-12-07T13:43:28Z | [
"python",
"frameworks"
] |
Rounding float to the nearest factor? | 347,538 | <p>I have a small math problem I am trying to solve</p>
<p>Given a number x and resolution y, I need to find the next x' with the required resolution.</p>
<p>e.g.</p>
<pre><code>x = 1.002 y = 0.1 x'= 1.1
x = 0.348 y = 0.1 x'= 0.4
x = 0.50 y = 1 x'= 1
x = 0.32 y = 0.05 x'= 0.35
</code... | 6 | 2008-12-07T12:45:15Z | 347,549 | <pre><code>import math
def next_multiple(x, y):
return math.ceil(x/y)*y
def try_it(x, y):
print x, y, next_multiple(x, y)
for x, y in [
(1.002, 0.1),
(0.348, 0.1),
(0.50, 1),
(0.32, 0.05)
]:
try_it(x, y)
</code></pre>
<p>produces:</p>
<pre><code>1.002 0.1 1.1
0.348 0.1 0.4
0.5 1 1.0... | 11 | 2008-12-07T13:00:28Z | [
"python",
"algorithm",
"math"
] |
How do I get nose to discover dynamically-generated testcases? | 347,574 | <p>This is a follow-up to a <a href="http://stackoverflow.com/questions/347109/how-do-i-concisely-implement-multiple-similar-unit-tests-in-the-python-unittest">previous question</a> of mine.</p>
<p>In the previous question, methods were explored to implement what was essentially the same test over an entire family of ... | 6 | 2008-12-07T13:30:45Z | 366,620 | <p>You could try to generate the testcase classes with type()</p>
<pre><code>class UnderTest_MixIn(object):
def f1(self, i):
return i + 1
def f2(self, i):
return i + 2
SomeDynamicTestcase = type(
"SomeDynamicTestcase",
(UnderTest_MixIn, unittest.TestCase),
{"even_more_dynamic":... | 0 | 2008-12-14T14:54:30Z | [
"python",
"unit-testing",
"nose"
] |
How do I get nose to discover dynamically-generated testcases? | 347,574 | <p>This is a follow-up to a <a href="http://stackoverflow.com/questions/347109/how-do-i-concisely-implement-multiple-similar-unit-tests-in-the-python-unittest">previous question</a> of mine.</p>
<p>In the previous question, methods were explored to implement what was essentially the same test over an entire family of ... | 6 | 2008-12-07T13:30:45Z | 676,420 | <p>Nose has a "test generator" feature for stuff like this. You write a generator function that yields each "test case" function you want it to run, along with its args. Following your previous example, this could check each of the functions in a separate test:</p>
<pre><code>import unittest
import numpy
from somew... | 7 | 2009-03-24T07:19:15Z | [
"python",
"unit-testing",
"nose"
] |
How do I get nose to discover dynamically-generated testcases? | 347,574 | <p>This is a follow-up to a <a href="http://stackoverflow.com/questions/347109/how-do-i-concisely-implement-multiple-similar-unit-tests-in-the-python-unittest">previous question</a> of mine.</p>
<p>In the previous question, methods were explored to implement what was essentially the same test over an entire family of ... | 6 | 2008-12-07T13:30:45Z | 13,579,703 | <p>Nose does not scan for tests statically, so you <em>can</em> use metaclass magic to make tests that Nose finds.</p>
<p>The hard part is that standard metaclass techniques don't set the func_name attribute correctly, which is what Nose looks for when checking whether methods on your class are tests.</p>
<p>Here's a... | 2 | 2012-11-27T08:00:07Z | [
"python",
"unit-testing",
"nose"
] |
mod_python.publisher always gives content type 'text/plain' | 347,632 | <p>I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I searched through the source of it and found the line where it dif... | 0 | 2008-12-07T14:27:09Z | 347,733 | <p>Your configuration looks okay: I've got a working mod_python.publisher script with essentially the same settings.</p>
<p>A few other thoughts:</p>
<ul>
<li><p>When you tried editing the publisher source code, did you restart your web server? It only loads Python libraries once, when the server is first started.</p... | 3 | 2008-12-07T16:15:26Z | [
"python",
"content-type",
"mod-python"
] |
Gauss-Legendre Algorithm in python | 347,734 | <p>I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use.
I have read about the <a href="http://en.wikipedia.org/wiki/Gauss-Legendre_algorithm">Gauss-Legendre Algorithm</a>, and I have t... | 12 | 2008-12-07T16:15:40Z | 347,749 | <ol>
<li><p>You forgot parentheses around <code>4*t</code>:</p>
<pre><code>pi = (a+b)**2 / (4*t)
</code></pre></li>
<li><p>You can use <code>decimal</code> to perform calculation with higher precision.</p>
<pre><code>#!/usr/bin/env python
from __future__ import with_statement
import decimal
def pi_gauss_legendre():... | 24 | 2008-12-07T16:29:55Z | [
"python",
"algorithm",
"pi"
] |
Gauss-Legendre Algorithm in python | 347,734 | <p>I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use.
I have read about the <a href="http://en.wikipedia.org/wiki/Gauss-Legendre_algorithm">Gauss-Legendre Algorithm</a>, and I have t... | 12 | 2008-12-07T16:15:40Z | 347,758 | <pre><code>pi = (square((a+b)))/4*t
</code></pre>
<p>should be</p>
<pre><code>pi = (square((a+b)))/(4*t)
</code></pre>
| 3 | 2008-12-07T16:37:09Z | [
"python",
"algorithm",
"pi"
] |
Gauss-Legendre Algorithm in python | 347,734 | <p>I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use.
I have read about the <a href="http://en.wikipedia.org/wiki/Gauss-Legendre_algorithm">Gauss-Legendre Algorithm</a>, and I have t... | 12 | 2008-12-07T16:15:40Z | 347,760 | <ol>
<li>If you want to calculate PI to 1000 digits you need to use a data type that supports 1000 digits of precision (e.g., <a href="http://www.egenix.com/products/python/mxExperimental/mxNumber/" rel="nofollow">mxNumber</a>)</li>
<li>You need to calculate a,b,t, and x until |a-b| < 10**-digits, not iterate digits... | 3 | 2008-12-07T16:38:24Z | [
"python",
"algorithm",
"pi"
] |
AKS Primes algorithm in Python | 347,811 | <p>A few years ago, it was proven that <a href="http://www.cse.iitk.ac.in/~manindra/algebra/primality_v6.pdf">PRIMES is in P</a>. Are there any algorithms implementing <a href="http://en.wikipedia.org/wiki/AKS_primality_test">their primality test</a> in Python? I wanted to run some benchmarks with a naive generator and... | 23 | 2008-12-07T17:41:10Z | 347,840 | <p>Quick answer: no, the AKS test is not the fastest way to test primality. There are much <em>much</em> faster primality tests that either assume the (generalized) Riemann hypothesis and/or are randomized. (E.g. <a href="http://en.wikipedia.org/wiki/Miller-Rabin_primality_test">Miller-Rabin</a> is fast and simple to i... | 42 | 2008-12-07T18:02:27Z | [
"python",
"algorithm",
"primes"
] |
AKS Primes algorithm in Python | 347,811 | <p>A few years ago, it was proven that <a href="http://www.cse.iitk.ac.in/~manindra/algebra/primality_v6.pdf">PRIMES is in P</a>. Are there any algorithms implementing <a href="http://en.wikipedia.org/wiki/AKS_primality_test">their primality test</a> in Python? I wanted to run some benchmarks with a naive generator and... | 23 | 2008-12-07T17:41:10Z | 29,834,291 | <p>Yes, go look at <a href="http://rosettacode.org/wiki/AKS_test_for_primes#Python" rel="nofollow">AKS test for primes</a> page on rosettacode.org</p>
<pre><code>def expand_x_1(p):
ex = [1]
for i in range(p):
ex.append(ex[-1] * -(p-i) / (i+1))
return ex[::-1]
def aks_test(p):
if p < 2: retu... | -3 | 2015-04-23T21:04:51Z | [
"python",
"algorithm",
"primes"
] |
How to test django caching? | 347,812 | <p>Is there a way to be <strong>sure</strong> that a page is coming from cache on a production server and on the development server as well?</p>
<p>The solution <strong>shouldn't</strong> involve caching middleware because not every project uses them. Though the solution itself might <strong>be</strong> a middleware.<... | 14 | 2008-12-07T17:41:34Z | 348,079 | <p>Mock the view, hit the page, and see if the mock was called. if it was not, the cache was used instead.</p>
| 7 | 2008-12-07T21:06:49Z | [
"python",
"django",
"caching",
"django-cache"
] |
How to test django caching? | 347,812 | <p>Is there a way to be <strong>sure</strong> that a page is coming from cache on a production server and on the development server as well?</p>
<p>The solution <strong>shouldn't</strong> involve caching middleware because not every project uses them. Though the solution itself might <strong>be</strong> a middleware.<... | 14 | 2008-12-07T17:41:34Z | 348,192 | <p>The reason you use caches is to improve performance. Test the performance by running a load test against your server. If the server's performance matches your needs, then you are all set!</p>
| 3 | 2008-12-07T22:12:02Z | [
"python",
"django",
"caching",
"django-cache"
] |
How to test django caching? | 347,812 | <p>Is there a way to be <strong>sure</strong> that a page is coming from cache on a production server and on the development server as well?</p>
<p>The solution <strong>shouldn't</strong> involve caching middleware because not every project uses them. Though the solution itself might <strong>be</strong> a middleware.<... | 14 | 2008-12-07T17:41:34Z | 348,546 | <p>We do a lot of component caching and not all of them are updated at the same time. So we set host and timestamp values in a universally included context processor. At the top of each template fragment we stick in:</p>
<pre><code><!-- component_name {{host}} {{timestamp}} -->
</code></pre>
<p>The component_na... | 18 | 2008-12-08T02:33:16Z | [
"python",
"django",
"caching",
"django-cache"
] |
How to test django caching? | 347,812 | <p>Is there a way to be <strong>sure</strong> that a page is coming from cache on a production server and on the development server as well?</p>
<p>The solution <strong>shouldn't</strong> involve caching middleware because not every project uses them. Though the solution itself might <strong>be</strong> a middleware.<... | 14 | 2008-12-07T17:41:34Z | 5,563,503 | <p>Peter Rowells suggestion works well, but you don't need a custom template context processor
for timestamps. You can simply use the template tag:</p>
<pre><code> <!-- {% now "jS F Y H:i" %} -->
</code></pre>
| 12 | 2011-04-06T08:32:14Z | [
"python",
"django",
"caching",
"django-cache"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 348,317 | <p>I see four things that can justify an investment of time in using Plone:</p>
<ul>
<li>Plone has a large and helpful community. Most of the things you need, somebody else<br />
already did at some time in the past. He probably asked some questions and got helpful
answers, or he wrote a tutorial. Usually that leaves... | 7 | 2008-12-07T23:30:53Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 348,508 | <p>It's hard to answer your question without any background information. Is the complexity justified if you just want a blog? No. Is the complexity justified if you're building a company intranet for 400+ people? Yes. Is it a good investment if you're looking to be a consultant? Absolutely! There's a lot of Plone work ... | 29 | 2008-12-08T01:59:39Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 351,692 | <p>If you want to see the complexity of Plone, you have to ask for it. For most people, it's just not there. It installs in a couple of minutes through a one-click installer. Then it's one click to log in, one click to create a page, use a WYSYWIG editor, and one click to save. Everything is through an intuitive web GU... | 23 | 2008-12-09T03:29:19Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 446,659 | <p>I found an anonymous comment <a href="http://bitubique.com/content/im-done-plone#comment-10">here</a> which is much better than that post itself, so I'm reposting it here in full, with a couple of typos corrected.</p>
<p><hr /></p>
<p>This summer my chess club asked me to make a new website, where the members of t... | 9 | 2009-01-15T13:08:53Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 476,336 | <p>From a system administrator standpoint, Plone is just shy of being the absolute devil. Upgrading, maintaining, and installing where you want to install things is all more painful than necessary on the Linux platform. That's just my two cents though, and why I typically prefer to avoid the Zope/Plone stack.</p>
<p>N... | 3 | 2009-01-24T17:04:56Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 855,005 | <p>Accretion.</p>
| 3 | 2009-05-12T21:40:37Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 5,332,436 | <p>About the comment <a href="http://stackoverflow.com/questions/348044/what-could-justify-the-complexity-of-plone/446659#446659">here</a> I think Plone doesn't work like that (at least not anymore). </p>
<p>1 - Plone is somehow slower than other CMS solutions indeed, but from the out-of-the-box setup to a Apache-Varn... | 2 | 2011-03-16T22:08:16Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
What could justify the complexity of Plone? | 348,044 | <p>Plone is very complex. <a href="http://en.wikipedia.org/wiki/Zope">Zope</a>2, <a href="http://en.wikipedia.org/wiki/Zope_3">Zope3</a>, <a href="http://codespeak.net/z3/five/">Five</a>, <a href="http://wiki.zope.org/zope3/ZCML">ZCML</a>, <a href="http://en.wikipedia.org/wiki/Zope_Object_Database">ZODB</a>, <a href="h... | 12 | 2008-12-07T20:41:40Z | 34,743,241 | <p>Don't use it, if you don't have to. The whole ZOPE universe is a dinosaur. Grown for ages, has collected lots of cruft and rust. Many things would be done completely different nowadays. Overly complex for most stuff, hard to handle for complex stuff. It's the opposite of slim and scalable design. And for seriously f... | 0 | 2016-01-12T12:05:10Z | [
"python",
"content-management-system",
"plone",
"zope"
] |
Creating a list of objects in Python | 348,196 | <p>I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created.</p>
<p>I've simplified the program to its bare bones for this posting. First I create a new... | 42 | 2008-12-07T22:15:46Z | 348,214 | <p>Create a new instance each time, where each new instance has the correct state, rather than continually modifying the state of the same instance.</p>
<p>Alternately, store an explicitly-made copy of the object (using the hint <a href="http://docs.python.org/library/copy.html">at this page</a>) at each step, rather ... | 5 | 2008-12-07T22:22:32Z | [
"python",
"list",
"object",
"loops"
] |
Creating a list of objects in Python | 348,196 | <p>I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created.</p>
<p>I've simplified the program to its bare bones for this posting. First I create a new... | 42 | 2008-12-07T22:15:46Z | 348,215 | <p>You demonstrate a fundamental misunderstanding.</p>
<p>You never created an instance of SimpleClass at all, because you didn't call it.</p>
<pre><code>for count in xrange(4):
x = SimpleClass()
x.attr = count
simplelist.append(x)
</code></pre>
<p>Or, if you let the class take parameters, instead, you c... | 39 | 2008-12-07T22:22:39Z | [
"python",
"list",
"object",
"loops"
] |
Creating a list of objects in Python | 348,196 | <p>I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created.</p>
<p>I've simplified the program to its bare bones for this posting. First I create a new... | 42 | 2008-12-07T22:15:46Z | 348,222 | <p>If I understand correctly your question, you ask a way to execute a deep copy of an object.
What about using copy.deepcopy?</p>
<pre><code>import copy
x = SimpleClass()
for count in range(0,4):
y = copy.deepcopy(x)
(...)
y.attr1= '*Bob* '* count
</code></pre>
<p>A deepcopy is a recursive copy of the entire... | 3 | 2008-12-07T22:25:21Z | [
"python",
"list",
"object",
"loops"
] |
Creating a list of objects in Python | 348,196 | <p>I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created.</p>
<p>I've simplified the program to its bare bones for this posting. First I create a new... | 42 | 2008-12-07T22:15:46Z | 348,284 | <p>It shouldn't be necessary to recreate the SimpleClass object each time, as some are suggesting, if you're simply using it to output data based on its attributes. However, you're not actually creating an instance of the class; you're simply creating a reference to the class object itself. Therefore, you're adding a... | 7 | 2008-12-07T23:06:58Z | [
"python",
"list",
"object",
"loops"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.