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 |
|---|---|---|---|---|---|---|---|---|---|
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 27,565,426 | <p>Yes.</p>
<p>You can use <strong>jsonstreamer</strong> SAX-like push parser that I have written which will allow you to parse arbitrary sized chunks, you can <a href="https://github.com/kashifrazzaqui/json-streamer">get it here</a> and checkout the README for examples. Its fast because it uses the 'C' yajl library.<... | 6 | 2014-12-19T11:44:02Z | [
"python",
"json",
"large-files"
] |
Python: How do I create sequential file names? | 2,400,827 | <p>I want my program to be able to write files in a sequential format, ie: file1.txt, file2.txt, file3.txt. It is only meant to write a single file upon execution of the code. It can't overwrite any existing files, and it MUST be created. I'm stumped.</p>
| 5 | 2010-03-08T11:12:27Z | 2,400,861 | <p>Two choices:</p>
<ol>
<li><p>Counter File.</p></li>
<li><p>Check the directory.</p></li>
</ol>
<p><strong>Counter File</strong>.</p>
<pre><code>with open("thecounter.data","r") as counter:
count= int( counter.read() )
count += 1
</code></pre>
<p>Each time you create a new file, you also rewrite the counter ... | 4 | 2010-03-08T11:20:42Z | [
"python",
"filesystems"
] |
Python: How do I create sequential file names? | 2,400,827 | <p>I want my program to be able to write files in a sequential format, ie: file1.txt, file2.txt, file3.txt. It is only meant to write a single file upon execution of the code. It can't overwrite any existing files, and it MUST be created. I'm stumped.</p>
| 5 | 2010-03-08T11:12:27Z | 2,400,870 | <p>Or you could append the current system time to make unique filenames...</p>
| 2 | 2010-03-08T11:22:16Z | [
"python",
"filesystems"
] |
Python: How do I create sequential file names? | 2,400,827 | <p>I want my program to be able to write files in a sequential format, ie: file1.txt, file2.txt, file3.txt. It is only meant to write a single file upon execution of the code. It can't overwrite any existing files, and it MUST be created. I'm stumped.</p>
| 5 | 2010-03-08T11:12:27Z | 22,685,365 | <p>Here is the way I implemented this:</p>
<pre><code>import os
import glob
import re
#we need natural sort to avoid having the list sorted as such:
#['./folder1.txt', './folder10.txt', './folder2.txt', './folder9.txt']
def sorted_nicely(strings):
"Sort strings the way humans are said to expect."
return sorte... | 0 | 2014-03-27T10:51:09Z | [
"python",
"filesystems"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 2,400,875 | <pre><code>>>> t
[1, 3, 6]
>>> [j-i for i, j in zip(t[:-1], t[1:])] # or use itertools.izip in py2k
[2, 3]
</code></pre>
| 57 | 2010-03-08T11:23:38Z | [
"python",
"list"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 2,400,886 | <p>Ok. I think I found the proper solution:</p>
<pre><code>v = [x[1]-x[0] for x in zip(t[1:],t[:-1])]
</code></pre>
| 2 | 2010-03-08T11:25:33Z | [
"python",
"list"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 2,401,936 | <p>The other answers are correct but if you're doing numerical work, you might want to consider numpy. Using numpy, the answer is:</p>
<pre><code>v = numpy.diff(t)
</code></pre>
| 45 | 2010-03-08T14:26:04Z | [
"python",
"list"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 16,714,453 | <p>If you don't want to use <code>numpy</code> nor <code>zip</code>, you can use the simple (simplest in my opinion) solution:</p>
<pre><code>>>> t = [1, 3, 6]
>>> v = [t[i+1]-t[i] for i in range(len(t)-1)]
>>> v
[2, 3]
</code></pre>
| 17 | 2013-05-23T12:51:33Z | [
"python",
"list"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 24,894,043 | <p>You can use <a href="https://docs.python.org/3.4/library/itertools.html#itertools.tee" rel="nofollow"><code>itertools.tee</code></a> and <code>zip</code> to efficiently build the result:</p>
<pre><code>from itertools import tee
# python2 only:
#from itertools import izip as zip
def differences(seq):
iterable, ... | 3 | 2014-07-22T17:34:37Z | [
"python",
"list"
] |
Python - Differences between elements of a list | 2,400,840 | <p>Given a list of numbers how to find differences between every (<code>i</code>)-th and (<code>i+1</code>)-th of its elements? Should one better use lambda or maybe lists comprehension?</p>
<p>Example:
Given a list <code>t=[1,3,6,...]</code> it is to find a list <code>v=[2,3,...]</code> because <code>3-1=2</code>, <c... | 41 | 2010-03-08T11:16:11Z | 36,640,451 | <p>My way</p>
<pre><code>>>>v = [1,2,3,4,5]
>>>[v[i] - v[i-1] for i, value in enumerate(v[1:], 1)]
[1, 1, 1, 1]
</code></pre>
| 0 | 2016-04-15T07:09:34Z | [
"python",
"list"
] |
Why subprocess.Popen doesn't work when args is sequence? | 2,400,878 | <p>I'm having a problem with subprocess.Popen when args parameter is given as sequence.</p>
<p>For example:</p>
<pre><code>import subprocess
maildir = "/home/support/Maildir"
</code></pre>
<p>This works (it prints the correct size of /home/support/Maildir dir):</p>
<pre><code>size = subprocess.Popen(["du -s -b " + ... | 6 | 2010-03-08T11:24:23Z | 2,400,895 | <p>it should be <code>["du", "-s", "-b", maildir]</code></p>
| 1 | 2010-03-08T11:27:34Z | [
"python",
"subprocess"
] |
Why subprocess.Popen doesn't work when args is sequence? | 2,400,878 | <p>I'm having a problem with subprocess.Popen when args parameter is given as sequence.</p>
<p>For example:</p>
<pre><code>import subprocess
maildir = "/home/support/Maildir"
</code></pre>
<p>This works (it prints the correct size of /home/support/Maildir dir):</p>
<pre><code>size = subprocess.Popen(["du -s -b " + ... | 6 | 2010-03-08T11:24:23Z | 2,400,918 | <p>From <a href="http://docs.python.org/library/subprocess.html#using-the-subprocess-module">document</a>,</p>
<blockquote>
<p>On Unix, with <strong>shell=True</strong>: If args is a
<strong>string</strong>, it specifies the command
string to execute through the shell.
If args is a <strong>sequence</strong>, t... | 5 | 2010-03-08T11:30:52Z | [
"python",
"subprocess"
] |
Why subprocess.Popen doesn't work when args is sequence? | 2,400,878 | <p>I'm having a problem with subprocess.Popen when args parameter is given as sequence.</p>
<p>For example:</p>
<pre><code>import subprocess
maildir = "/home/support/Maildir"
</code></pre>
<p>This works (it prints the correct size of /home/support/Maildir dir):</p>
<pre><code>size = subprocess.Popen(["du -s -b " + ... | 6 | 2010-03-08T11:24:23Z | 2,401,128 | <p>From the <a href="http://docs.python.org/library/subprocess.html#using-the-subprocess-module">documentation</a></p>
<blockquote>
<p>On Unix, with shell=True: [â¦] If args is a sequence, the first item specifies the
command string, and any <strong>additional items will be treated as additional arguments to
th... | 9 | 2010-03-08T12:10:27Z | [
"python",
"subprocess"
] |
Why does this python queue code process items multiple times? | 2,401,117 | <p>The following is a testcase I created. Why does every process print the number 1 to 5 and are the numbers not divided over the processes?</p>
<p>code:</p>
<pre><code>#!/usr/bin/python
from subprocess import *
from Queue import Queue
from Queue import Empty
import multiprocessing
from multiprocessing import Proce... | 1 | 2010-03-08T12:08:47Z | 2,401,220 | <p>The Queue package is not process aware, it only works for threads. The following happens in your example:</p>
<ol>
<li>Create Queue and fill with numbers</li>
<li>Fork 4 processes. This copies the memory content into each subprocess, including the filled Queue</li>
<li>Each process empties its copy of the queue</li... | 6 | 2010-03-08T12:27:10Z | [
"python",
"queue",
"multithreading"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,401,245 | <p>I don't really understand the question. You have a Vector which describes a point in space with 3 coordinates. Your implementation already allows you to change the values:</p>
<pre><code>v = Vector()
v.x = 10 # now x is 10
</code></pre>
<p>why should it return a tuple? What would you use it for? That said, a tuple... | 1 | 2010-03-08T12:31:11Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,401,283 | <p><s>I may be misreading your question, but I think what you want is already made for you in <a href="http://docs.python.org/library/collections.html#collections.namedtuple" rel="nofollow"><code>collections.namedtuple</code></a>:</p>
<pre><code>>>> from collections import namedtuple
>>> Vector = nam... | 3 | 2010-03-08T12:38:49Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,401,293 | <p>If I understand your question correctly, you want something like this ?</p>
<pre><code>class Vector(object):
def __init__(self, x=0, y=0, z=0):
self._x, self._y, self._z = x, y, z
def setx(self, x): self._x = float(x)
def sety(self, y): self._y = float(y)
def setz(self, z): self._z... | 5 | 2010-03-08T12:40:23Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,401,304 | <p>Is this what you're looking for? </p>
<pre><code>class vector(object):
def __init__(self, x,y,z):
self.x = x
self.y = y
self.z = z
# overload []
def __getitem__(self, index):
data = [self.x,self.y,self.z]
return data[index]
# overload set []
def __seti... | 2 | 2010-03-08T12:42:11Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,401,335 | <p>I understand that</p>
<ol>
<li>you want to have a filter that transform the input values into floats</li>
<li>you don't want to write the property three times</li>
</ol>
<p>You could use the following code:</p>
<pre><code>class Vector(object):
def __init__(self, x,y,z):
self._x = x
def mangle(name):... | -1 | 2010-03-08T12:46:41Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 2,403,889 | <p><strong>Edit:</strong> My previous answer tried to make a generalized AutoProperties metaclass which I hoped could be of general use. As @martineau's answer shows a solution specialized to the <code>Vector</code> class can make things simpler. </p>
<p>Here's another idea along those lines (specialized simplicity ov... | 2 | 2010-03-08T18:59:44Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 3,357,718 | <p><strong>Edit:</strong> I've modified the code with my answer a bit more from @unutbu's original to simplify it and make what is being done clearer. In the latest version, the <code>@staticmethod</code>'s have been eliminated altogether and replaced with nested one-liners. The outer function and nested class have bee... | 4 | 2010-07-28T21:39:55Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Python Vector Class | 2,401,185 | <p>I'm coming from a C# background where this stuff is super easyâtrying to translate into Python for Maya.</p>
<p>There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 c... | 4 | 2010-03-08T12:21:11Z | 30,245,057 | <p>You can easy represent your vector doing this:</p>
<pre><code>def __repr__(self):
return "(%.1f, %.1f, %.1f)" % (self.x, self.y, self.z)
</code></pre>
<p>When you do methods with <code>__ ... __</code> is like <code>@Override</code> on Java.</p>
| 0 | 2015-05-14T18:50:20Z | [
"python",
"class",
"object",
"vector",
"maya"
] |
Importing Python module from the Bash | 2,401,305 | <p>I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that?</p>
<p>I have tried an alias like this one:</p>
<pre><code>alias program="cd /home/myname... | 7 | 2010-03-08T12:42:11Z | 2,401,314 | <p>Example:</p>
<pre><code>python -c "import time ; print 'waiting 2 sec.'; time.sleep(2); print 'finished' "
</code></pre>
| 3 | 2010-03-08T12:43:47Z | [
"python",
"linux",
"bash",
"alias"
] |
Importing Python module from the Bash | 2,401,305 | <p>I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that?</p>
<p>I have tried an alias like this one:</p>
<pre><code>alias program="cd /home/myname... | 7 | 2010-03-08T12:42:11Z | 2,401,385 | <p>An easy way to do this is with the "code" module:</p>
<pre><code>python -c "import code; code.interact(local=locals())"
</code></pre>
<p>This will drop you into an interactive shell when code.interact() is called. The <code>local</code> keyword argument to <code>interact</code> is used to prepopulate the default ... | 5 | 2010-03-08T12:58:17Z | [
"python",
"linux",
"bash",
"alias"
] |
Importing Python module from the Bash | 2,401,305 | <p>I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that?</p>
<p>I have tried an alias like this one:</p>
<pre><code>alias program="cd /home/myname... | 7 | 2010-03-08T12:42:11Z | 2,401,408 | <p>use a subroutine instead of alias</p>
<pre><code>callmyprogram(){
python -i -c "import time;print time.localtime()"
}
callmyprogram
</code></pre>
| 5 | 2010-03-08T13:02:37Z | [
"python",
"linux",
"bash",
"alias"
] |
How to digitally sign a message with M2Crypto using the keys within a DER format certificate | 2,401,397 | <p>I am working on a project to implement digital signatures of outgoing messages and decided to use M2Crypto for that.</p>
<p>I have a certificate (in DER format) from which I extract the keys to sign the message. For some reason I keep getting an ugly segmentation fault error when I call the "sign_update" method.</p... | 1 | 2010-03-08T13:00:56Z | 2,405,659 | <p>One obvious thing jumps at me: you say your certificate is in DER format, but you are passing <code>format=0</code> to <code>load_cert()</code> which means PEM. See <a href="http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.X509-module.html#section-Variables" rel="nofollow">X509 module variables</a>. Maybe not wha... | 2 | 2010-03-08T23:48:39Z | [
"python",
"digital-signature",
"digital-certificate",
"m2crypto"
] |
How to digitally sign a message with M2Crypto using the keys within a DER format certificate | 2,401,397 | <p>I am working on a project to implement digital signatures of outgoing messages and decided to use M2Crypto for that.</p>
<p>I have a certificate (in DER format) from which I extract the keys to sign the message. For some reason I keep getting an ugly segmentation fault error when I call the "sign_update" method.</p... | 1 | 2010-03-08T13:00:56Z | 2,418,558 | <p>There is no private key file, thats why it crashes and I can not sign it.</p>
| 0 | 2010-03-10T16:23:07Z | [
"python",
"digital-signature",
"digital-certificate",
"m2crypto"
] |
Python recursive function error: "maximum recursion depth exceeded" | 2,401,447 | <p>I solved Problem 10 of Project Euler with the following code, which works through brute force:</p>
<pre><code>def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
def primeList(n):
primes = []
for i in range(2,n):
if isPrime(i):
... | 11 | 2010-03-08T13:10:12Z | 2,401,515 | <p>Well I'm no python expert but I presume you've hit the <a href="http://en.wikipedia.org/wiki/Call_stack" rel="nofollow">stack</a> limit. That's the problem with recursion, it's great when you don't have to recurse very many times but no good when the number of recursions gets even moderately big.</p>
<p>The ideal a... | 1 | 2010-03-08T13:19:46Z | [
"python",
"recursion"
] |
Python recursive function error: "maximum recursion depth exceeded" | 2,401,447 | <p>I solved Problem 10 of Project Euler with the following code, which works through brute force:</p>
<pre><code>def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
def primeList(n):
primes = []
for i in range(2,n):
if isPrime(i):
... | 11 | 2010-03-08T13:10:12Z | 2,401,520 | <p>Recursion is not the most idiomatic way to do things in Python, as it doesn't have <a href="http://en.wikipedia.org/wiki/Tail_recursion">tail recursion</a> optimization thus making impractical the use of recursion as a substitute for iteration (even if in your example the function is not tail-recursive, that wouldn'... | 20 | 2010-03-08T13:20:42Z | [
"python",
"recursion"
] |
Python recursive function error: "maximum recursion depth exceeded" | 2,401,447 | <p>I solved Problem 10 of Project Euler with the following code, which works through brute force:</p>
<pre><code>def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
def primeList(n):
primes = []
for i in range(2,n):
if isPrime(i):
... | 11 | 2010-03-08T13:10:12Z | 2,401,583 | <p>You're iterating over n numbers and recursing at each step. Therefore Python's recursion limit defines your maximum input number. That's obviously undesirable. Especially because the Euler problems typically deal with pretty large numbers.</p>
| 0 | 2010-03-08T13:32:50Z | [
"python",
"recursion"
] |
Python recursive function error: "maximum recursion depth exceeded" | 2,401,447 | <p>I solved Problem 10 of Project Euler with the following code, which works through brute force:</p>
<pre><code>def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
def primeList(n):
primes = []
for i in range(2,n):
if isPrime(i):
... | 11 | 2010-03-08T13:10:12Z | 2,401,755 | <p>Like already said, in languages that can't deal with deep stacks it's better to take an iterative approach. In your case, in particular, it's best to change the algorithm used. I suggest using the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow">Sieve of Eratosthenes</a> to find the list o... | 0 | 2010-03-08T13:58:26Z | [
"python",
"recursion"
] |
Python recursive function error: "maximum recursion depth exceeded" | 2,401,447 | <p>I solved Problem 10 of Project Euler with the following code, which works through brute force:</p>
<pre><code>def isPrime(n):
for x in range(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
def primeList(n):
primes = []
for i in range(2,n):
if isPrime(i):
... | 11 | 2010-03-08T13:10:12Z | 34,236,307 | <p>You can do it in a dirty way:</p>
<pre><code>try: function() except: function()
</code></pre>
| -2 | 2015-12-12T04:36:18Z | [
"python",
"recursion"
] |
What would be the most efficient way to do this search (mysql or text)? | 2,401,508 | <p>Suppose I have 500 rows of data, each with a paragraph of text (like this paragraph). That's it.I want to do a search that matches part of words. (%LIKE%, not FULL_TEXT)</p>
<p>What would be faster?</p>
<ol>
<li>SELECT * FROM ...WHERE LIKE "%query%"; This would put load on the database server.</li>
<li>Select all.... | 0 | 2010-03-08T13:18:54Z | 2,401,635 | <p>This is very hard for us to determine without knowing:</p>
<ul>
<li>the amount of text to search</li>
<li>the load and configuration on the database server</li>
<li>the load and configuration on on the webserver</li>
<li>etc etc ...</li>
</ul>
<p>With that said i would <strong>conceptually</strong> definitely go f... | 1 | 2010-03-08T13:39:55Z | [
"python",
"mysql",
"database",
"regex",
"search"
] |
What would be the most efficient way to do this search (mysql or text)? | 2,401,508 | <p>Suppose I have 500 rows of data, each with a paragraph of text (like this paragraph). That's it.I want to do a search that matches part of words. (%LIKE%, not FULL_TEXT)</p>
<p>What would be faster?</p>
<ol>
<li>SELECT * FROM ...WHERE LIKE "%query%"; This would put load on the database server.</li>
<li>Select all.... | 0 | 2010-03-08T13:18:54Z | 2,403,547 | <p>You can use a full text search if you use myisam engine. <a href="http://dev.mysql.com/doc/refman/5.1/en/fulltext-query-expansion.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/fulltext-query-expansion.html</a></p>
| 0 | 2010-03-08T18:09:43Z | [
"python",
"mysql",
"database",
"regex",
"search"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,401,704 | <p>Have a look at <a href="http://www.ogre3d.org/" rel="nofollow">Ogre</a>; it's the engine behind <strong>Torchlight</strong>. It supports Windows, Ubuntu, MacOS and iPhone. </p>
<p>You may also want to read <a href="http://www.gamasutra.com/" rel="nofollow">Gamasutra</a>: their articles, interviews, in-depth and pos... | 4 | 2010-03-08T13:51:08Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,458,543 | <p>I presume that your game is a 3D one. If yes, than you need OpenGL. It's C, so you'll be familiar with the syntax, but the approach is a bit different, due to the fact that OpenGL is a finite state machine. More on this topic <a href="http://gpwiki.org/index.php/OpenGL%3aTutorials%3aTheory" rel="nofollow">here</a>.<... | 0 | 2010-03-16T22:12:52Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,465,731 | <p>It greatly depends if you want to build a whole game including the engine, or just building upon an established game engine. Although building a whole engine includes much more overhead and hard work, it gives you tons of experience.</p>
<p>Now if you want to create a game engine, the language for the job is C++ (C... | 3 | 2010-03-17T20:41:58Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,467,317 | <p>For casual gaming I would recommend Flash</p>
| 0 | 2010-03-18T03:01:45Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,468,589 | <p>If you haven't programmed a game before, I'd recommend that you start with Python and Pygame. Python itself is very easy to learn if you're already a programmer, so that won't be too much of a leap for you.</p>
<p>With Pygame, you spend almost no time writing "glue" or dealing with mundane low-level details like wi... | 7 | 2010-03-18T09:17:01Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
Game cross-compiling and packaging | 2,401,599 | <p>Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.</p>
<p>We wish our game to be 'standalone'. By standalone, I mean most users (at least Linu... | 5 | 2010-03-08T13:34:11Z | 2,477,280 | <p>i would suggest that you develop it On QT... QT will handle most of the portability issues itself... so you don't have to worry about it, plus it supports most of the platform including mobiles... and QT also has very good native support for gaming (Graphics,UI,Sound Controls.. ) </p>
<p><a href="http://en.wikiped... | 1 | 2010-03-19T12:40:24Z | [
"python",
"c",
"cross-platform",
"packaging",
"cross-compiling"
] |
How to run python scripts on your server? | 2,401,602 | <p>I have mod_python installed on my server, but if I want to acceses a python script - let's say httü://site.com/<strong>something.py</strong> the script doesn't run, the download box "pops up"</p>
<p>Any solutions?</p>
| 2 | 2010-03-08T13:34:29Z | 2,401,607 | <p>This should be on ServerFault. By the way, <code>mod_python</code> is deprecated, use WSGI instead.</p>
| 0 | 2010-03-08T13:36:10Z | [
"python",
"apache",
"unix"
] |
How to run python scripts on your server? | 2,401,602 | <p>I have mod_python installed on my server, but if I want to acceses a python script - let's say httü://site.com/<strong>something.py</strong> the script doesn't run, the download box "pops up"</p>
<p>Any solutions?</p>
| 2 | 2010-03-08T13:34:29Z | 2,401,610 | <p>I would consider a lightweight framework such as <a href="http://werkzeug.pocoo.org/" rel="nofollow">http://werkzeug.pocoo.org/</a> as it isn't very practical in the modern day to have CGI-style python scripts.</p>
<p>And I would use <code>mod_wsgi</code> instead of <code>mod_python</code> as the latter is a bit ou... | 1 | 2010-03-08T13:36:30Z | [
"python",
"apache",
"unix"
] |
How to run python scripts on your server? | 2,401,602 | <p>I have mod_python installed on my server, but if I want to acceses a python script - let's say httü://site.com/<strong>something.py</strong> the script doesn't run, the download box "pops up"</p>
<p>Any solutions?</p>
| 2 | 2010-03-08T13:34:29Z | 2,401,611 | <p>Is mod_py configured ok?<br>
<a href="http://www.modpython.org/live/current/doc-html/inst-apacheconfig.html" rel="nofollow">http://www.modpython.org/live/current/doc-html/inst-apacheconfig.html</a></p>
| 0 | 2010-03-08T13:36:34Z | [
"python",
"apache",
"unix"
] |
open file in "w" mode: IOError: [Errno 2] No such file or directory | 2,401,628 | <p>When I try to open a file in <strong>write</strong> mode with the following code:</p>
<p><code>packetFile = open("%s/%s/%s/%s.mol2" % ("dir", "dir2", "dir3", "some_file"), "w")</code></p>
<p>Gives me the following error:</p>
<p><code>IOError: [Errno 2] No such file or directory: 'dir/dir2/dir3/some_file.mol2'</co... | 21 | 2010-03-08T13:39:04Z | 2,401,649 | <p>Check that that the script has write permissions on that directory. Try this:</p>
<pre><code>chmod a+w dir/dir2/dir3
</code></pre>
<p>Note that this will give write permissions to everyone on that directory.</p>
| 1 | 2010-03-08T13:43:08Z | [
"python",
"file-io"
] |
open file in "w" mode: IOError: [Errno 2] No such file or directory | 2,401,628 | <p>When I try to open a file in <strong>write</strong> mode with the following code:</p>
<p><code>packetFile = open("%s/%s/%s/%s.mol2" % ("dir", "dir2", "dir3", "some_file"), "w")</code></p>
<p>Gives me the following error:</p>
<p><code>IOError: [Errno 2] No such file or directory: 'dir/dir2/dir3/some_file.mol2'</co... | 21 | 2010-03-08T13:39:04Z | 2,401,650 | <p>Since you don't have a 'starting' slash, your python script is looking for this file relative to the current working directory (and not to the root of the filesystem). Also note that the directories leading up to the file must exist!</p>
<p>And: use <a href="http://docs.python.org/library/os.path.html#os.path.join"... | 11 | 2010-03-08T13:43:35Z | [
"python",
"file-io"
] |
open file in "w" mode: IOError: [Errno 2] No such file or directory | 2,401,628 | <p>When I try to open a file in <strong>write</strong> mode with the following code:</p>
<p><code>packetFile = open("%s/%s/%s/%s.mol2" % ("dir", "dir2", "dir3", "some_file"), "w")</code></p>
<p>Gives me the following error:</p>
<p><code>IOError: [Errno 2] No such file or directory: 'dir/dir2/dir3/some_file.mol2'</co... | 21 | 2010-03-08T13:39:04Z | 2,401,655 | <p>You'll see this error if the <em>directory</em> containing the file you're trying to open does not exist, even when trying to open the file in "w" mode.</p>
<p>Since you're opening the file with a relative path, it's possible that you're confused about exactly what that directory is. Try putting a quick print to ch... | 23 | 2010-03-08T13:44:47Z | [
"python",
"file-io"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,401,826 | <p>Mabe this, but it's more or less the same verbose...</p>
<pre><code>import itertools
for airport in itertools.ifilter(lambda x: x.is_important, airports):
...
</code></pre>
| 5 | 2010-03-08T14:08:12Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,401,831 | <p>You could do</p>
<pre><code>for airport in filter(lamdba x: x.is_important, airports):
# do stuff...
</code></pre>
| 16 | 2010-03-08T14:08:46Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,401,839 | <p>Using list comprehension (only if airports is a list of objects):</p>
<pre><code>for airport in [a for a in airports if a.is_important]:
</code></pre>
| 0 | 2010-03-08T14:11:00Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,401,845 | <p>This is a design philosophy of python. If it takes you too many words to put it on one line, it should be broken into a few lines to help the person who comes after you. List and generator expressions are more for transforming iterables in-place -- making more readable forms of <code>map</code> and <code>filter</c... | 1 | 2010-03-08T14:12:05Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,401,855 | <p>No, there is no shorter way. Usually, you will even break it into two lines :</p>
<pre><code>important_airports = (airport for airport in airports if airport.is_important)
for airport in important_airports:
# do stuff
</code></pre>
<p>This is more flexible, easier to read and still don't consume much memory.</... | 42 | 2010-03-08T14:14:31Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 2,404,419 | <p>I'd use a negative guard on the loop. It's readable, and doesn't introduce an extra level of indentation.</p>
<pre><code>for airport in airports:
if not airport.is_important: continue
<body of loop>
</code></pre>
| 8 | 2010-03-08T20:16:42Z | [
"python"
] |
In Python, can I single line a for loop over iterator with an IF filter? | 2,401,785 | <p>Silly question:<br>
I have a simple for loop followed by a simple if statement: </p>
<pre><code>for airport in airports:
if airport.is_important:
</code></pre>
<p>and I was wondering if I can write this as a single line somehow.<br>
So, yes, I can do this: </p>
<pre><code>for airport in (airport for airport... | 24 | 2010-03-08T14:03:33Z | 18,730,750 | <p>Here's an alternative to some of the other filter versions:</p>
<pre><code>from operator import attrgetter as attr
for airport in filter(attr('is_important'), airports):
...
</code></pre>
<p>This has the advantages of being pretty concise and also letting you use dot notation attr('first_class.is_full').</p>
... | 1 | 2013-09-11T00:13:36Z | [
"python"
] |
Unit testing aspect-oriented features | 2,401,789 | <p>I'd like to know what would you propose as the best way to unit test aspect-oriented application features (well, perhaps that's not the best name, but it's the best I was able to come up with :-) ) such as logging or security?</p>
<p>These things are sort of omni-present in the application, so how to test them prop... | 4 | 2010-03-08T14:03:58Z | 2,402,152 | <p>Well... let's see. In my opinion you are testing three different things here (sorry for the "Java AOP jargon"):</p>
<ol>
<li>the features implemented by the interceptors (i.e. the methods that implement the functions activated at the cutpoints)</li>
<li>the coverage of the filters (i.e. whether the intended cutpoin... | 0 | 2010-03-08T14:55:17Z | [
"python",
"unit-testing",
"aop"
] |
Unit testing aspect-oriented features | 2,401,789 | <p>I'd like to know what would you propose as the best way to unit test aspect-oriented application features (well, perhaps that's not the best name, but it's the best I was able to come up with :-) ) such as logging or security?</p>
<p>These things are sort of omni-present in the application, so how to test them prop... | 4 | 2010-03-08T14:03:58Z | 2,427,785 | <p>My answer is for the specific example you give, not for the possible problems with bolted-on security. Decorators are just regular functions, and you can test them as such. For instance:</p>
<pre><code># ... inside included module ...
def require_admin(function):
if (admin):
return function
else:
... | 0 | 2010-03-11T18:53:55Z | [
"python",
"unit-testing",
"aop"
] |
Unit testing aspect-oriented features | 2,401,789 | <p>I'd like to know what would you propose as the best way to unit test aspect-oriented application features (well, perhaps that's not the best name, but it's the best I was able to come up with :-) ) such as logging or security?</p>
<p>These things are sort of omni-present in the application, so how to test them prop... | 4 | 2010-03-08T14:03:58Z | 2,796,926 | <p>IMHO, the way of testing users permissions to the pages depends on the design of your app and design of the framework you're using.</p>
<p>Generally, it's probably enough to cover your permission checker decorator with unit tests to make sure it always works as expected and then write a test that cycles through you... | 1 | 2010-05-09T07:15:27Z | [
"python",
"unit-testing",
"aop"
] |
Do you know a Python module to read Universal File Format (UFF)? | 2,401,991 | <p>Google wasn't my friend this time.</p>
<p>This is the closest to a doc I can find : <a href="http://go-ci.com/note/new/note_401.html" rel="nofollow">http://go-ci.com/note/new/note_401.html</a>. The guys who created that should have something at <a href="http://sdrl.uc.edu/UFF2/58.asc" rel="nofollow">http://sdrl.uc.... | 2 | 2010-03-08T14:34:31Z | 2,402,316 | <p>If you're referring to <a href="http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/file-formats" rel="nofollow">these</a> many "universal file formats", e.g. <a href="http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_0... | 5 | 2010-03-08T15:20:23Z | [
"python"
] |
Do you know a Python module to read Universal File Format (UFF)? | 2,401,991 | <p>Google wasn't my friend this time.</p>
<p>This is the closest to a doc I can find : <a href="http://go-ci.com/note/new/note_401.html" rel="nofollow">http://go-ci.com/note/new/note_401.html</a>. The guys who created that should have something at <a href="http://sdrl.uc.edu/UFF2/58.asc" rel="nofollow">http://sdrl.uc.... | 2 | 2010-03-08T14:34:31Z | 35,587,416 | <p>Yes, there is the pyuff module.</p>
<p>Check out the pyuff showcase:
<a href="https://github.com/openmodal/pyuff/blob/master/pyuff%20Showcase.ipynb">https://github.com/openmodal/pyuff/blob/master/pyuff%20Showcase.ipynb</a></p>
<p>Link to pypi: <a href="https://pypi.python.org/pypi/pyuff">https://pypi.python.org/py... | 5 | 2016-02-23T20:24:24Z | [
"python"
] |
Google App Engine UI Widgets | 2,402,128 | <p>Are there any UI widgets available to the python side of Google App Engine? I'd like something like the collapsed/expanded views of Google Groups threads. Are these type things limited to the GWT side?</p>
| 5 | 2010-03-08T14:52:24Z | 2,402,162 | <p>Why not simply use <a href="http://jqueryui.com/"><strong>jQueryUI</strong></a>? It's a tested and very solid library, and will be easier to pick up than anything else at the current stage.</p>
<p>Cheers</p>
| 9 | 2010-03-08T14:56:25Z | [
"python",
"user-interface",
"google-app-engine"
] |
Google App Engine UI Widgets | 2,402,128 | <p>Are there any UI widgets available to the python side of Google App Engine? I'd like something like the collapsed/expanded views of Google Groups threads. Are these type things limited to the GWT side?</p>
| 5 | 2010-03-08T14:52:24Z | 2,402,429 | <p><a href="http://toscawidgets.org/documentation/tw2.core/">ToscaWidgets</a>, in the version 2 that's currently in alpha test, is said to support App Engine (at least for the <code>tw2.core</code> part). I've also seen posts showing ways (a bit complicated ones, it seemed to me) to use the current ToscaWidgets on App... | 5 | 2010-03-08T15:35:24Z | [
"python",
"user-interface",
"google-app-engine"
] |
Google App Engine UI Widgets | 2,402,128 | <p>Are there any UI widgets available to the python side of Google App Engine? I'd like something like the collapsed/expanded views of Google Groups threads. Are these type things limited to the GWT side?</p>
| 5 | 2010-03-08T14:52:24Z | 2,404,551 | <p>There is no difference in the amount of built in widgets available to the python and java sides of app engine. Neither side has any! App Engine is primarily a back end technology. It allows you to use pretty much whatever web framework you want for your presentation layer, subject to constraints that Alex mentions... | 3 | 2010-03-08T20:37:14Z | [
"python",
"user-interface",
"google-app-engine"
] |
Processing a log to fix a malformed IP address ?.?.?.x | 2,402,553 | <p>I would like to replace the first character '<strong>x</strong>' with the number '<strong>7</strong>' on every line of a log file using a shell script. Example of the log file:</p>
<pre><code>216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17... | 1 | 2010-03-08T15:50:32Z | 2,402,606 | <p>The following perl one-liner should do the trick:</p>
<p><code>
perl -p -i -e 's/\.x/\.7/' foo.log
</code></p>
<p>It'll substitute the first instance of '.x' with '.7' on each line of the log file. </p>
| 2 | 2010-03-08T15:57:29Z | [
"python",
"perl",
"bash",
"string",
"shell"
] |
Processing a log to fix a malformed IP address ?.?.?.x | 2,402,553 | <p>I would like to replace the first character '<strong>x</strong>' with the number '<strong>7</strong>' on every line of a log file using a shell script. Example of the log file:</p>
<pre><code>216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17... | 1 | 2010-03-08T15:50:32Z | 2,403,869 | <p>You can use this little python script (which could probably be written in fewer lines than this):</p>
<pre><code>import sys
for line in sys.stdin:
ip_number, rest = line.split(' ', 1)
ip_parts = ip_number.split('.')
ip_parts[3] = '7'
ip_number = '.'.join(ip_parts)
print ip_number, rest,
</code><... | 0 | 2010-03-08T18:56:50Z | [
"python",
"perl",
"bash",
"string",
"shell"
] |
Processing a log to fix a malformed IP address ?.?.?.x | 2,402,553 | <p>I would like to replace the first character '<strong>x</strong>' with the number '<strong>7</strong>' on every line of a log file using a shell script. Example of the log file:</p>
<pre><code>216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17... | 1 | 2010-03-08T15:50:32Z | 2,405,809 | <p>while i don't know what's the purpose of putting "7" in every IP because that's inaccurate, nevertheless, here's an awk one-liner</p>
<pre><code>$ awk '{sub(/x$/,7,$1)}1' file
216.129.119.7 [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.7 [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17.7 [01/Mar/2010:... | 2 | 2010-03-09T00:25:56Z | [
"python",
"perl",
"bash",
"string",
"shell"
] |
Processing a log to fix a malformed IP address ?.?.?.x | 2,402,553 | <p>I would like to replace the first character '<strong>x</strong>' with the number '<strong>7</strong>' on every line of a log file using a shell script. Example of the log file:</p>
<pre><code>216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17... | 1 | 2010-03-08T15:50:32Z | 2,405,918 | <p>Python (run with file to process as the first argument):</p>
<pre><code>import sys
import gzip
fin = gzip.GzipFile(sys.argv[1], 'r')
fout = gzip.GzipFile(sys.argv[1] + '.new', 'w', 9)
for line in fin:
address, rest = line.split(' ', 1)
prefix, node = address.rsplit('.', 1)
fout.write('%s.7 %s' % (prefix, re... | 0 | 2010-03-09T00:49:37Z | [
"python",
"perl",
"bash",
"string",
"shell"
] |
Processing a log to fix a malformed IP address ?.?.?.x | 2,402,553 | <p>I would like to replace the first character '<strong>x</strong>' with the number '<strong>7</strong>' on every line of a log file using a shell script. Example of the log file:</p>
<pre><code>216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/....
74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/....
222.168.17... | 1 | 2010-03-08T15:50:32Z | 2,406,013 | <p>since everyone is posting their alternative solutions i'm going to post one that i think is very simple:</p>
<pre><code>sed s/\.x/\.7/ input_file > output_file
</code></pre>
<p>replace any string ".x" by ".7"</p>
<p>hope it helps! :)</p>
| 3 | 2010-03-09T01:13:09Z | [
"python",
"perl",
"bash",
"string",
"shell"
] |
Convert list in tuple to numpy array? | 2,402,575 | <p>I have tuple of lists. One of these lists is a list of scores. I want to convert the list of scores to a numpy array to take advantage of the pre-built stats that scipy provides.</p>
<p>In this case the tuple is called 'data'</p>
<pre><code>In [12]: type data[2]
-------> type(data[2])
Out[12]: <type 'list'&g... | 17 | 2010-03-08T15:53:38Z | 2,402,604 | <p>The command <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html"><code>numpy.asarray</code></a> will turn a number of pre-set iterable containers (list, tuple, etc) into a numpy array.</p>
| 38 | 2010-03-08T15:57:17Z | [
"python",
"arrays",
"numpy",
"scipy",
"tuples"
] |
Why is my spawned process still causing IntelliJ to wait? | 2,402,635 | <p>I'm trying to start a server as part of an Ant artifact. </p>
<p>Here are the relevant lines:</p>
<pre><code> <exec dir="." executable="cmd.exe" spawn="true">
<arg line="/c c:\Java\james-2.3.2\bin\debug.bat" />
</exec>
</code></pre>
<p>If I start it with <code>ant</code> from the ... | 0 | 2010-03-08T16:01:06Z | 2,418,140 | <p>I've given up on figuring this out, so instead I set up an XML RPC server that does the starting and stopping, and the startup/shutdown scripts make an XML RPC call.</p>
<p>Code for the server (simplified):</p>
<pre><code>from __future__ import with_statement
from threading import Lock
from SimpleXMLRPCServer imp... | 0 | 2010-03-10T15:33:49Z | [
"python",
"ant",
"intellij-idea",
"subprocess"
] |
Python - Initializing Multiple Lists/Line | 2,402,646 | <p>This is terribly ugly:</p>
<pre><code>psData = []
nsData = []
msData = []
ckData = []
mAData = []
RData = []
pData = []
</code></pre>
<p>Is there a way to declare these variables on a single line?</p>
| 15 | 2010-03-08T16:03:11Z | 2,402,653 | <pre><code>alist, blist, clist, dlist, elist = ([] for i in range(5))
</code></pre>
<p>The downside of above approach is, you need to count the number of names on the left of <code>=</code> and have exactly the same number of empty lists (e.g. via the <code>range</code> call, or more explicitly) on the right hand
sid... | 56 | 2010-03-08T16:04:10Z | [
"python",
"list",
"initialization"
] |
Python - Initializing Multiple Lists/Line | 2,402,646 | <p>This is terribly ugly:</p>
<pre><code>psData = []
nsData = []
msData = []
ckData = []
mAData = []
RData = []
pData = []
</code></pre>
<p>Is there a way to declare these variables on a single line?</p>
| 15 | 2010-03-08T16:03:11Z | 2,402,661 | <pre><code>psData,nsData,msData,ckData,mAData,RData,pData = [],[],[],[],[],[],[]
</code></pre>
| 1 | 2010-03-08T16:05:35Z | [
"python",
"list",
"initialization"
] |
Python - Initializing Multiple Lists/Line | 2,402,646 | <p>This is terribly ugly:</p>
<pre><code>psData = []
nsData = []
msData = []
ckData = []
mAData = []
RData = []
pData = []
</code></pre>
<p>Is there a way to declare these variables on a single line?</p>
| 15 | 2010-03-08T16:03:11Z | 2,402,678 | <p>Depending on your needs, you could consider using a defaultdict with a list factory.
Something like:</p>
<pre><code>my_lists = collections.defaultdict(list)
</code></pre>
<p>and then you can directly append to my_lists["psData"] and so on.
This is the relevant doc page: <a href="http://docs.python.org/library/coll... | 6 | 2010-03-08T16:07:57Z | [
"python",
"list",
"initialization"
] |
Python - Initializing Multiple Lists/Line | 2,402,646 | <p>This is terribly ugly:</p>
<pre><code>psData = []
nsData = []
msData = []
ckData = []
mAData = []
RData = []
pData = []
</code></pre>
<p>Is there a way to declare these variables on a single line?</p>
| 15 | 2010-03-08T16:03:11Z | 11,437,881 | <p>You can use a class to initialize/store the data, it would take more lines, but could be easier to read, and more object oriented.</p>
<p>Like:</p>
<pre><code>class Data:
def __init__(self):
self.var1=[]
<etc.>
def zeroize(self):
self.var1=[]
<etc.>
</code></pre>... | -1 | 2012-07-11T17:12:59Z | [
"python",
"list",
"initialization"
] |
django: caching passwords for custom authentication | 2,402,694 | <p>I am authenticating users in ldap, but this happens only once, when user is logging in. Afterwards I need to keep username and password, because before every ldap operation I need to make bind on ldap server before every operation. What is the safe way to cache this password (I can't store in the database or cookies... | 1 | 2010-03-08T16:09:42Z | 2,402,812 | <p>solution 1:
maybe the most elegant solution would be to write your own <a href="http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend" rel="nofollow">auth-backend</a> and share it with the community :-)</p>
<p>solution 2:
make use of the very good <a href="http://docs.djangoproject.com... | 1 | 2010-03-08T16:26:31Z | [
"python",
"django",
"caching",
"ldap",
"passwords"
] |
django: caching passwords for custom authentication | 2,402,694 | <p>I am authenticating users in ldap, but this happens only once, when user is logging in. Afterwards I need to keep username and password, because before every ldap operation I need to make bind on ldap server before every operation. What is the safe way to cache this password (I can't store in the database or cookies... | 1 | 2010-03-08T16:09:42Z | 2,402,916 | <p>You may cache authentication credentials in sessions. If you are afraid that they may "leak" to disk, i.e. be cached in database, you may use memory based sessions.</p>
<p>With cache session engine (<a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cached-sessions" rel="nofollow">Using cache... | 2 | 2010-03-08T16:42:08Z | [
"python",
"django",
"caching",
"ldap",
"passwords"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,852 | <p>In an environment like that, you can't go wrong with VB/C#. Try the various <a href="http://www.microsoft.com/express/Windows/" rel="nofollow">VS Express</a> editions.</p>
<p>If you want something that will translate to Linux a little more, Python and just about any cross-platform GUI framework(QT, or wxpython) wou... | 5 | 2010-03-08T16:32:29Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,857 | <p>As long as the clients don't share a database, a .NET WPF/WinForms app w/ an embedded DB sounds like it would work just fine.</p>
<p>You could probably even develop something that works on both Windows PCs and your Linux machine using Mono (you'd be stuck with a subset of WinForms...but for a simple business app, t... | 0 | 2010-03-08T16:33:23Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,859 | <p>Have you thought about <a href="http://www.appcelerator.com/" rel="nofollow">Appcelerator Titanium</a> or something similar? You create a rich GUI using web techniques (HTML, CSS, javascript and or python) and compile that to a desktop application.</p>
<p>The advantage would be that you can develop on Linux, and on... | 0 | 2010-03-08T16:33:46Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,866 | <p>I would say web app (C#) with SQL Express on the back end - but this is just me</p>
| 2 | 2010-03-08T16:34:31Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,883 | <p>WPF has a pretty steep learning curve, especially coming from Access. WinForms would be a simpler path, but it's still a leap from Access. However, both WPF and WinForms have drag-and-drop form construction, and assuming you learn enough VB.NET to convert the VBA business logic, you're more than halfway there. :)</p... | 1 | 2010-03-08T16:37:15Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,906 | <p>MS Access is a desktop database application. One step up is most likely <a href="http://www.microsoft.com/Sqlserver/2005/en/us/compact.aspx" rel="nofollow">SQL Server Compact Edition (SQLCE)</a>, which operates as part of your application (as opposed to SQL Server Express or higher, which run as system services). I'... | 3 | 2010-03-08T16:40:47Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,402,966 | <p>VB and C# are certainly similar to Access, and would be good if you are looking to not move too far away. </p>
<p>Python is brilliant but nothing like Access. It is simply a programming language that happens to have good db libraries. The GUI libraries look pretty good as well though I have never used them. GUI de... | 0 | 2010-03-08T16:48:35Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,404,017 | <p>I said this in a comment, but I'll repeat it as an answer:</p>
<p>If you look at the future of Access, it's bright. MS is investing a lot in it. Access 2010 in conjunction with Sharepoint 2010 offers some pretty amazing benefits, and you do it all without any VBA (instead you use the new, powerful macros, which hav... | 1 | 2010-03-08T19:17:55Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,404,428 | <p>Based on your criteria, I would use PyGtk and Glade. Gtk is well supported on Windows and Linux, and I've gotten more done in less time with Python and GTK, than with any other language/toolkit combination.</p>
<p>If you are willing to rethink doing it on the web, have a look at <a href="http://www.extjs.com" rel=... | 1 | 2010-03-08T20:18:30Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
wanting to move up from ms access, thinking .net? visual studio? | 2,402,814 | <p>So I wrote a project-management program for a small business using Microsoft Access 2007.</p>
<p>Now they've requested lots of additional features (timekeeping, privileged data tiers ...)</p>
<p>I personally use Linux, but the whole office uses Windows.</p>
<p>I'm relatively new to programming but like to teach m... | 5 | 2010-03-08T16:26:40Z | 2,404,714 | <p>If it's only smallish, internal apps you're working on, take a look at <a href="http://www.visualwebgui.com/" rel="nofollow">Visual WebGUI</a> - you get a very VB6-like development environment for web apps. I would not recommend it for large and/or public apps though.</p>
| 0 | 2010-03-08T21:03:34Z | [
".net",
"python",
"database",
"ms-access",
"access-vba"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,910 | <p>The behavior occurs because all calls to your <code>__init__</code> method share the same default list.</p>
<p>Try:</p>
<pre><code>class intlist:
def __init__(self, l):
self.l = l if (l is not None) else []
def add(self,a):
self.l.append(a)
</code></pre>
<p>EDIT: Us... | 1 | 2010-03-08T16:41:26Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,912 | <p>Ah, you've hit one of the common Python gotchas: default values are computed once, then re-used. So, every time <code>__init__</code> is called, the <em>same</em> list is being used.</p>
<p>This is the Pythonic way of doing what you want:</p>
<pre><code>def __init__(self, l=None):
self.l = [] if l is None else... | 14 | 2010-03-08T16:41:51Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,913 | <p>The issue is that when you are saying</p>
<pre><code>def __init__(self,l = []):
</code></pre>
<p>You are telling Python to use the same list, <code>[]</code>, for each invocation of the constructor. So each time <code>obj = intlist()</code> is called the same list is appended to. </p>
<p>What you should do instea... | 3 | 2010-03-08T16:41:54Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,915 | <p>Be careful with default parameters of types like lists and dicts. Each instance of intlist gets that same list object from the default parameter.</p>
| 0 | 2010-03-08T16:42:03Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,919 | <p>When you set the default value of <code>l=[]</code> in <code>__init__</code>, you're actually using the same list each time. Instead, you could try something like:</p>
<pre><code>class intlist:
def __init__(self, l=None):
if l is None:
self.l = []
else:
self.l = l
</code>... | 4 | 2010-03-08T16:42:44Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,932 | <p><code>obj = intlist()</code> calls your <code>__init__()</code> function which uses the same array for every instance of the class.</p>
<p><code>obj = intlist(l=[])</code> creates a new array for every instance.</p>
| 1 | 2010-03-08T16:44:21Z | [
"python",
"class",
"attributes",
"instance"
] |
Python instances and attributes: is this a bug or i got it totally wrong? | 2,402,887 | <p>Suppose you have something like this:</p>
<pre><code>class intlist:
def __init__(self,l = []):
self.l = l
def add(self,a):
self.l.append(a)
def appender(a):
obj = intlist()
obj.add(a)
print obj.l
if __name__ == "__main__":
for i in ra... | 5 | 2010-03-08T16:37:56Z | 2,402,940 | <p>For more information I suggest reading this: <a href="http://effbot.org/zone/default-values.htm" rel="nofollow">http://effbot.org/zone/default-values.htm</a></p>
| 1 | 2010-03-08T16:45:05Z | [
"python",
"class",
"attributes",
"instance"
] |
How do I create a set of image files from a PowerPoint file file? | 2,403,041 | <p>I'm creating a "slideshow room" web page. The user will upload a PowerPoint file that my server will use to generate a set of .jpg image files representing the slides to present in a custom "gallery viewer".</p>
<p>I'm an experienced Python developer but I cannot find anything useful.</p>
<p>How can I do that?</p>... | 4 | 2010-03-08T16:59:37Z | 2,403,104 | <p>Off the top of my head, the way I'd do it:</p>
<ol>
<li>Use OpenOffice.org to convert the .ppt file into a PDF. (OO.o has a very rich Java API. Rich and bloody difficult to use, mind, but once you figure out how to get it to do the task you need, you're all set. Dunno if you can do anything useful with it via Py... | 4 | 2010-03-08T17:08:24Z | [
"python",
"powerpoint",
"jpeg"
] |
How do I create a set of image files from a PowerPoint file file? | 2,403,041 | <p>I'm creating a "slideshow room" web page. The user will upload a PowerPoint file that my server will use to generate a set of .jpg image files representing the slides to present in a custom "gallery viewer".</p>
<p>I'm an experienced Python developer but I cannot find anything useful.</p>
<p>How can I do that?</p>... | 4 | 2010-03-08T16:59:37Z | 2,403,707 | <p>Are you doing this on Windows? If so win32 com:</p>
<pre><code>import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
Application.Visible = True
Presentation = Application.Presentations.Open(pathToPPT)
Presentation.Slides[1].Export("C:/path/to/jpg.jpg", "JPG", 800, 600);
etc...
</c... | 1 | 2010-03-08T18:29:18Z | [
"python",
"powerpoint",
"jpeg"
] |
How do I create a set of image files from a PowerPoint file file? | 2,403,041 | <p>I'm creating a "slideshow room" web page. The user will upload a PowerPoint file that my server will use to generate a set of .jpg image files representing the slides to present in a custom "gallery viewer".</p>
<p>I'm an experienced Python developer but I cannot find anything useful.</p>
<p>How can I do that?</p>... | 4 | 2010-03-08T16:59:37Z | 2,404,490 | <p>Apache <a href="http://poi.apache.org/" rel="nofollow">POI</a> and Jython. POI, even has an ImageExtractor class, but having just glanced at the Javadocs, I suspect it is incomplete.</p>
| 0 | 2010-03-08T20:26:30Z | [
"python",
"powerpoint",
"jpeg"
] |
doctest locally defined functions | 2,403,237 | <p>is there any way to doctest locally defined functions? As an example I would want </p>
<pre><code>def foo():
""" >>> foo()
testfoo"""
def foo2():
""" >>> 1/0 """
print 'testfoo'
foo2()
</code></pre>
<p>to NOT pass the test. But still I would not want to make foo2 global for the... | 5 | 2010-03-08T17:25:22Z | 2,403,757 | <p>You just have a whitespace problem -- if you fix it, for example as follows:</p>
<pre><code>def foo():
"""
>>> foo()
testfoo"""
def foo2():
""" >>> 1/0 """
print 'testfoo'
foo2()
if __name__ == '__main__':
import doctest
doctest.testmod()
</code></pre>
<p>the test pa... | 1 | 2010-03-08T18:36:18Z | [
"python",
"doctest"
] |
doctest locally defined functions | 2,403,237 | <p>is there any way to doctest locally defined functions? As an example I would want </p>
<pre><code>def foo():
""" >>> foo()
testfoo"""
def foo2():
""" >>> 1/0 """
print 'testfoo'
foo2()
</code></pre>
<p>to NOT pass the test. But still I would not want to make foo2 global for the... | 5 | 2010-03-08T17:25:22Z | 2,432,052 | <p>Thanks. I already feared there would be no way around code outside the docstring. Still I thought there might be a trick to import the locals of a function and thus get access to nested functions. Anyhow, a solution using Alex' approach would read</p>
<pre><code>def foo(debug=False):
"""
>>> foo()
... | 1 | 2010-03-12T10:37:37Z | [
"python",
"doctest"
] |
Node.js as a custom (streaming) upload handler for Django | 2,403,280 | <p>I want to build an upload-centric app using Django. One way to do this is with nginx's upload module (nonblocking) but it has its problems. Node.js is supposed to be a good candidate for this type of application. But how can I make node.js act as an <a href="http://docs.djangoproject.com/en/1.1/topics/http/file-uplo... | 2 | 2010-03-08T17:31:32Z | 2,440,831 | <p>Okay I'm not like an expert on the subject or anything, but the way I think I understand it, nginx is a proxy that runs in front of the webserver that serves your django app, right?</p>
<p>You could build a simple node.js server that does the same - listen on port 80, wait until the request is completely sent to th... | 2 | 2010-03-14T01:28:34Z | [
"python",
"django",
"javascript",
"node.js",
"uploading"
] |
Node.js as a custom (streaming) upload handler for Django | 2,403,280 | <p>I want to build an upload-centric app using Django. One way to do this is with nginx's upload module (nonblocking) but it has its problems. Node.js is supposed to be a good candidate for this type of application. But how can I make node.js act as an <a href="http://docs.djangoproject.com/en/1.1/topics/http/file-uplo... | 2 | 2010-03-08T17:31:32Z | 2,754,266 | <p>Make node.js write the file to disk and proxy the upload POST to Django along with a '_node_file' value so your Django view knows where to get the file.</p>
| 0 | 2010-05-02T17:22:00Z | [
"python",
"django",
"javascript",
"node.js",
"uploading"
] |
Python: Get values (objects) from a dictionary of objects in which one of the object's field matches a value (or condition) | 2,403,372 | <p>I have a python dictionary whose keys are strings and the values are objects.</p>
<p>For instance, and object with one string and one int</p>
<pre><code>class DictItem:
def __init__(self, field1, field2):
self.field1 = str(field1)
self.field2 = int(field2)
</code></pre>
<p>and the dictionary:</p>
... | 5 | 2010-03-08T17:46:38Z | 2,403,431 | <pre><code>mySubList = [dict((k,v) for k,v in myDict.iteritems() if v.field2 >= 2)]
</code></pre>
<p>Documentation:</p>
<p><a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list-comprehensions</a>, <a href="http://docs.python.org/library/stdtypes.html#dict.iteritems" ... | 3 | 2010-03-08T17:55:56Z | [
"python",
"dictionary"
] |
Python: Get values (objects) from a dictionary of objects in which one of the object's field matches a value (or condition) | 2,403,372 | <p>I have a python dictionary whose keys are strings and the values are objects.</p>
<p>For instance, and object with one string and one int</p>
<pre><code>class DictItem:
def __init__(self, field1, field2):
self.field1 = str(field1)
self.field2 = int(field2)
</code></pre>
<p>and the dictionary:</p>
... | 5 | 2010-03-08T17:46:38Z | 2,403,533 | <p>You should keep your various records - that is "DicItem" instances - inside a list.
An generator/list expression can then filter your desired results with ease.</p>
<pre><code>data = [
DictItem("test1", 1),
DictItem("test2", 2),
DictItem("test3", 3),
DictItem("test4", 4),
]
</code></pre>
<p>and then:<... | 3 | 2010-03-08T18:07:08Z | [
"python",
"dictionary"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.