title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 25,797,695 | <p>When we do this:</p>
<pre><code>def foo(a=[]):
...
</code></pre>
<p>... we assign the argument <code>a</code> to an <em>unnamed</em> list, if the caller does not pass the value of a.</p>
<p>To make things simpler for this discussion, let's temporarily give the unnamed list a name. How about <code>pavlo</code>... | 10 | 2014-09-11T22:05:43Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 28,354,667 | <p>I sometimes exploit this behavior as an alternative to the following pattern:</p>
<pre><code>singleton = None
def use_singleton():
global singleton
if singleton is None:
singleton = _make_singleton()
return singleton.use_me()
</code></pre>
<p>If <code>singleton</code> is only used by <code>u... | 11 | 2015-02-05T21:44:51Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 29,290,566 | <p>Already busy topic, but from what I read here, the following helped me realizing how it's working internally:</p>
<pre><code>def bar(a=[]):
print id(a)
a = a + [1]
print id(a)
return a
>>> bar()
4484370232
4484524224
[1]
>>> bar()
4484370232
4484524152
[1]
>>> bar()
4... | 15 | 2015-03-26T23:14:01Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 29,344,819 | <h1>5 points in defense of Python</h1>
<ol>
<li><p><strong>Simplicity</strong>: The behavior is simple in the following sense:
Most people fall into this trap only once, not several times.</p></li>
<li><p><strong>Consistency</strong>: Python <em>always</em> passes objects, not names.
The default parameter is, obviousl... | 26 | 2015-03-30T11:18:25Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 30,177,062 | <p>A very subtle issue being pointed out here. Thanks for all the insights.</p>
<p>I ran into a similar problem and found a fix for this.</p>
<p><strong>It's always safe to clean the vessel before we start cooking</strong></p>
<p><em>safe version:</em> </p>
<pre><code>def foo(bird=[]):
del bird[:] # <---... | 2 | 2015-05-11T20:28:57Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 30,447,095 | <p>Just change the function to be:</p>
<pre><code>def notastonishinganymore(a = [])'''The name is just a joke :)''':
del a[:]
a.append(5)
return a
</code></pre>
| 2 | 2015-05-25T23:04:44Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 32,535,706 | <p>I am going to demonstrate an alternative structure to pass a default list value to a function (it works equally well with dictionaries). </p>
<p>As others have extensively commented, the list parameter is bound to the function when it is defined as opposed to when it is executed. Because lists and dictionaries ar... | 7 | 2015-09-12T06:00:51Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 34,172,768 | <h2>Why don't you introspect?</h2>
<p>I'm actually <em>really</em> surprised no one has performed the insightfull introspection offered by Python (<code>2</code> and <code>3</code> certainly apply) on callables. </p>
<p>Given a simple little function <code>func</code> defined as:</p>
<pre><code>>>> def func... | 14 | 2015-12-09T07:13:28Z | [
"python",
"language-design",
"least-astonishment"
] |
"Least Astonishment" and the Mutable Default Argument | 1,132,941 | <p>Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:</p>
<pre><code>def foo(a=[]):
a.append(5)
return a
</code></pre>
<p>Python novices would expect this function to always return a list with only one element: <code>[5]</code>. The result is instead very diff... | 1,504 | 2009-07-15T18:00:37Z | 36,968,932 | <h1>Python: The Mutable Default Argument</h1>
<p>Default arguments get evaluated at the time the function is compiled into a function object. When used by the function, multiple times by that function, they are and remain the same object. </p>
<p>When they are mutable, when mutated (for example, by adding an element ... | 4 | 2016-05-01T16:20:44Z | [
"python",
"language-design",
"least-astonishment"
] |
Django serialization of inherited model | 1,132,980 | <p>I have a problem with serialization of Django inherited models. For example</p>
<pre><code>class Animal(models.Model):
color = models.CharField(max_length=50)
class Dog(Animal):
name = models.CharField(max_length=50)
...
# now I want to serialize Dog model with Animal inherited fields obviously included
p... | 6 | 2009-07-15T18:06:50Z | 1,179,693 | <p>Did you look at select_related() ?
as in </p>
<pre><code>serializers.serialize('xml', Dog.objects.select_related().all())
</code></pre>
| 0 | 2009-07-24T19:30:05Z | [
"python",
"django",
"serialization"
] |
Django serialization of inherited model | 1,132,980 | <p>I have a problem with serialization of Django inherited models. For example</p>
<pre><code>class Animal(models.Model):
color = models.CharField(max_length=50)
class Dog(Animal):
name = models.CharField(max_length=50)
...
# now I want to serialize Dog model with Animal inherited fields obviously included
p... | 6 | 2009-07-15T18:06:50Z | 1,303,306 | <p>You found your answer in the documentation of the patch.</p>
<pre><code>all_objects = list(Animal.objects.all()) + list(Dog.objects.all())
print serializers.serialize('xml', all_objects)
</code></pre>
<p>However, if you change <code>Animal</code> to be an abstract base class it will work:</p>
<pre><code>class Ani... | 1 | 2009-08-20T00:14:01Z | [
"python",
"django",
"serialization"
] |
Django serialization of inherited model | 1,132,980 | <p>I have a problem with serialization of Django inherited models. For example</p>
<pre><code>class Animal(models.Model):
color = models.CharField(max_length=50)
class Dog(Animal):
name = models.CharField(max_length=50)
...
# now I want to serialize Dog model with Animal inherited fields obviously included
p... | 6 | 2009-07-15T18:06:50Z | 14,753,889 | <p>You'll need a custom serializer to support inherited fields, as Django's serializer will only serialize local fields.</p>
<p>I ended up writing my own when dealing with this issue, feel free to copy it: <a href="https://github.com/zmathew/django-backbone/blob/master/backbone/serializers.py" rel="nofollow">https://g... | 0 | 2013-02-07T14:47:42Z | [
"python",
"django",
"serialization"
] |
Django serialization of inherited model | 1,132,980 | <p>I have a problem with serialization of Django inherited models. For example</p>
<pre><code>class Animal(models.Model):
color = models.CharField(max_length=50)
class Dog(Animal):
name = models.CharField(max_length=50)
...
# now I want to serialize Dog model with Animal inherited fields obviously included
p... | 6 | 2009-07-15T18:06:50Z | 32,158,475 | <p>You can define a custom Serializer:</p>
<pre><code>class DogSerializer(serializers.ModelSerializer):
class Meta:
model = Dog
fields = ('color','name')
</code></pre>
<p>Use it like:<br>
serializer = DogSerializer(Dog.objects.all(), many=True)<br>
print serializer.data enter code here</p>
| 0 | 2015-08-22T16:44:10Z | [
"python",
"django",
"serialization"
] |
Alternatives to using pack_into() when manipulating a list of bytes? | 1,133,044 | <p>I'm reading in a binary file into a list and parsing the binary data. I'm using unpack() to extract certain parts of the data as primitive data types, and I want to edit that data and insert it back into the original list of bytes. Using <a href="http://docs.python.org/library/struct.html" rel="nofollow">pack_into()... | 2 | 2009-07-15T18:18:20Z | 1,133,205 | <p>Do you mean editing data in a buffer object? Documentation on manipulating those at all from Python directly is fairly scarce.</p>
<p>If you just want to edit bytes in a string, it's simple enough, though; struct.pack_into is new to 2.5, but struct.pack isn't:</p>
<pre><code>import struct
s = open("file").read()
... | 1 | 2009-07-15T18:46:28Z | [
"python",
"binary",
"struct"
] |
Alternatives to using pack_into() when manipulating a list of bytes? | 1,133,044 | <p>I'm reading in a binary file into a list and parsing the binary data. I'm using unpack() to extract certain parts of the data as primitive data types, and I want to edit that data and insert it back into the original list of bytes. Using <a href="http://docs.python.org/library/struct.html" rel="nofollow">pack_into()... | 2 | 2009-07-15T18:18:20Z | 1,143,568 | <p>Have you looked at the <a href="http://python-bitstring.googlecode.com" rel="nofollow"><code>bitstring</code></a> module? It's designed to make the construction, parsing and modification of binary data easier than using the <code>struct</code> and <code>array</code> modules directly.</p>
<p>It's especially made for... | 3 | 2009-07-17T14:15:10Z | [
"python",
"binary",
"struct"
] |
DateTime in python extracting different bits and pieces | 1,133,147 | <p>I want to extract year from current date using python.</p>
<p>Do something like: </p>
<pre><code> DateTime a = DateTime.Now()
a.Year # (this is in C#)
</code></pre>
| 34 | 2009-07-15T18:37:27Z | 1,133,171 | <pre><code>import datetime
a = datetime.datetime.today().year
</code></pre>
<p>or even (as Lennart suggested)</p>
<pre><code>a = datetime.datetime.now().year
</code></pre>
<p>or even</p>
<pre><code>a = datetime.date.today().year
</code></pre>
| 10 | 2009-07-15T18:41:17Z | [
"python",
"datetime"
] |
DateTime in python extracting different bits and pieces | 1,133,147 | <p>I want to extract year from current date using python.</p>
<p>Do something like: </p>
<pre><code> DateTime a = DateTime.Now()
a.Year # (this is in C#)
</code></pre>
| 34 | 2009-07-15T18:37:27Z | 1,133,190 | <p>It's in fact almost the same in Python.. :-)</p>
<pre><code>import datetime
year = datetime.date.today().year
</code></pre>
<p>Of course, date doesn't have a time associated, so if you care about that too, you can do the same with a complete datetime object:</p>
<pre><code>import datetime
year = datetime.datetime... | 43 | 2009-07-15T18:44:31Z | [
"python",
"datetime"
] |
DateTime in python extracting different bits and pieces | 1,133,147 | <p>I want to extract year from current date using python.</p>
<p>Do something like: </p>
<pre><code> DateTime a = DateTime.Now()
a.Year # (this is in C#)
</code></pre>
| 34 | 2009-07-15T18:37:27Z | 1,133,246 | <p>The other answers to this question seem to hit it spot on. Now how would you figure this out for yourself without stack overflow? Check out <a href="http://ipython.scipy.org/moin/">IPython</a>, an interactive Python shell that has tab auto-complete.</p>
<pre><code>> ipython
import Python 2.5 (r25:51908, Nov 6... | 9 | 2009-07-15T18:52:54Z | [
"python",
"datetime"
] |
DateTime in python extracting different bits and pieces | 1,133,147 | <p>I want to extract year from current date using python.</p>
<p>Do something like: </p>
<pre><code> DateTime a = DateTime.Now()
a.Year # (this is in C#)
</code></pre>
| 34 | 2009-07-15T18:37:27Z | 19,181,120 | <p>If you want the year from a (unknown) datetime-object:</p>
<pre><code>tijd = datetime.datetime(9999, 12, 31, 23, 59, 59)
>>> tijd.timetuple()
time.struct_time(tm_year=9999, tm_mon=12, tm_mday=31, tm_hour=23, tm_min=59, tm_sec=59, tm_wday=4, tm_yday=365, tm_isdst=-1)
>>> tijd.timetuple().tm_year
9... | 1 | 2013-10-04T12:26:14Z | [
"python",
"datetime"
] |
Adding tuples to produce a tuple with a subtotal per 'column' | 1,133,286 | <p>What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'?</p>
<p>Eg:</p>
<pre><code>>>> a = (10, 20)
>>> b = (40, 50)
>>> c = (1, 3)
>>> ???
(51, 73)
</code></pre>
<p>I've so far considered the following:</p>
<pre><code>def ... | 2 | 2009-07-15T19:00:35Z | 1,133,313 | <p>If your set of tuples is going to be relatively small, your solution is fine. However, if you're going to be working on very large data sets you should consider using reduce as it will only iterate over the list once compared to your original solution which iterates over the list of tuples twice.</p>
<pre><code>&g... | 0 | 2009-07-15T19:05:35Z | [
"python",
"tuples"
] |
Adding tuples to produce a tuple with a subtotal per 'column' | 1,133,286 | <p>What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'?</p>
<p>Eg:</p>
<pre><code>>>> a = (10, 20)
>>> b = (40, 50)
>>> c = (1, 3)
>>> ???
(51, 73)
</code></pre>
<p>I've so far considered the following:</p>
<pre><code>def ... | 2 | 2009-07-15T19:00:35Z | 1,133,316 | <p>I guess you could use <code>reduce</code>, though it's debatable whether that's pythonic ..</p>
<pre><code>In [13]: reduce(lambda s, t: (s[0]+t[0], s[1]+t[1]), [a, b, c], (0, 0))
Out[13]: (51, 73)
</code></pre>
<p>Here's another way using <code>map</code> and <code>zip</code>:</p>
<pre><code>In [14]: map(sum, zip... | 7 | 2009-07-15T19:06:07Z | [
"python",
"tuples"
] |
Adding tuples to produce a tuple with a subtotal per 'column' | 1,133,286 | <p>What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'?</p>
<p>Eg:</p>
<pre><code>>>> a = (10, 20)
>>> b = (40, 50)
>>> c = (1, 3)
>>> ???
(51, 73)
</code></pre>
<p>I've so far considered the following:</p>
<pre><code>def ... | 2 | 2009-07-15T19:00:35Z | 1,133,347 | <p>Not pure Python, but the preferred way if you have SciPy installed:</p>
<pre><code>from scipy import array
a = array((10, 20))
b = array((40, 50))
c = array((1, 3))
print tuple(a+b+c)
</code></pre>
| 1 | 2009-07-15T19:10:47Z | [
"python",
"tuples"
] |
Adding tuples to produce a tuple with a subtotal per 'column' | 1,133,286 | <p>What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'?</p>
<p>Eg:</p>
<pre><code>>>> a = (10, 20)
>>> b = (40, 50)
>>> c = (1, 3)
>>> ???
(51, 73)
</code></pre>
<p>I've so far considered the following:</p>
<pre><code>def ... | 2 | 2009-07-15T19:00:35Z | 1,133,349 | <p>Since we're going crazy,</p>
<pre><code>a = (10, 20)
b = (40, 50)
c = (1, 3)
def sumtuples(*tuples):
return map(sum, zip(*tuples))
sumtuples(a,b,c)
[51, 73]
</code></pre>
<p>Truth is, almost every time I post one of these crazy solutions, the 'naive' method seems to work out faster and more readable...</p>
| 2 | 2009-07-15T19:11:15Z | [
"python",
"tuples"
] |
Adding tuples to produce a tuple with a subtotal per 'column' | 1,133,286 | <p>What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'?</p>
<p>Eg:</p>
<pre><code>>>> a = (10, 20)
>>> b = (40, 50)
>>> c = (1, 3)
>>> ???
(51, 73)
</code></pre>
<p>I've so far considered the following:</p>
<pre><code>def ... | 2 | 2009-07-15T19:00:35Z | 1,134,856 | <p>These solutions all suffer from one of two problems:</p>
<ul>
<li>they only work on exactly two columns; ((1,2,3),(2,3,4),(3,4,5)) doesn't work; or</li>
<li>they don't work on an iterator, so generating a billion rows doesn't work (or wastes tons of memory).</li>
</ul>
<p>Don't get caught up in the "pythonic" buzz... | 0 | 2009-07-16T00:31:47Z | [
"python",
"tuples"
] |
Weird Problem with Classes and Optional Arguments | 1,133,309 | <p>Okay so this was driving me nuts all day. </p>
<p>Why does this happen:</p>
<pre><code>class Foo:
def __init__(self, bla = {}):
self.task_defs = bla
def __str__(self):
return ''.join(str(self.task_defs))
a = Foo()
b = Foo()
a.task_defs['BAR'] = 1
print 'B is ==> %s' % str(b)
print 'A is... | 0 | 2009-07-15T19:05:05Z | 1,133,329 | <p>Since you have <code>bla</code> initially set to a mutable type (in this case a dict) in the arguments, it gets shared since <code>bla</code> doesn't get reinitialized to a new dict instance for each instance created for <code>Foo</code>. Here, try this instead:</p>
<pre><code>class Foo:
def __init__(self, bla=... | 6 | 2009-07-15T19:08:24Z | [
"python"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 1,133,448 | <p>PHP has a direct equivalent called <a href="http://se2.php.net/manual/en/language.generators.overview.php" rel="nofollow">generators</a>.</p>
<p><strong>Old (pre php 5.5 answer):</strong></p>
<p>Unfortunately, there isn't a language equivalent. The easiest way is to either to what you're already doing, or to creat... | 12 | 2009-07-15T19:25:29Z | [
"php",
"python",
"lazy-evaluation"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 1,133,650 | <p>There may not be an equivalent operator, but the following code is equivalent in function and overhead:</p>
<pre><code>function file_lines($file) {
static $fhandle;
if ( is_null($fhandle) ) {
$fhandle = fopen($file, 'r');
if ( $fhandle === false ) {
return false;
}
}
if ( ($line = fgets... | 1 | 2009-07-15T20:03:59Z | [
"php",
"python",
"lazy-evaluation"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 1,133,863 | <p>I prototype everything in Python before implementing in any other languages, including PHP. I ended up using callbacks to achieve what I would with the <code>yield</code>.</p>
<pre><code>function doSomething($callback)
{
foreach ($something as $someOtherThing) {
// do some computations that generates $... | 11 | 2009-07-15T20:34:15Z | [
"php",
"python",
"lazy-evaluation"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 8,546,875 | <p>Extending @Luiz's answer - another cool way is to use anonymous functions:</p>
<pre><code>function iterator($n, $cb)
{
for($i=0; $i<$n; $i++) {
call_user_func($cb, $i);
}
}
$sum = 0;
iterator(10,
function($i) use (&$sum)
{
$sum += $i;
}
);
print $sum;
</code></pre>
| 3 | 2011-12-17T18:16:41Z | [
"php",
"python",
"lazy-evaluation"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 11,495,404 | <p>There is a rfc at <a href="https://wiki.php.net/rfc/generators">https://wiki.php.net/rfc/generators</a> adressing just that, which might be included in PHP 5.5.</p>
<p>In the mean time, check out this proof-of-concept of a poor mans "generator function" implemented in userland.</p>
<p>
<pre><code>namespace Functi... | 18 | 2012-07-15T20:34:16Z | [
"php",
"python",
"lazy-evaluation"
] |
PHP equivalent to Python's yield operator | 1,133,371 | <p>In Python (and others), you can incrementally process large volumes of data by using the 'yield' operator in a function. What would be the similar way to do so in PHP?</p>
<p>For example, lets say in Python, if I wanted to read a potentially very large file, I could work on each line one at a time like so (this ex... | 19 | 2009-07-15T19:15:19Z | 18,170,824 | <p>The same sentence 'yield' exists now on PHP 5.5: </p>
<p><a href="http://php.net/manual/en/language.generators.syntax.php" rel="nofollow">http://php.net/manual/en/language.generators.syntax.php</a></p>
| 1 | 2013-08-11T10:07:48Z | [
"php",
"python",
"lazy-evaluation"
] |
Code lines of code in a Django Project | 1,133,391 | <p>Is there an easy way to count the lines of code you have written for your django project? </p>
<p>Edit: The shell stuff is cool, but how about on Windows?</p>
| 9 | 2009-07-15T19:17:15Z | 1,133,411 | <p>Yep:</p>
<pre><code>shell]$ find /my/source -name "*.py" -type f -exec cat {} + | wc -l
</code></pre>
<p>Job's a good 'un.</p>
| 14 | 2009-07-15T19:20:47Z | [
"python",
"django"
] |
Code lines of code in a Django Project | 1,133,391 | <p>Is there an easy way to count the lines of code you have written for your django project? </p>
<p>Edit: The shell stuff is cool, but how about on Windows?</p>
| 9 | 2009-07-15T19:17:15Z | 1,133,417 | <p>Check out the wc command on unix.</p>
| 1 | 2009-07-15T19:21:36Z | [
"python",
"django"
] |
Code lines of code in a Django Project | 1,133,391 | <p>Is there an easy way to count the lines of code you have written for your django project? </p>
<p>Edit: The shell stuff is cool, but how about on Windows?</p>
| 9 | 2009-07-15T19:17:15Z | 1,134,186 | <p>Starting with Aiden's answer, and with a bit of help in <a href="http://stackoverflow.com/questions/1133698/find-name-pattern-that-matches-multiple-patterns">a question of my own</a>, I ended up with this god-awful mess:</p>
<pre><code># find the combined LOC of files
# usage: loc Documents/fourU py html
function l... | 2 | 2009-07-15T21:25:14Z | [
"python",
"django"
] |
Code lines of code in a Django Project | 1,133,391 | <p>Is there an easy way to count the lines of code you have written for your django project? </p>
<p>Edit: The shell stuff is cool, but how about on Windows?</p>
| 9 | 2009-07-15T19:17:15Z | 1,139,296 | <p>Get wc command on Windows using GnuWin32 (<a href="http://gnuwin32.sourceforge.net/packages/coreutils.htm" rel="nofollow">http://gnuwin32.sourceforge.net/packages/coreutils.htm</a>)</p>
<blockquote>
<p>wc *.py</p>
</blockquote>
| 0 | 2009-07-16T18:07:43Z | [
"python",
"django"
] |
Code lines of code in a Django Project | 1,133,391 | <p>Is there an easy way to count the lines of code you have written for your django project? </p>
<p>Edit: The shell stuff is cool, but how about on Windows?</p>
| 9 | 2009-07-15T19:17:15Z | 1,141,171 | <p>You might want to look at <a href="http://cloc.sourceforge.net/" rel="nofollow">CLOC</a> -- it's not Django specific but it supports Python. It can show you lines counts for actual code, comments, blank lines, etc.</p>
| 4 | 2009-07-17T02:04:21Z | [
"python",
"django"
] |
Why can't IPython return records with multiple fields when submitting a query to sqlite? | 1,133,604 | <p>I am trying to write a simple query to an sqlite database in a python script. To test if my parameters were correct, I tried running the query from the ipython command line. It looked something like this:</p>
<pre><code>import sqlite3
db = 'G:\path\to\db\file.sqlite'
conn = sqlite3.connect(db)
results = conn.execut... | 1 | 2009-07-15T19:55:08Z | 1,133,661 | <p>This is SQL. IronPython has little or nothing to do with the processing of the query. Are you using an unusual character encoding? (IE not UTF-8 or ASCII)?</p>
<p>What happens if you <code>SELECT id,fieldname,fieldname FROM studies</code> (In other words, simulating what '*' does.)</p>
| 1 | 2009-07-15T20:06:32Z | [
"python",
"sqlite3",
"field",
"ipython"
] |
Why can't IPython return records with multiple fields when submitting a query to sqlite? | 1,133,604 | <p>I am trying to write a simple query to an sqlite database in a python script. To test if my parameters were correct, I tried running the query from the ipython command line. It looked something like this:</p>
<pre><code>import sqlite3
db = 'G:\path\to\db\file.sqlite'
conn = sqlite3.connect(db)
results = conn.execut... | 1 | 2009-07-15T19:55:08Z | 1,134,475 | <p>Just a wild guess, but please try to escape backslashes in the path to the database file. In other words instead of</p>
<pre><code>db = 'G:\path\to\db\file.sqlite'
</code></pre>
<p>try</p>
<pre><code>db = 'G:\\path\\to\\db\\file.sqlite'
</code></pre>
| 0 | 2009-07-15T22:28:29Z | [
"python",
"sqlite3",
"field",
"ipython"
] |
Why can't IPython return records with multiple fields when submitting a query to sqlite? | 1,133,604 | <p>I am trying to write a simple query to an sqlite database in a python script. To test if my parameters were correct, I tried running the query from the ipython command line. It looked something like this:</p>
<pre><code>import sqlite3
db = 'G:\path\to\db\file.sqlite'
conn = sqlite3.connect(db)
results = conn.execut... | 1 | 2009-07-15T19:55:08Z | 1,134,584 | <p>Some more debugging you could try:</p>
<pre><code>s = 'SELEECT * from studies'
print s
conn.execute(s).fetchall()
</code></pre>
<p>or:</p>
<pre><code>s = 'SELECT ' + chr(42) + ' from studies'
conn.execute(s).fetchall()
</code></pre>
<p>You might also try:</p>
<pre><code>conn.execute('select count(*) from studie... | 1 | 2009-07-15T23:05:46Z | [
"python",
"sqlite3",
"field",
"ipython"
] |
Why can't IPython return records with multiple fields when submitting a query to sqlite? | 1,133,604 | <p>I am trying to write a simple query to an sqlite database in a python script. To test if my parameters were correct, I tried running the query from the ipython command line. It looked something like this:</p>
<pre><code>import sqlite3
db = 'G:\path\to\db\file.sqlite'
conn = sqlite3.connect(db)
results = conn.execut... | 1 | 2009-07-15T19:55:08Z | 1,135,685 | <p>I've tried all the things you've mentioned in IPython and sqlite without any problems (ipython 0.9.1, python 2.5.2).</p>
<p>Is there a chance this is some kind of version mismatch issue? Maybe your shells are referencing different libraries?</p>
<p>For example, does</p>
<pre><code>import sqlite3; print sqlite3.v... | 1 | 2009-07-16T06:08:35Z | [
"python",
"sqlite3",
"field",
"ipython"
] |
Python processes stops responding to SIGTERM / SIGINT after being restarted | 1,133,693 | <p>I'm having a weird problem with some python processes running using a watchdog process.</p>
<p>The watchdog process is written in python and is the parent, and has a function called *start_child(name)* which uses <em>subprocess.Popen</em> to open the child process. The Popen object is recorded so that the watchdog ... | 3 | 2009-07-15T20:11:48Z | 1,134,566 | <p>As explained here: <a href="http://blogs.gentoo.org/agaffney/2005/03/18/python_sucks">http://blogs.gentoo.org/agaffney/2005/03/18/python_sucks</a> , when Python creates a new thread, it blocks all signals for that thread (and for any processes that thread spawns).</p>
<p>I fixed this using sigprocmask, called throu... | 5 | 2009-07-15T23:00:10Z | [
"python",
"ipc",
"freebsd"
] |
Python processes stops responding to SIGTERM / SIGINT after being restarted | 1,133,693 | <p>I'm having a weird problem with some python processes running using a watchdog process.</p>
<p>The watchdog process is written in python and is the parent, and has a function called *start_child(name)* which uses <em>subprocess.Popen</em> to open the child process. The Popen object is recorded so that the watchdog ... | 3 | 2009-07-15T20:11:48Z | 1,135,368 | <p>Wouldn't it be better to restore the default signal handlers within Python rather than via ctypes? In your child process, use the signal module:</p>
<pre><code>import signal
for sig in range(1, signal.NSIG):
try:
signal.signal(sig, signal.SIG_DFL)
except RuntimeError:
pass
</code></pre>
<p>... | 0 | 2009-07-16T04:21:35Z | [
"python",
"ipc",
"freebsd"
] |
How can I retrieve last x elements in Django | 1,133,715 | <p>I am trying to retrieve the latest 5 posts (by post time)
In the views.py, if I try <code>blog_post_list = blogPosts.objects.all()[:5]</code> It retreives the first 5 elements of the blogPosts objects, how can I reverse this to retreive the latest ones?</p>
<p>Cheers</p>
| 2 | 2009-07-15T20:15:07Z | 1,133,736 | <pre><code>blog_post_list = blogPosts.objects.all().reverse()[:5]
# OR
blog_post_list = blogPosts.objects.all().order_by('-DEFAULT_ORDER_KEY')[:5]
</code></pre>
<p>I prefer the first.</p>
| 8 | 2009-07-15T20:18:06Z | [
"python",
"django",
"list"
] |
How can I retrieve last x elements in Django | 1,133,715 | <p>I am trying to retrieve the latest 5 posts (by post time)
In the views.py, if I try <code>blog_post_list = blogPosts.objects.all()[:5]</code> It retreives the first 5 elements of the blogPosts objects, how can I reverse this to retreive the latest ones?</p>
<p>Cheers</p>
| 2 | 2009-07-15T20:15:07Z | 1,133,895 | <p>Based on Nick Presta's answer and your comment, try:</p>
<pre><code>blog_post_list = blogPosts.objects.all().order_by('-pub_date')[:5]
</code></pre>
| 4 | 2009-07-15T20:39:39Z | [
"python",
"django",
"list"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 1,133,879 | <p>From the <a href="http://docs.python.org/3.0/library/time.html">documentation</a>:</p>
<blockquote>
<p>On the other hand, the precision of
<code>time()</code> and <code>sleep()</code> is better than
their Unix equivalents: times are
expressed as floating point numbers,
<code>time()</code> returns the most... | 17 | 2009-07-15T20:37:01Z | [
"python",
"datetime",
"time",
"sleep"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 1,133,888 | <p>The accuracy of the time.sleep function depends on the accuracy of your underlying OS's sleep accuracy. For non-realtime OS's like a stock Windows the smallest interval you can sleep for is about 10-13ms. I have seen accurate sleeps within several milliseconds of that time when above the minimum 10-13ms.</p>
<p>U... | 45 | 2009-07-15T20:38:44Z | [
"python",
"datetime",
"time",
"sleep"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 1,133,925 | <p>You can't really guarantee anything about sleep(), except that it will at least make a best effort to sleep as long as you told it (signals can kill your sleep before the time is up, and lots more things can make it run long). For sure the minimum you can get on a standard desktop operating system is going to be ar... | 2 | 2009-07-15T20:45:43Z | [
"python",
"datetime",
"time",
"sleep"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 1,133,984 | <p>Why don't you find out:</p>
<pre><code>from datetime import datetime
import time
def check_sleep(amount):
start = datetime.now()
time.sleep(amount)
end = datetime.now()
delta = end-start
return delta.seconds + delta.microseconds/1000000.
error = sum(abs(check_sleep(0.050)-0.050) for i in xrang... | 12 | 2009-07-15T20:52:09Z | [
"python",
"datetime",
"time",
"sleep"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 15,967,564 | <p>People are quite right about the differences between operating systems and kernels, but I do not see any granularity in Ubuntu and I see a 1 ms granularity in MS7. Suggesting a different implementation of time.sleep, not just a different tick rate. Closer inspection suggests a 1μs granularity in Ubuntu by the way, ... | 29 | 2013-04-12T09:23:01Z | [
"python",
"datetime",
"time",
"sleep"
] |
How accurate is python's time.sleep()? | 1,133,857 | <p>I can give it floating point numbers, such as</p>
<pre><code>time.sleep(0.5)
</code></pre>
<p>but how accurate is it? If i give it</p>
<pre><code>time.sleep(0.05)
</code></pre>
<p>will it really sleep about 50 ms?</p>
| 48 | 2009-07-15T20:33:42Z | 30,672,412 | <p>Here's my follow-up to Wilbert's answer: the same for Mac OS X Yosemite, since it's not been mentioned much yet.<img src="http://i.stack.imgur.com/4MYle.png" alt="Sleep behavior of Mac OS X Yosemite"></p>
<p>Looks like a lot of the time it sleeps about 1.25 times the time that you request and sometimes sleeps betwe... | 7 | 2015-06-05T17:25:35Z | [
"python",
"datetime",
"time",
"sleep"
] |
Keep ConfigParser output files sorted | 1,134,071 | <p>I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values.</p>
<p>Is there a way to keep things sorted in the configuration file so that... | 6 | 2009-07-15T21:03:18Z | 1,134,109 | <p>No. The ConfigParser library writes things out in dictionary hash order. (You can see this if you look at the source code.) There are replacements for this module that do a better job.</p>
<p>I will see if I can find one and add it here.</p>
<p><a href="http://www.voidspace.org.uk/python/configobj.html#introduct... | 3 | 2009-07-15T21:09:51Z | [
"python",
"configuration",
"configparser"
] |
Keep ConfigParser output files sorted | 1,134,071 | <p>I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values.</p>
<p>Is there a way to keep things sorted in the configuration file so that... | 6 | 2009-07-15T21:03:18Z | 1,134,323 | <p>ConfigParser is based on the ini file format, who in it's design is supposed to NOT be sensitive to order. If your config file format is sensitive to order, you can't use ConfigParser. It may also confuse people if you have an ini-type format that is sensitive to the order of the statements...</p>
| -1 | 2009-07-15T21:55:54Z | [
"python",
"configuration",
"configparser"
] |
Keep ConfigParser output files sorted | 1,134,071 | <p>I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values.</p>
<p>Is there a way to keep things sorted in the configuration file so that... | 6 | 2009-07-15T21:03:18Z | 1,134,533 | <p>Looks like this was fixed in <a href="http://docs.python.org/dev/py3k/whatsnew/3.1.html">Python 3.1</a> and 2.7 with the introduction of ordered dictionaries:</p>
<blockquote>
<p>The standard library now supports use
of ordered dictionaries in several
modules. The configparser module uses
them by default. T... | 8 | 2009-07-15T22:45:03Z | [
"python",
"configuration",
"configparser"
] |
Python accessing web service protected by PKI/SSL | 1,134,565 | <p>I need to use Python to access data from a RESTful web service that requires certificate-based client authentication (PKI) over SSL/HTTPS. What is the recommended way of doing this?</p>
| 1 | 2009-07-15T23:00:04Z | 1,134,612 | <p>I found this: <a href="http://code.activestate.com/recipes/117004/" rel="nofollow">http://code.activestate.com/recipes/117004/</a>
I did not try it so it may not work.</p>
| 1 | 2009-07-15T23:18:22Z | [
"python",
"web-services",
"ssl",
"certificate",
"pki"
] |
Python accessing web service protected by PKI/SSL | 1,134,565 | <p>I need to use Python to access data from a RESTful web service that requires certificate-based client authentication (PKI) over SSL/HTTPS. What is the recommended way of doing this?</p>
| 1 | 2009-07-15T23:00:04Z | 1,135,272 | <p>The suggestion by stribika using <code>httplib.HTTPSConnection</code> should work for you provided that you do not need to verify the server's certificate. If you do want/need to verify the server, you'll need to look at a 3rd party module such as <a href="http://pyopenssl.sourceforge.net/" rel="nofollow">pyOpenSSL<... | 2 | 2009-07-16T03:35:50Z | [
"python",
"web-services",
"ssl",
"certificate",
"pki"
] |
Python accessing web service protected by PKI/SSL | 1,134,565 | <p>I need to use Python to access data from a RESTful web service that requires certificate-based client authentication (PKI) over SSL/HTTPS. What is the recommended way of doing this?</p>
| 1 | 2009-07-15T23:00:04Z | 1,441,812 | <p>I would recommend using <a href="http://chandlerproject.org/Projects/MeTooCrypto" rel="nofollow">M2Crypto</a>. If you are a Twisted guy, <a href="http://svn.osafoundation.org/m2crypto/trunk/M2Crypto/SSL/TwistedProtocolWrapper.py" rel="nofollow">M2Crypto integrates with Twisted</a> so you can let Twisted handle the n... | 0 | 2009-09-17T23:16:52Z | [
"python",
"web-services",
"ssl",
"certificate",
"pki"
] |
Python Exception handling | 1,134,607 | <p>C has perror and errno, which print and store the last error encountered. This is convenient when doing file io as I do not have to fstat() every file that fails as an argument to fopen() to present the user with a reason why the call failed.</p>
<p>I was wondering what is the proper way to grab errno when graceful... | 15 | 2009-07-15T23:15:06Z | 1,134,614 | <p>The Exception has a errno attribute:</p>
<pre><code>try:
fp = open("nother")
except IOError, e:
print e.errno
print e
</code></pre>
| 18 | 2009-07-15T23:18:53Z | [
"python",
"exception",
"errno",
"ioerror"
] |
Python Exception handling | 1,134,607 | <p>C has perror and errno, which print and store the last error encountered. This is convenient when doing file io as I do not have to fstat() every file that fails as an argument to fopen() to present the user with a reason why the call failed.</p>
<p>I was wondering what is the proper way to grab errno when graceful... | 15 | 2009-07-15T23:15:06Z | 1,134,616 | <p>Here's how you can do it. Also see the <code>errno</code> module and <code>os.strerror</code> function for some utilities.</p>
<pre><code>import os, errno
try:
f = open('asdfasdf', 'r')
except IOError as ioex:
print 'errno:', ioex.errno
print 'err code:', errno.errorcode[ioex.errno]
print 'err mes... | 22 | 2009-07-15T23:19:32Z | [
"python",
"exception",
"errno",
"ioerror"
] |
Python Exception handling | 1,134,607 | <p>C has perror and errno, which print and store the last error encountered. This is convenient when doing file io as I do not have to fstat() every file that fails as an argument to fopen() to present the user with a reason why the call failed.</p>
<p>I was wondering what is the proper way to grab errno when graceful... | 15 | 2009-07-15T23:15:06Z | 1,134,622 | <pre><code>try:
fp = open("nothere")
except IOError as err:
print err.errno
print err.strerror
</code></pre>
| 18 | 2009-07-15T23:20:51Z | [
"python",
"exception",
"errno",
"ioerror"
] |
Django required field in model form | 1,134,667 | <p>I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py</p>
<pre><code>class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init_... | 51 | 2009-07-15T23:37:16Z | 1,134,693 | <blockquote>
<p>If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True</p>
</blockquote>
<p>Says so here: <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/">http://docs.djangoproject.com/en/dev/topics/forms/modelforms/</a></p>
<p>Looks like ... | 10 | 2009-07-15T23:45:10Z | [
"python",
"django",
"forms",
"model",
"widget"
] |
Django required field in model form | 1,134,667 | <p>I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py</p>
<pre><code>class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init_... | 51 | 2009-07-15T23:37:16Z | 1,429,646 | <p>If you don't want to modify blank setting for your fields inside models (doing so will break normal validation in admin site), you can do the following in your Form class:</p>
<pre><code>def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init__(*args, **kwargs)
for key in self.fields:
... | 84 | 2009-09-15T21:11:02Z | [
"python",
"django",
"forms",
"model",
"widget"
] |
Django required field in model form | 1,134,667 | <p>I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py</p>
<pre><code>class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init_... | 51 | 2009-07-15T23:37:16Z | 1,650,162 | <p>It's not an answer, but for anyone else who finds this via Google, one more bit of data: this is happening to me on a Model Form with a DateField. It has required set to False, the model has "null=True, blank=True" and the field in the form shows required=False if I look at it during the clean() method, but it's sti... | 3 | 2009-10-30T14:33:49Z | [
"python",
"django",
"forms",
"model",
"widget"
] |
Django required field in model form | 1,134,667 | <p>I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py</p>
<pre><code>class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init_... | 51 | 2009-07-15T23:37:16Z | 1,833,543 | <p>This is a bug when using the widgets:</p>
<p>workaround:
<a href="http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form/1833247#1833247">http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form/1833247#1833247</a></p>
<p>or ticket 12303</p>
| 0 | 2009-12-02T15:16:19Z | [
"python",
"django",
"forms",
"model",
"widget"
] |
Django required field in model form | 1,134,667 | <p>I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py</p>
<pre><code>class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init_... | 51 | 2009-07-15T23:37:16Z | 34,790,883 | <p>Expanding on DataGreed's answer, I created a Mixin that allows you to specify a <code>fields_required</code> variable on the <code>Meta</code> class like this:</p>
<pre><code>class MyForm(RequiredFieldsMixin, ModelForm):
class Meta:
model = MyModel
fields = ['field1', 'field2']
fields_r... | 1 | 2016-01-14T13:29:18Z | [
"python",
"django",
"forms",
"model",
"widget"
] |
Simple tray icon application using pygtk | 1,134,749 | <p>I'm writing a webmail checker in python and I want it to just sit on the tray icon and warn me when there is a new email. Could anyone point me in the right direction as far as the gtk code?</p>
<p>I already coded the bits necessary to check for new email but it's CLI right now.</p>
| 4 | 2009-07-16T00:02:35Z | 1,134,771 | <p>You'll want to use a gtk.StatusIcon to actually display the icon. <a href="http://www.pygtk.org/docs/pygtk/class-gtkstatusicon.html">Here are the docs</a>. If you're just getting started with gui programming you might want to work though a bit of the <a href="http://www.pygtk.org/pygtk2tutorial/index.html">pygtk tut... | 5 | 2009-07-16T00:11:40Z | [
"python",
"pygtk",
"trayicon",
"tray"
] |
Simple tray icon application using pygtk | 1,134,749 | <p>I'm writing a webmail checker in python and I want it to just sit on the tray icon and warn me when there is a new email. Could anyone point me in the right direction as far as the gtk code?</p>
<p>I already coded the bits necessary to check for new email but it's CLI right now.</p>
| 4 | 2009-07-16T00:02:35Z | 1,134,773 | <p>This <a href="http://www.pygtk.org/docs/pygtk/class-gtkstatusicon.html" rel="nofollow">http://www.pygtk.org/docs/pygtk/class-gtkstatusicon.html</a> should get you going.</p>
| 2 | 2009-07-16T00:12:50Z | [
"python",
"pygtk",
"trayicon",
"tray"
] |
How to install django-haystack using buildout | 1,134,946 | <p>I'm trying to convert a current Django project in development to use zc.buildout So far, I've got all the bits figured except for Haystack figured out.</p>
<p>The Haystack source is available on GitHub, but I don't want to force users to install git. A suitable alternative seems to be to fetch a tarball from <a h... | 3 | 2009-07-16T01:08:12Z | 1,136,131 | <p>Well, if you don't want to install GIT, you can't check it out. So then you have to download a release. But there aren't any. In theory, find-links directly to the distribution should work. In this case it wont, probably because you don't link to the file, but to a page that generates the file from the trunk. So tha... | 1 | 2009-07-16T08:15:48Z | [
"python",
"buildout"
] |
How to install django-haystack using buildout | 1,134,946 | <p>I'm trying to convert a current Django project in development to use zc.buildout So far, I've got all the bits figured except for Haystack figured out.</p>
<p>The Haystack source is available on GitHub, but I don't want to force users to install git. A suitable alternative seems to be to fetch a tarball from <a h... | 3 | 2009-07-16T01:08:12Z | 1,144,547 | <p>I figured this one out, without posting it to PyPI. (There is no actually tagged release version of django-haystack, so posting to to PyPI seems unclean. It's something the maintainer should and probably will handle better themselves.)</p>
<p>The relevant section is as follows:</p>
<pre><code>[haystack]
recipe =... | 4 | 2009-07-17T17:06:27Z | [
"python",
"buildout"
] |
How to install django-haystack using buildout | 1,134,946 | <p>I'm trying to convert a current Django project in development to use zc.buildout So far, I've got all the bits figured except for Haystack figured out.</p>
<p>The Haystack source is available on GitHub, but I don't want to force users to install git. A suitable alternative seems to be to fetch a tarball from <a h... | 3 | 2009-07-16T01:08:12Z | 1,202,483 | <p>This currently works for me without forking.</p>
<pre><code>[django-haystack]
recipe = zerokspot.recipe.git
repository = git://github.com/toastdriven/django-haystack.git
as_egg = true
[whoosh]
recipe = zerokspot.recipe.git
repository = git://github.com/toastdriven/whoosh.git
branch = haystacked
as_egg = true
</cod... | 2 | 2009-07-29T19:25:11Z | [
"python",
"buildout"
] |
How to install django-haystack using buildout | 1,134,946 | <p>I'm trying to convert a current Django project in development to use zc.buildout So far, I've got all the bits figured except for Haystack figured out.</p>
<p>The Haystack source is available on GitHub, but I don't want to force users to install git. A suitable alternative seems to be to fetch a tarball from <a h... | 3 | 2009-07-16T01:08:12Z | 1,701,213 | <p>It seems they've fixed the package to work from the tarball. James' fork is not working right now, but you can use the same recipe passing it the standard url:</p>
<pre><code>[haystack]
recipe = collective.recipe.distutils
url = http://github.com/toastdriven/django-haystack/tarball/master
</code></pre>
<p>This wor... | 0 | 2009-11-09T14:14:40Z | [
"python",
"buildout"
] |
Buildout recipe for a hierarchy of parts | 1,135,082 | <p>Is there a Python <a href="http://www.buildout.org/" rel="nofollow">buildout</a> recipe which would allow the following:</p>
<pre><code>[buildout]
parts = group-of-parts
[group-of-parts]
recipe = what.can.i.use.for.this
parts = part-1 part-2
[part-1]
...
[part-2]
...
</code></pre>
<p>In other words, I want a re... | 4 | 2009-07-16T02:05:58Z | 1,135,970 | <p>No, there is no hierarchy, although you could build a recipe for it, of course.</p>
<p>Why do you want it? It's not like you end up with hundreds of parts so it's hard to keep track of them...</p>
| 1 | 2009-07-16T07:33:57Z | [
"python",
"buildout"
] |
Buildout recipe for a hierarchy of parts | 1,135,082 | <p>Is there a Python <a href="http://www.buildout.org/" rel="nofollow">buildout</a> recipe which would allow the following:</p>
<pre><code>[buildout]
parts = group-of-parts
[group-of-parts]
recipe = what.can.i.use.for.this
parts = part-1 part-2
[part-1]
...
[part-2]
...
</code></pre>
<p>In other words, I want a re... | 4 | 2009-07-16T02:05:58Z | 7,325,985 | <p>Some time ago I wrote an <a href="http://bluedynamics.com/articles/jens/dependencies-and-zc.buildout" rel="nofollow">article on dependency resolution in buildout</a>. Its not an answer to your question, because what you want does not make much sense in my opinion. But you may get an insights to dependency hierachy t... | 0 | 2011-09-06T20:50:49Z | [
"python",
"buildout"
] |
Buildout recipe for a hierarchy of parts | 1,135,082 | <p>Is there a Python <a href="http://www.buildout.org/" rel="nofollow">buildout</a> recipe which would allow the following:</p>
<pre><code>[buildout]
parts = group-of-parts
[group-of-parts]
recipe = what.can.i.use.for.this
parts = part-1 part-2
[part-1]
...
[part-2]
...
</code></pre>
<p>In other words, I want a re... | 4 | 2009-07-16T02:05:58Z | 7,327,966 | <p>You can do this:</p>
<pre><code>[buildout]
development-tools-parts =
thing1
thing2
software-parts =
thing3
thing4
parts =
${buildout:development-tools-parts}
${buildout:software-parts}
</code></pre>
<p>Did I understand you correctly?</p>
<p>It works because most of those buildout configura... | 0 | 2011-09-07T01:31:58Z | [
"python",
"buildout"
] |
Preventing variable substitutions from occurring with buildout | 1,135,292 | <p>Is there a simple way of escaping the magic characters used for variable substitution in a <a href="http://www.buildout.org/">buildout</a> configuration, such that the string is left alone. In other words, where I say:</p>
<pre><code>[part]
attribute = ${variable}
</code></pre>
<p>I don't actually want it to expan... | 6 | 2009-07-16T03:45:55Z | 1,164,584 | <p>I am afraid your analysis of the buildout variable substitution code (which collective.recipe.template relies on) is correct. There is no syntax for escaping a <code>${section:variable}</code> variable substitution and your solution of providing a <code>${dollar}</code> substitution is the best workaround I can thin... | 5 | 2009-07-22T11:17:12Z | [
"python",
"buildout"
] |
Preventing variable substitutions from occurring with buildout | 1,135,292 | <p>Is there a simple way of escaping the magic characters used for variable substitution in a <a href="http://www.buildout.org/">buildout</a> configuration, such that the string is left alone. In other words, where I say:</p>
<pre><code>[part]
attribute = ${variable}
</code></pre>
<p>I don't actually want it to expan... | 6 | 2009-07-16T03:45:55Z | 5,939,291 | <p>since version 1.7 of collective.recipe.template you can use genshi text templates, but since version 1.8 its useful because of some fixes made.</p>
<pre><code>recipe = collective.recipe.template[genshi]:genshi
...
mymessage = Hello
</code></pre>
<p>so the input-file it looks like</p>
<pre><code>The message in $${... | 5 | 2011-05-09T15:46:45Z | [
"python",
"buildout"
] |
Preventing variable substitutions from occurring with buildout | 1,135,292 | <p>Is there a simple way of escaping the magic characters used for variable substitution in a <a href="http://www.buildout.org/">buildout</a> configuration, such that the string is left alone. In other words, where I say:</p>
<pre><code>[part]
attribute = ${variable}
</code></pre>
<p>I don't actually want it to expan... | 6 | 2009-07-16T03:45:55Z | 37,085,401 | <p>Inserting an empty substitution between the <code>$</code> and the <code>{</code> should prevent buildout from evaluating the resulting text as a buildout substitution.</p>
<p><strong>buildout.cfg:</strong></p>
<pre><code>[server-xml]
recipe = collective.recipe.template
input = server.xml.in
output = server.xml
_ ... | 0 | 2016-05-07T06:43:34Z | [
"python",
"buildout"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 1,135,344 | <p>It would probably be easier to create a class that implements the int methods and wraps an internal integer.</p>
| 3 | 2009-07-16T04:10:36Z | [
"python",
"int"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 1,135,347 | <p>ints are immutable, so you'll have to build your own class with all the int's methods if you want a "mutable int"</p>
| 11 | 2009-07-16T04:10:55Z | [
"python",
"int"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 1,135,348 | <p>Hah, seems I misread the op.</p>
<p>But yes, the short answer is that, ints are immutable.</p>
| 0 | 2009-07-16T04:11:45Z | [
"python",
"int"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 1,140,858 | <p>If you absolutely have to get that code to work, here's a dirty method, where an instance method moves up a frame and overwrites its own locals entry. Wouldn't recommend. (like, really not. I'm not even sure what that does. What happens to the old instance? I don't know enough about frames...). Really, I'm only post... | 3 | 2009-07-16T23:44:29Z | [
"python",
"int"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 18,700,492 | <p>You can always put an immutable object inside a mutable container; lists are easiest. That will allow multiple references to the container, which can mutate its items.</p>
<p>If you did the following, the int is not mutable:</p>
<pre><code>a = 0
b = a
b = 1
print(a) # prints 0
</code></pre>
<p>Here's the same cod... | 1 | 2013-09-09T14:24:02Z | [
"python",
"int"
] |
increment int object | 1,135,335 | <p>Is there a way in python to increment int object in place, int doesn't seem to implement <code>__iadd__</code> so += 1 actually returns a new object</p>
<pre><code>>>> n=1
>>> id(n)
9788024
>>> n+=1
>>> id(n)
9788012
</code></pre>
<p>What I want is n to remain pointing to same o... | 13 | 2009-07-16T04:06:12Z | 28,757,945 | <p>You can use ctypes as mutable integers. Choosing the right ctype will be important though, as they limit the size of integer they can carry.</p>
<pre><code>>>> from ctypes import c_int64
>>> num = c_int64(0)
>>> id(num)
4447709232
>>> def increment(number):
... number.value +... | 4 | 2015-02-27T05:09:32Z | [
"python",
"int"
] |
Using python scripts in subversion hooks on windows | 1,135,499 | <p>My main goal is to get <a href="http://stackoverflow.com/questions/84178/how-do-i-implement-the-post-commit-hook-with-trac-svn-in-a-windows-environment">this</a> up and running.</p>
<p>My hook gets called when I do the commit with Tortoise SVN, but it always exits when I get to this line: Python "%~dp0trac-post-com... | 1 | 2009-07-16T05:15:13Z | 1,137,861 | <p>Take the following things into account:</p>
<ul>
<li>network drive mappings and <code>subst</code>
mappings are user specific. Make sure
the drives exist for the user account
under which the svn server is
running.</li>
<li>subversion hook scripts are <a href="http://svnbook.red-bean.com/en/1.5/svn.reposadmin.create... | 3 | 2009-07-16T14:08:14Z | [
"python",
"windows",
"svn",
"hook",
"svn-hooks"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 1,135,722 | <p>The module is not likely in your python search path..</p>
<p>Check to see if that module is in your <em>Python Path</em>... In windows...you may find it in the registry</p>
<p>HKLM\Software\Python\PythonCore\2.6\PythonPath</p>
<p>Be careful editing it...</p>
<p>You may also alter the Python Path programmaticly b... | 4 | 2009-07-16T06:19:09Z | [
"python",
"mysql"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 1,135,877 | <p>generally, (good) python modules provide a 'setup.py' script that takes care of things like proper installation (google for 'distutils python'). MySQLdb is a "good" module in this sense.</p>
<p>since you're using windows, things might be a bit more complex. I assume you already installed MySQLdb following the ins... | 0 | 2009-07-16T07:06:19Z | [
"python",
"mysql"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 1,137,144 | <p>See this post on the mysql-python blog: <a href="http://mysql-python.blogspot.com/2009/03/mysql-python-123-beta-2-released.html" rel="nofollow">MySQL-python-1.2.3 beta 2 released</a> - dated March 2009. Looks like MySQLdb for Python 2.6 is still a work in progress...</p>
| 0 | 2009-07-16T12:15:20Z | [
"python",
"mysql"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 1,473,805 | <p>The best setup for Windows that I've found:</p>
<p><a href="http://www.codegood.com/downloads?dl_cat=2" rel="nofollow">http://www.codegood.com/downloads?dl_cat=2</a></p>
<p>EDIT: Removed original link (it's an ad farm now :( )</p>
| 13 | 2009-09-24T19:52:05Z | [
"python",
"mysql"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 2,372,127 | <p>I was having this problem and then I realised I was importing MySQLdb erroneously - it's case sensitive: </p>
<p>Incorrect: >>>import mysqldb</p>
<p>Correct: >>>import MySQLdb</p>
<p>Silly mistake, but cost me a few hours!</p>
| 2 | 2010-03-03T14:40:11Z | [
"python",
"mysql"
] |
connecting Python 2.6.1 with MySQLdb | 1,135,625 | <p>Hi All
I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect <strong>MySQL-python-1.2.2.win32-py2.6</strong> from <strong><a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a></strong> site but its not ... | 4 | 2009-07-16T05:51:27Z | 5,099,785 | <p>I went for compiled binary , thats the best way to go on windows. There is a good source maintained by someone.
I wrote about it here before because some months down the lane I will forget how I solved this and be searching Stack again :/
<a href="http://vangel.3ezy.com/archives/101-Python-2.4-2.5-2.6-and-2.7-Windo... | 0 | 2011-02-24T02:42:48Z | [
"python",
"mysql"
] |
How do I receive SNMP traps on OS X? | 1,135,981 | <p>I need to receive and parse some SNMP traps (messages) and I would appreciate any advice on getting the code I have working on my OS X machine. I have been given some Java code that runs on Windows with net-snmp. I'd like to either get the Java code running on my development machine or whip up some Python code to do... | 0 | 2009-07-16T07:36:59Z | 1,136,576 | <p>The standard port number for SNMP traps is 162. </p>
<p>Is there a reason you're specifying a different port number ? You can normally change the port number that traps are sent on/received on, but obviously both ends have to agree. So I'm wondering if this is your problem.</p>
| 0 | 2009-07-16T09:57:36Z | [
"java",
"python",
"osx",
"sockets",
"snmp"
] |
How do I receive SNMP traps on OS X? | 1,135,981 | <p>I need to receive and parse some SNMP traps (messages) and I would appreciate any advice on getting the code I have working on my OS X machine. I have been given some Java code that runs on Windows with net-snmp. I'd like to either get the Java code running on my development machine or whip up some Python code to do... | 0 | 2009-07-16T07:36:59Z | 1,139,504 | <p>Ok, the solution to get my code working was to run the program as <code>java -Djava.net.preferIPv4Stack=true -jar bridge.jar</code> and to power cycle the SNMP trap sender. Thanks for your help, Brian.</p>
| 0 | 2009-07-16T18:41:53Z | [
"java",
"python",
"osx",
"sockets",
"snmp"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 1,136,141 | <p>Have a look at <a href="http://www.djangosnippets.org/snippets/446/" rel="nofollow">this</a>. It's meant for use out-of-the-box with MySQL only, but there are pointers on what to do for other databases.</p>
| 3 | 2009-07-16T08:18:00Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 1,136,160 | <p>You might be better off bulk-loading the items - prepare a file and use a bulk load tool. This will be vastly more efficient than 8000 individual inserts.</p>
| 3 | 2009-07-16T08:24:24Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 1,136,248 | <p>You want to check out <code>django.db.transaction.commit_manually</code>.</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/transactions/#django-db-transaction-commit-manually">http://docs.djangoproject.com/en/dev/topics/db/transactions/#django-db-transaction-commit-manually</a></p>
<p>So it would be ... | 84 | 2009-07-16T08:44:56Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 1,139,355 | <p>I recommend using plain SQL (not ORM) you can insert multiple rows with a single insert:</p>
<pre><code>insert into A select from B;
</code></pre>
<p>The <b>select from B</b> portion of your sql could be as complicated as you want it to get as long as the results match the columns in table A and there are no const... | 1 | 2009-07-16T18:18:49Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 3,878,219 | <p>I've ran into the same problem and I can't figure out a way to do it without so many inserts.
I agree that using transactions is probably the <em>right</em> way to solve it, but here is my hack:</p>
<pre><code> def viewfunc(request):
...
to_save = [];
for item in items:
entry = Entry(a1=ite... | -2 | 2010-10-07T02:13:13Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 4,903,947 | <p>You should check out <a href="http://pypi.python.org/pypi/dse/0.4.0" rel="nofollow">DSE</a>. I wrote DSE to solve these kinds of problems ( massive insert or updates ). Using the django orm is a dead-end, you got to do it in plain SQL and DSE takes care of much of that for you.</p>
<p>Thomas</p>
| 2 | 2011-02-04T23:30:55Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 7,971,313 | <p>Bulk creation is available in Django 1.4:</p>
<p><a href="https://django.readthedocs.io/en/1.4/ref/models/querysets.html#bulk-create" rel="nofollow">https://django.readthedocs.io/en/1.4/ref/models/querysets.html#bulk-create</a></p>
| 11 | 2011-11-01T18:45:49Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
What is an efficent way of inserting thousands of records into an SQLite table using Django? | 1,136,106 | <p>I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute.<br /> At the moment I'm using a for loop to iterate through all the items and then insert them one by one.<br />
Example:</p>
<pre><code>for item in items:
entry = Entry(a... | 49 | 2009-07-16T08:08:30Z | 20,840,338 | <p>To answer the question particularly with regard to SQLite, as asked, while I have just now confirmed that bulk_create does provide a tremendous speedup there is a limitation with SQLite: "The default is to create all objects in one batch, except for SQLite where the default is such that at maximum 999 variables per ... | 1 | 2013-12-30T13:15:45Z | [
"python",
"sql",
"django",
"sqlite",
"insert"
] |
Allowing user to configure cron | 1,136,168 | <p>I have this bash script on the server that runs every hour, via cron. I was perfectly happy, but now the user wants to be able to configure the frequency through the web interface.</p>
<p>I don't feel comfortable manipulating the cron configuration programmatically, but I'm not sure if the other options are any bet... | 3 | 2009-07-16T08:25:31Z | 1,136,222 | <p>Give your users some reasonable choices like every minute, every 5 minutes, every half an hour, ... and translate these values to a cron job string. This is user friendly and forbids users to tamper directly with the cron job string.</p>
| 10 | 2009-07-16T08:37:38Z | [
"python",
"bash",
"cron"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.