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 |
|---|---|---|---|---|---|---|---|---|---|
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 1,606,870 | <p>Some rules of thumb for <code>subprocess</code>.</p>
<ul>
<li><strong>Never</strong> use <code>shell=True</code>. It needlessy invokes an extra shell process to call your program.</li>
<li>When calling processes, arguments are passed around as lists. <code>sys.argv</code> in python is a list, and so is <code>argv</... | 51 | 2009-10-22T12:29:06Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 8,058,981 | <p>I've noticed that there is no mention of using a temporary file as intermediate. The following gets around the buffering issues by outputting to a temporary file and allows you to parse the data coming from rsync without connecting to a pty. I tested the following on a linux box, and the output of rsync tends to d... | 0 | 2011-11-09T00:31:36Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 11,902,799 | <p>You cannot get stdout to print unbuffered to a pipe (unless you can rewrite the program that prints to stdout), so here is my solution:</p>
<p>Redirect stdout to sterr, which is not buffered. <code>'<cmd> 1>&2'</code> should do it. Open the process as follows: <code>myproc = subprocess.Popen('<cmd... | 6 | 2012-08-10T13:34:07Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 14,837,673 | <pre><code>for line in p.stdout:
...
</code></pre>
<p>always blocks until the next line-feed.</p>
<p>For "real-time" behaviour you have to do something like this:</p>
<pre><code>while True:
inchar = p.stdout.read(1)
if inchar: #neither empty string nor None
print(str(inchar), end='') #or end=None to flush ... | 6 | 2013-02-12T16:55:25Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 16,346,104 | <p>Your problem is:</p>
<pre><code>for line in p.stdout:
print(">>> " + str(line.rstrip()))
p.stdout.flush()
</code></pre>
<p>the iterator itself has extra buffering.</p>
<p>Try doing like this:</p>
<pre><code>while True:
line = p.stdout.readline()
if not line:
break
print line
</code></... | 2 | 2013-05-02T19:23:00Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 35,775,429 | <p>I know this is an old topic, but there is a solution now. Call the rsync with option --outbuf=L. Example:</p>
<pre><code>cmd=['rsync', '-arzv','--backup','--outbuf=L','source/','dest']
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, b''):
print '>>... | 5 | 2016-03-03T14:51:56Z | [
"python",
"subprocess",
"stdout"
] |
catching stdout in realtime from subprocess | 1,606,795 | <p>I have read tons of posts but still can't seem to figure it out.</p>
<p>I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.</p>
<p>My code works, but it doesn't catch the progress until a file is done transfered! I want to print the progress for each file in realtime.</p>
<p>Using p... | 39 | 2009-10-22T12:14:43Z | 38,943,027 | <p>To avoid caching of output you might wanna try pexpect, </p>
<pre><code>child = pexpect.spawn(launchcmd,args,timeout=None)
while True:
try:
child.expect('\n')
print(child.before)
except pexpect.EOF:
break
</code></pre>
<p><strong>PS</strong> : I know this question is pretty old, sti... | 0 | 2016-08-14T14:08:46Z | [
"python",
"subprocess",
"stdout"
] |
How to get all unique IDs from the list of dicts? | 1,606,915 | <p>Say you have a list of dicts like this <code>{'id': 1, 'other_value':5}</code></p>
<p>So maybe;</p>
<pre><code>items = [{'id': 1, 'other_value':5}, {'id': 1, 'other_value2':6}, {'id': 2, 'other_value':4}, {'id': 2, 'other_value2':3}]
</code></pre>
<p>Now, you can assume this is a small subset of the data. There a... | 0 | 2009-10-22T12:35:53Z | 1,606,935 | <p>if you want unique id's you can use a set:</p>
<pre><code>set(i['id'] for i in items)
</code></pre>
| 7 | 2009-10-22T12:39:44Z | [
"python"
] |
How to get all unique IDs from the list of dicts? | 1,606,915 | <p>Say you have a list of dicts like this <code>{'id': 1, 'other_value':5}</code></p>
<p>So maybe;</p>
<pre><code>items = [{'id': 1, 'other_value':5}, {'id': 1, 'other_value2':6}, {'id': 2, 'other_value':4}, {'id': 2, 'other_value2':3}]
</code></pre>
<p>Now, you can assume this is a small subset of the data. There a... | 0 | 2009-10-22T12:35:53Z | 1,606,945 | <pre><code>set(i['id'] for i in items)
</code></pre>
<p>but you might consider another data structure altogether, for example dict of lists:</p>
<pre><code>items = {1: [5, 6], 2: [2, 4]}
</code></pre>
| 1 | 2009-10-22T12:40:49Z | [
"python"
] |
Load different modules without changing the logic file | 1,606,960 | <p>Suppose I've got 2 different modules which have the uniform(same) interfaces. The files list like this:</p>
<pre><code>root/
logic.py
sns_api/
__init__.py
facebook/
pyfacebook.py
__init__.py
myspace/
pymyspace.py
__init__.py
</code></pre>
<p>And pyfac... | 2 | 2009-10-22T12:44:02Z | 1,606,974 | <p>Have a "factory" function in each module, do dynamic import and call the factory for the loaded module. At least, that's one way to do it. Remember, the pythonic way is "duck typing" so that factory returns an object and the client uses it through "duck calls" :-)</p>
| 0 | 2009-10-22T12:48:49Z | [
"python",
"interface",
"dynamic-import"
] |
Load different modules without changing the logic file | 1,606,960 | <p>Suppose I've got 2 different modules which have the uniform(same) interfaces. The files list like this:</p>
<pre><code>root/
logic.py
sns_api/
__init__.py
facebook/
pyfacebook.py
__init__.py
myspace/
pymyspace.py
__init__.py
</code></pre>
<p>And pyfac... | 2 | 2009-10-22T12:44:02Z | 1,607,014 | <p>With just two i'd do</p>
<pre><code>if platform == 'facebook':
from pyfacebook import FaceBook as Platform
elif platform == 'myspace':
from pymyspace import Myspace as Platform
else:
raise RuntimeError, "not a valid platform"
</code></pre>
<p>and use <code>Platform</code> in the rest of the code. It's ... | 6 | 2009-10-22T12:58:11Z | [
"python",
"interface",
"dynamic-import"
] |
Load different modules without changing the logic file | 1,606,960 | <p>Suppose I've got 2 different modules which have the uniform(same) interfaces. The files list like this:</p>
<pre><code>root/
logic.py
sns_api/
__init__.py
facebook/
pyfacebook.py
__init__.py
myspace/
pymyspace.py
__init__.py
</code></pre>
<p>And pyfac... | 2 | 2009-10-22T12:44:02Z | 1,608,881 | <p>You can also use exec:</p>
<pre><code>exec "from sns_api.%s import Platform" % PLATFORM
</code></pre>
<p>Then in your implementation files, assign something to Platform:</p>
<pre><code># in pyfacebook.py
class Facebook:
def __init__(self, a, b):
# do the init
def method1(self, a, b, ...):
# do... | 0 | 2009-10-22T17:51:10Z | [
"python",
"interface",
"dynamic-import"
] |
Best method to determine which of a set of keys exist in the datastore | 1,607,126 | <p>I have a few hundred keys, all of the same Model, which I have pre-computed:</p>
<pre><code>candidate_keys = [db.Key(...), db.Key(...), db.Key(...), ...]
</code></pre>
<p>Some of these keys refer to actual entities in the datastore, and some do not. I wish to determine which keys do correspond to entities.</p>
<p... | 2 | 2009-10-22T13:18:21Z | 1,607,204 | <p>At this point, the only solution I have is to manually query by key with <code>keys_only=True</code>, once per key.</p>
<pre><code>for key in candidate_keys:
if MyModel.all(keys_only=True).filter('__key__ =', key).count():
keys_with_entities.add(key)
</code></pre>
<p>This may in fact be slower then just load... | 0 | 2009-10-22T13:29:21Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Best method to determine which of a set of keys exist in the datastore | 1,607,126 | <p>I have a few hundred keys, all of the same Model, which I have pre-computed:</p>
<pre><code>candidate_keys = [db.Key(...), db.Key(...), db.Key(...), ...]
</code></pre>
<p>Some of these keys refer to actual entities in the datastore, and some do not. I wish to determine which keys do correspond to entities.</p>
<p... | 2 | 2009-10-22T13:18:21Z | 1,607,264 | <h2>How not to do it (update based on Nick Johnson's answer):</h2>
<p>I am also considering adding a parameter specifically for the purpose of being able to scan for it with an <code>IN</code> filter.</p>
<pre><code>class MyModel(db.Model):
"""Some model"""
# ... all the old stuff
the_key = db.StringProperty(re... | 0 | 2009-10-22T13:36:51Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Best method to determine which of a set of keys exist in the datastore | 1,607,126 | <p>I have a few hundred keys, all of the same Model, which I have pre-computed:</p>
<pre><code>candidate_keys = [db.Key(...), db.Key(...), db.Key(...), ...]
</code></pre>
<p>Some of these keys refer to actual entities in the datastore, and some do not. I wish to determine which keys do correspond to entities.</p>
<p... | 2 | 2009-10-22T13:18:21Z | 1,607,462 | <p>IN filters are not supported directly by the App Engine datastore; they're a convenience that's implemented in the client library. An IN query with 30 values is translated into 30 equality queries on one value each, resulting in 30 regular queries!</p>
<p>Due to round-trip times and the expense of even keys-only qu... | 3 | 2009-10-22T14:04:28Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
PyQt custom widget in c++ | 1,607,515 | <p>Can I write custom Qt widget in pure C++, compile it and use in PyQt?</p>
<p>I'm trying to use the ctypes-opencv with qt and I have performance problems with python's code for displaying opencv's image in Qt form.</p>
| 1 | 2009-10-22T14:12:19Z | 1,607,536 | <p>You will have to write a Python wrapper for the widget, using the <code>sip</code> library (which is used by PyQt). There is a <a href="http://pyqt.sourceforge.net/Docs/sip4/using.html#a-more-complex-c-example" rel="nofollow">simple example</a> for a Qt/C++ widget in the documentation.</p>
| 4 | 2009-10-22T14:15:47Z | [
"c++",
"python",
"qt",
"pyqt",
"python-sip"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,628 | <pre><code>class Subclass (SuperClass):
# Subclass stuff here
</code></pre>
| 0 | 2009-10-22T14:28:27Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,629 | <pre><code>class Class1(object):
pass
class Class2(Class1):
pass
</code></pre>
<p>Class2 is a sub-class of Class1</p>
| 3 | 2009-10-22T14:28:35Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,630 | <p>You use:</p>
<pre><code>class DerivedClassName(BaseClassName):
</code></pre>
<p>For details, see the <a href="https://docs.python.org/2/tutorial/classes.html#inheritance" rel="nofollow">Python docs, section 9.5</a>.</p>
| 2 | 2009-10-22T14:28:44Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,631 | <pre><code>class MySubClass(MySuperClass):
def __init__(self):
MySuperClass.__init__(self)
# <the rest of your custom initialization code goes here>
</code></pre>
<p>The <a href="http://docs.python.org/2/tutorial/classes.html" rel="nofollow">section on inheritance</a> in the python documenta... | 17 | 2009-10-22T14:28:46Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,633 | <pre><code>class Mammal(object):
#mammal stuff
class Dog(Mammal):
#doggie stuff
</code></pre>
| 1 | 2009-10-22T14:28:55Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,651 | <p>Subclassing in Python is done as follows:</p>
<pre><code>class WindowElement:
def print(self):
pass
class Button(WindowElement):
def print(self):
pass
</code></pre>
<p>Here is a <a href="http://www.gidnetwork.com/b-137.html" rel="nofollow">tutorial</a> about Python that also contains class... | 0 | 2009-10-22T14:31:13Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,607,708 | <p>A heroic little example:</p>
<pre><code>class SuperHero(object): #superclass, inherits from default object
def getName(self):
raise NotImplementedError #you want to override this on the child classes
class SuperMan(SuperHero): #subclass, inherits from SuperHero
def getName(self):
return "Cl... | 29 | 2009-10-22T14:39:05Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 1,608,905 | <p>The use of "super" (see <a href="http://docs.python.org/2/library/functions.html#super">Python Built-in</a>, super) may be a slightly better method of calling the parent for initialization:</p>
<pre><code># Initialize using Parent
#
class MySubClass(MySuperClass):
def __init__(self):
MySuperClass.__init... | 38 | 2009-10-22T17:54:40Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 25,899,123 | <p>There is another way to make subclasses in python dynamically with a function <code>type()</code>:</p>
<pre><code>SubClass = type('SubClass', (BaseClass,), {'set_x': set_x}) # Methods can be set, including __init__()
</code></pre>
<p>You usually want to use this method when working with metaclasses. When you want... | 1 | 2014-09-17T19:48:30Z | [
"python",
"class"
] |
Python: How do I make a subclass from a superclass? | 1,607,612 | <p>In Python, how do you make a subclass from a superclass?</p>
| 26 | 2009-10-22T14:26:22Z | 38,214,084 | <pre><code> class BankAccount:
def __init__(self, balance=0):
self.balance = int(balance)
def checkBalance(self): ## Checking opening balance....
return self.balance
def deposit(self, deposit_amount=1000): ## takes in cash deposit ... | -1 | 2016-07-05T22:54:46Z | [
"python",
"class"
] |
What profiling tools exist for Python on Linux beyond the ones included in the standard library? | 1,607,641 | <p>I've been using Python's built-in cProfile tool with some pretty good success. But I'd like to be able to access more information such as how long I'm waiting for I/O (and what kind of I/O I'm waiting on) or how many cache misses I have. Are there any Linux tools to help with this beyond your basic time command?</... | 1 | 2009-10-22T14:29:42Z | 1,608,157 | <p>I'm not sure if python will provide the low level information you are looking for. You might want to look at oprofile and latencytop though.</p>
| 2 | 2009-10-22T15:46:42Z | [
"python",
"linux",
"profiling"
] |
What profiling tools exist for Python on Linux beyond the ones included in the standard library? | 1,607,641 | <p>I've been using Python's built-in cProfile tool with some pretty good success. But I'd like to be able to access more information such as how long I'm waiting for I/O (and what kind of I/O I'm waiting on) or how many cache misses I have. Are there any Linux tools to help with this beyond your basic time command?</... | 1 | 2009-10-22T14:29:42Z | 1,613,044 | <p>If you want to know exactly what you are waiting for, and approximately what percentage of the time, <a href="http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024">this</a> will tell you. It won't tell you other things though, like cache misses or memory leaks.</p>
| 1 | 2009-10-23T12:14:10Z | [
"python",
"linux",
"profiling"
] |
How to create a file one directory up? | 1,607,751 | <p>How can I create a file in python one directory up, without using the full path?</p>
<p>I would like a way that worked both for windows and linux.</p>
<p>Thanks.</p>
| 9 | 2009-10-22T14:44:02Z | 1,607,764 | <p>Use <code>os.pardir</code> (which is probably always <code>".."</code>)</p>
<pre><code>import os
fobj = open(os.path.join(os.pardir, "filename"), "w")
</code></pre>
| 19 | 2009-10-22T14:45:46Z | [
"python",
"io"
] |
How to create a file one directory up? | 1,607,751 | <p>How can I create a file in python one directory up, without using the full path?</p>
<p>I would like a way that worked both for windows and linux.</p>
<p>Thanks.</p>
| 9 | 2009-10-22T14:44:02Z | 1,607,770 | <p>Depends whether you are working in a unix or windows environment.</p>
<p>On windows:</p>
<pre><code>..\foo.txt
</code></pre>
<p>On unix like OS:</p>
<pre><code>../foo.txt
</code></pre>
<p>you need to make sure the os sets the current path correctly when your application launches.
Take the appropriate path and s... | 0 | 2009-10-22T14:46:52Z | [
"python",
"io"
] |
How to create a file one directory up? | 1,607,751 | <p>How can I create a file in python one directory up, without using the full path?</p>
<p>I would like a way that worked both for windows and linux.</p>
<p>Thanks.</p>
| 9 | 2009-10-22T14:44:02Z | 1,607,881 | <p>People don't seem to realize this, but Python is happy to accept forward slash even on Windows. This works fine on all platforms:</p>
<pre><code>fobj = open("../filename", "w")
</code></pre>
| 4 | 2009-10-22T15:05:57Z | [
"python",
"io"
] |
Django syntax highlighting causing character escaping issues | 1,607,979 | <p>I've been working on my own django based blog (like everyone, I know) to sharpen up my python, and I thought added some syntax highlight would be pretty great. I looked at some of the snippets out there and decided to combine a few and write my own syntax highlighting template filter using Beautiful Soup and Pygment... | 1 | 2009-10-22T15:20:35Z | 1,657,847 | <p>I've finally found some time to figure it out. When beautiful soup pulls in the content and it contains a tag, the tag is listed as a sub node of a list. This line is the culprit:</p>
<pre><code>new_content = pygments.highlight(code.contents[0], lexer, formatter)
</code></pre>
<p>The [0] cuts off the other part of... | 1 | 2009-11-01T18:07:06Z | [
"python",
"django",
"escaping",
"pygments"
] |
Counting booleans in dictionary | 1,608,040 | <p>I have a python dictionary object that contains a boolean for every key, e.g.:</p>
<pre><code>d = {'client1': True, 'client2': False}
</code></pre>
<p>What is the easiest and most concise way to count the number of True values in the dictionary?</p>
| 5 | 2009-10-22T15:29:33Z | 1,608,053 | <p>For clarity:</p>
<pre><code>num_true = sum(1 for condition in d.values() if condition)
</code></pre>
<p>For conciseness (this works because True is a subclass of int with a value 1):</p>
<pre><code>num_true = sum(d.values())
</code></pre>
| 15 | 2009-10-22T15:31:02Z | [
"python",
"dictionary"
] |
Counting booleans in dictionary | 1,608,040 | <p>I have a python dictionary object that contains a boolean for every key, e.g.:</p>
<pre><code>d = {'client1': True, 'client2': False}
</code></pre>
<p>What is the easiest and most concise way to count the number of True values in the dictionary?</p>
| 5 | 2009-10-22T15:29:33Z | 1,608,063 | <pre><code>sum(d.values())
</code></pre>
| 2 | 2009-10-22T15:32:21Z | [
"python",
"dictionary"
] |
Counting booleans in dictionary | 1,608,040 | <p>I have a python dictionary object that contains a boolean for every key, e.g.:</p>
<pre><code>d = {'client1': True, 'client2': False}
</code></pre>
<p>What is the easiest and most concise way to count the number of True values in the dictionary?</p>
| 5 | 2009-10-22T15:29:33Z | 1,608,085 | <p>In Python <code>2.*</code>, sum(d.itervalues()) is slightly less concise than the <code>sum(d.values())</code> many are proposing (4 more characters;-), but avoids needlessly materializing the list of values and so saves memory (and probably time) when you have a large dictionary to deal with.</p>
<p>As some have p... | 1 | 2009-10-22T15:37:01Z | [
"python",
"dictionary"
] |
Counting booleans in dictionary | 1,608,040 | <p>I have a python dictionary object that contains a boolean for every key, e.g.:</p>
<pre><code>d = {'client1': True, 'client2': False}
</code></pre>
<p>What is the easiest and most concise way to count the number of True values in the dictionary?</p>
| 5 | 2009-10-22T15:29:33Z | 1,608,088 | <pre><code>a.values().count(True)
</code></pre>
| 2 | 2009-10-22T15:37:07Z | [
"python",
"dictionary"
] |
os.walk and some tests | 1,608,090 | <p>I'm not sure if i understand properly how os.walk store its results.</p>
<p>Im trying to do the following:</p>
<p>I'm checking a root folder for subsequent folders. There are several hundreds of em, and they are nested in somewaht uniform way.</p>
<p>I'm trying to check each subfolder, and if it ends with a four ... | 0 | 2009-10-22T15:37:11Z | 1,608,121 | <p>regex you should be using is:</p>
<pre><code>pattern = re.compile(r'(?<!\d)\d{4}$')
re.search(pattern, p)
</code></pre>
<p>as for <code>os.walk</code> your explanation is not entirely clear.</p>
| 0 | 2009-10-22T15:42:33Z | [
"python",
"regex",
"folders"
] |
os.walk and some tests | 1,608,090 | <p>I'm not sure if i understand properly how os.walk store its results.</p>
<p>Im trying to do the following:</p>
<p>I'm checking a root folder for subsequent folders. There are several hundreds of em, and they are nested in somewaht uniform way.</p>
<p>I'm trying to check each subfolder, and if it ends with a four ... | 0 | 2009-10-22T15:37:11Z | 1,608,135 | <p>About the regex: If you use <code>p[-4:]</code>, you'll always look at the last four characters of <code>p</code>, so you don't get a chance to see if there really are five. </p>
<p>So instead, use</p>
<pre><code>regex = "(?<![0-9])[0-9]{4}$"
padrao = re.compile(regex)
regexObject = re.search(padrao, p)
</code... | 0 | 2009-10-22T15:44:50Z | [
"python",
"regex",
"folders"
] |
os.walk and some tests | 1,608,090 | <p>I'm not sure if i understand properly how os.walk store its results.</p>
<p>Im trying to do the following:</p>
<p>I'm checking a root folder for subsequent folders. There are several hundreds of em, and they are nested in somewaht uniform way.</p>
<p>I'm trying to check each subfolder, and if it ends with a four ... | 0 | 2009-10-22T15:37:11Z | 1,608,148 | <blockquote>
<p>using "$[0-9]{4}" but it returns me
nothing. Any ideas why?</p>
</blockquote>
<p><code>$</code> means end-of-(line or string) in a regex pattern, so I wonder how you expected "end of string then four digits" to ever possibly match anything...? By definition of "end" it won't be followed by 4 digit... | 3 | 2009-10-22T15:46:24Z | [
"python",
"regex",
"folders"
] |
How to script a google search without google license key? | 1,608,442 | <p>I'm looking at 'pygoogle' python library for google search, call from my python script. But google doesn't give out license key anymore, and looks like pygoogle needs license key to work.</p>
<p>Does anyone have suggestions of libraries to use for scripting web searches? Languages doesn't matter. It can be in pytho... | 0 | 2009-10-22T16:33:05Z | 1,608,494 | <p>They don't give out keys for the SOAP API anymore, because <a href="http://code.google.com/apis/soapsearch/" rel="nofollow">that's deprecated</a>. But you can use their <a href="http://code.google.com/apis/ajaxsearch/" rel="nofollow">AJAX API</a>, which is now the preferred interface. You can get a developer key <a ... | 10 | 2009-10-22T16:42:43Z | [
"python",
"perl",
"api",
"search"
] |
How to script a google search without google license key? | 1,608,442 | <p>I'm looking at 'pygoogle' python library for google search, call from my python script. But google doesn't give out license key anymore, and looks like pygoogle needs license key to work.</p>
<p>Does anyone have suggestions of libraries to use for scripting web searches? Languages doesn't matter. It can be in pytho... | 0 | 2009-10-22T16:33:05Z | 1,608,628 | <p>Your question made me look. </p>
<ul>
<li><p>Yahoo! now offers a new search service called <a href="http://developer.yahoo.com/search/boss/" rel="nofollow">BOSS</a> which looks very interesting.</p></li>
<li><p>Microsoft offers access via the <a href="http://msdn.microsoft.com/en-us/library/dd251056.aspx" rel="nofo... | 0 | 2009-10-22T17:07:29Z | [
"python",
"perl",
"api",
"search"
] |
How to script a google search without google license key? | 1,608,442 | <p>I'm looking at 'pygoogle' python library for google search, call from my python script. But google doesn't give out license key anymore, and looks like pygoogle needs license key to work.</p>
<p>Does anyone have suggestions of libraries to use for scripting web searches? Languages doesn't matter. It can be in pytho... | 0 | 2009-10-22T16:33:05Z | 1,615,392 | <p>in case you are still looking - this is how (with ajax api in python): <a href="http://dcortesi.com/2008/05/28/google-ajax-search-api-example-python-code/" rel="nofollow">http://dcortesi.com/2008/05/28/google-ajax-search-api-example-python-code/</a></p>
| 0 | 2009-10-23T19:18:18Z | [
"python",
"perl",
"api",
"search"
] |
Site wide caching with Django - problems with password protected pages on logout | 1,608,521 | <p>I've recently implemented sitewide caching using <a href="http://en.wikipedia.org/wiki/Memcached" rel="nofollow">memcached</a> on my Django application, I've set the <a href="http://en.wikipedia.org/wiki/Time%5Fto%5Flive" rel="nofollow">TTL</a> to about 500 seconds, and implement per view caches on other parts of th... | 5 | 2009-10-22T16:47:13Z | 1,608,636 | <p>In the view of a password protected part of the site, do you check whether the user is registered or anonymous before fetching the data (and perhaps bringing data from cache)?</p>
<p>You should. Django helps you, with a login required decorator you can place on the view.
Take a look at this:
<a href="http://docs.dj... | 1 | 2009-10-22T17:09:08Z | [
"python",
"django",
"memcached"
] |
Site wide caching with Django - problems with password protected pages on logout | 1,608,521 | <p>I've recently implemented sitewide caching using <a href="http://en.wikipedia.org/wiki/Memcached" rel="nofollow">memcached</a> on my Django application, I've set the <a href="http://en.wikipedia.org/wiki/Time%5Fto%5Flive" rel="nofollow">TTL</a> to about 500 seconds, and implement per view caches on other parts of th... | 5 | 2009-10-22T16:47:13Z | 1,609,360 | <p>I ran into similar issues. The standard Django way is to disable cache for authenticated users. </p>
<pre><code>#settings.py
CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True
</code></pre>
<p>It works fine if different users see different pages (example: their user name on them) and you can't have one version for them.</p>
<p... | 7 | 2009-10-22T19:11:59Z | [
"python",
"django",
"memcached"
] |
Unable to get WAF to run | 1,608,646 | <p>I am trying to build the Monotooth library on Ubuntu and there is a native component which needs to be compiled. The distro from github has a wscript file and requires WAF to build. However, whenever I try to execute waf configure I get:</p>
<pre><code>Checking for program gcc : ok /usr/bin/gcc
Ch... | 1 | 2009-10-22T17:11:42Z | 1,609,787 | <p>I found that I needed to use a version of waf from <a href="http://waf.googlecode.com/files/waf-1.3.2.tar.bz2" rel="nofollow">http://waf.googlecode.com/files/waf-1.3.2.tar.bz2</a></p>
<p>I had version 1.5.9 which must have deprecated the create_library_configurator method.</p>
| 2 | 2009-10-22T20:34:32Z | [
"python",
"wscript",
"waf"
] |
Run time of a subprocess.Popen instance | 1,608,724 | <p>Is there an easy way to find out the current (real or cpu) run time of a subprocess.Popen instance?</p>
| 1 | 2009-10-22T17:26:29Z | 1,608,855 | <p>Not in a platform-independent manner. On Linux, you can read <code>/proc/<pid>/stat</code>, in particular the columns utime, stime, and starttime (as described in <a href="http://linux.die.net/man/5/proc" rel="nofollow">proc(5)</a>).</p>
| 0 | 2009-10-22T17:48:13Z | [
"python",
"subprocess"
] |
Run time of a subprocess.Popen instance | 1,608,724 | <p>Is there an easy way to find out the current (real or cpu) run time of a subprocess.Popen instance?</p>
| 1 | 2009-10-22T17:26:29Z | 1,608,884 | <p>No, but you can simply subclass and extend the Popen class to store the time it was created.</p>
| 1 | 2009-10-22T17:51:28Z | [
"python",
"subprocess"
] |
Run time of a subprocess.Popen instance | 1,608,724 | <p>Is there an easy way to find out the current (real or cpu) run time of a subprocess.Popen instance?</p>
| 1 | 2009-10-22T17:26:29Z | 1,610,294 | <p>On a Windows machine, you can use win32 APIs along with proc.pid, like so:</p>
<pre><code>import subprocess
def print_times(proc):
import win32process, win32api, win32con
hproc = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, False, proc.pid)
times = win32process.GetProcessTimes(hproc)
wi... | 0 | 2009-10-22T22:14:16Z | [
"python",
"subprocess"
] |
Whats new in Python 3.x? | 1,608,731 | <p><a href="http://docs.python.org/3.0/whatsnew/3.0.html" rel="nofollow">http://docs.python.org/3.0/whatsnew/3.0.html</a> says it lists whats <em>new</em>, but in my opinion, it only lists <em>differences</em>, so has does anybody know of any <em>completely new</em> Python features, introduced in release 3.x?</p>
<p>T... | 4 | 2009-10-22T17:27:54Z | 1,608,771 | <p>The section <a href="http://docs.python.org/3.0/whatsnew/3.0.html#new-syntax" rel="nofollow">New Syntax</a> lists, well, the new syntax in Python 3.x. I think it's debatable sometimes whether stuff is new or changed. E.g. exception chaining (<a href="http://www.python.org/dev/peps/pep-3134/" rel="nofollow">PEP 3134<... | 4 | 2009-10-22T17:34:27Z | [
"python"
] |
Whats new in Python 3.x? | 1,608,731 | <p><a href="http://docs.python.org/3.0/whatsnew/3.0.html" rel="nofollow">http://docs.python.org/3.0/whatsnew/3.0.html</a> says it lists whats <em>new</em>, but in my opinion, it only lists <em>differences</em>, so has does anybody know of any <em>completely new</em> Python features, introduced in release 3.x?</p>
<p>T... | 4 | 2009-10-22T17:27:54Z | 1,608,827 | <p>Many of the completely new features introduced in 3.0 were also backported to 2.6, a deliberate choice. However, this was not practical in all cases, so some of the new features remained Python 3 - only.</p>
<p>How metaclasses work, is probably the biggest single new feature. The syntax is clearly better than <cod... | 8 | 2009-10-22T17:45:07Z | [
"python"
] |
Types that define `__eq__` are unhashable in Python 3.x? | 1,608,842 | <p>I had a strange bug when porting a feature to the Python 3.1 fork of my program. I narrowed it down to the following hypothesis:</p>
<p>In contrast to Python 2.x, in Python 3.x if an object has a <code>.__eq__</code> method it is automatically unhashable.</p>
<p>Is this true?</p>
<p>Here's what happens in Python ... | 28 | 2009-10-22T17:46:31Z | 1,608,865 | <p>I'm no python expert, but wouldn't it make sense that, when you define a eq-method, you also have to define a hash-method as well (which calculates the hash value for an object) Otherwise, the hashing mechanism wouldn't know if it hit the same object, or a different object with just the same hash-value. Actually, it... | 1 | 2009-10-22T17:49:37Z | [
"python",
"hash",
"python-3.x"
] |
Types that define `__eq__` are unhashable in Python 3.x? | 1,608,842 | <p>I had a strange bug when porting a feature to the Python 3.1 fork of my program. I narrowed it down to the following hypothesis:</p>
<p>In contrast to Python 2.x, in Python 3.x if an object has a <code>.__eq__</code> method it is automatically unhashable.</p>
<p>Is this true?</p>
<p>Here's what happens in Python ... | 28 | 2009-10-22T17:46:31Z | 1,608,882 | <p>Yes, if you define <code>__eq__</code>, the default <code>__hash__</code> (namely, hashing the address of the object in memory) goes away. This is important because hashing needs to be consistent with equality: equal objects need to hash the same.</p>
<p>The solution is simple: just define <code>__hash__</code> alo... | 33 | 2009-10-22T17:51:11Z | [
"python",
"hash",
"python-3.x"
] |
Types that define `__eq__` are unhashable in Python 3.x? | 1,608,842 | <p>I had a strange bug when porting a feature to the Python 3.1 fork of my program. I narrowed it down to the following hypothesis:</p>
<p>In contrast to Python 2.x, in Python 3.x if an object has a <code>.__eq__</code> method it is automatically unhashable.</p>
<p>Is this true?</p>
<p>Here's what happens in Python ... | 28 | 2009-10-22T17:46:31Z | 1,608,888 | <p>Check the Python 3 manual on <a href="http://docs.python.org/3.1/reference/datamodel.html?highlight=hash#object.%5F%5Fhash%5F%5F" rel="nofollow"><code>object.__hash__</code></a>:</p>
<blockquote>
<p>If a class does not define an <code>__eq__()</code> method it should not define a <code>__hash__()</code> operation... | 2 | 2009-10-22T17:52:16Z | [
"python",
"hash",
"python-3.x"
] |
Types that define `__eq__` are unhashable in Python 3.x? | 1,608,842 | <p>I had a strange bug when porting a feature to the Python 3.1 fork of my program. I narrowed it down to the following hypothesis:</p>
<p>In contrast to Python 2.x, in Python 3.x if an object has a <code>.__eq__</code> method it is automatically unhashable.</p>
<p>Is this true?</p>
<p>Here's what happens in Python ... | 28 | 2009-10-22T17:46:31Z | 1,608,907 | <p>This paragraph from <a href="http://docs.python.org/3.1/reference/datamodel.html#object.%5F%5Fhash%5F%5F">http://docs.python.org/3.1/reference/datamodel.html#object.%5F%5Fhash%5F%5F</a></p>
<blockquote>
<p>If a class that overrides <code>__eq__()</code>
needs to retain the implementation of
<code>__hash__()</... | 11 | 2009-10-22T17:54:53Z | [
"python",
"hash",
"python-3.x"
] |
Abstract base class inheritance in Django with foreignkey | 1,608,975 | <p>I am attempting model inheritance on my Django powered site in order to adhere to DRY. My goal is to use an abstract base class called BasicCompany to supply the common info for three child classes: Butcher, Baker, CandlestickMaker (they are located in their own apps under their respective names).</p>
<p>Each of th... | 9 | 2009-10-22T18:03:46Z | 1,609,213 | <p>I suspect you'll be better off with <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1">generic relations</a> for the links, rather than trying to tie everything to a base class. Generic relations allow you to link a model such as EmailAddress to any other class, which would seem to be a goo... | 6 | 2009-10-22T18:43:56Z | [
"python",
"django",
"inheritance",
"django-models",
"abstract-class"
] |
Filter a User list using a UserProfile field in Django Admin | 1,609,241 | <p>I'm trying to filter the User list in Django using a UserProfile Field... I need to implement a queue system where new users are put in a queue until an Admin approves them.</p>
<p>I simply added a <code>is_in_queue</code> boolean field to my UserProfile model... However, when displaying the user list in my Admin a... | 5 | 2009-10-22T18:49:54Z | 1,609,859 | <p>It sounds to me like the quickest and easiest option is to add a new admin view to your application, specifically for your custom user model. See the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-options" rel="nofollow">Django admin docs</a> for details, though it sounds like you know h... | 0 | 2009-10-22T20:48:03Z | [
"python",
"django",
"django-admin"
] |
Filter a User list using a UserProfile field in Django Admin | 1,609,241 | <p>I'm trying to filter the User list in Django using a UserProfile Field... I need to implement a queue system where new users are put in a queue until an Admin approves them.</p>
<p>I simply added a <code>is_in_queue</code> boolean field to my UserProfile model... However, when displaying the user list in my Admin a... | 5 | 2009-10-22T18:49:54Z | 1,609,993 | <p>You may want to take a look in to using a custom manager for the <code>admin_objects</code> of your model.</p>
<pre><code>class UserAdminManager(models.AdminManager):
"""
Custom manager for the User model.
"""
def get_query_set(self):
"""
Overwrites the get_query_set to only return Users in the queue.
"... | 1 | 2009-10-22T21:14:52Z | [
"python",
"django",
"django-admin"
] |
Filter a User list using a UserProfile field in Django Admin | 1,609,241 | <p>I'm trying to filter the User list in Django using a UserProfile Field... I need to implement a queue system where new users are put in a queue until an Admin approves them.</p>
<p>I simply added a <code>is_in_queue</code> boolean field to my UserProfile model... However, when displaying the user list in my Admin a... | 5 | 2009-10-22T18:49:54Z | 8,511,605 | <p>Django 1.3 fixed that - list_filter now allows to span relations:</p>
<p><a href="https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter" rel="nofollow">https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter</a></p>
| 3 | 2011-12-14T21:03:08Z | [
"python",
"django",
"django-admin"
] |
How to make a private download area with django? | 1,609,273 | <p>I would like to implement a private download area on a website powered by django. The user would have to be logged in with the appropriate rights in order to be able to get some static files.</p>
<p>What would you recommend for writing this feature. Any tips or tricks?</p>
<p>Thanks in advance</p>
<p>Update:
Mayb... | 9 | 2009-10-22T18:54:28Z | 1,609,463 | <p>There's tons of tutorials on how to enable authentication in Django. Do you need help with that? If so, start <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">here</a>. </p>
<p>The next step is to create a View which lists your files. So do that, this is all basic Django. If you have... | 1 | 2009-10-22T19:33:08Z | [
"python",
"django",
"authentication",
"download"
] |
How to make a private download area with django? | 1,609,273 | <p>I would like to implement a private download area on a website powered by django. The user would have to be logged in with the appropriate rights in order to be able to get some static files.</p>
<p>What would you recommend for writing this feature. Any tips or tricks?</p>
<p>Thanks in advance</p>
<p>Update:
Mayb... | 9 | 2009-10-22T18:54:28Z | 1,609,799 | <p>So, searching I found <a href="http://groups.google.com/group/django-users/browse%5Fthread/thread/92a97bee7ab168b5">this</a> discussion thread.</p>
<p>There were three things said you might be interested in.</p>
<p>First there is the mod_python <a href="http://docs.djangoproject.com/en/dev/howto/apache-auth/">meth... | 8 | 2009-10-22T20:37:20Z | [
"python",
"django",
"authentication",
"download"
] |
How to make a private download area with django? | 1,609,273 | <p>I would like to implement a private download area on a website powered by django. The user would have to be logged in with the appropriate rights in order to be able to get some static files.</p>
<p>What would you recommend for writing this feature. Any tips or tricks?</p>
<p>Thanks in advance</p>
<p>Update:
Mayb... | 9 | 2009-10-22T18:54:28Z | 1,624,379 | <p>The XSendfile seems to be the right approach but It looks to be a bit complex to setup. I've decided to use a simpler way.</p>
<p>Based on emeryc answer and django snippets <a href="http://www.djangosnippets.org/snippets/365/" rel="nofollow">http://www.djangosnippets.org/snippets/365/</a>, I have written the follow... | 3 | 2009-10-26T11:54:20Z | [
"python",
"django",
"authentication",
"download"
] |
How import Pydev project into interactive console? | 1,609,460 | <p>Newbie question (I'm just getting started with Python and Pydev):</p>
<p>I've created a project "Playground" with (standard?) src/root sub-folder. In there I've created example.py.</p>
<p>How do I import my "example" module into Pydev's interactive console?
">>> import example" gives: "ImportError: No module named... | 8 | 2009-10-22T19:32:55Z | 1,609,487 | <p>You need to set your PYTHONPATH accordingly (Google search is your friend) or use *.pth in your installation <em>site-packages</em> directory pointing to your project path. Don't forget to set your interpreter details with Pydev (Window->Preferences->Pydev->interpreter).</p>
| 5 | 2009-10-22T19:37:02Z | [
"python",
"pydev"
] |
How import Pydev project into interactive console? | 1,609,460 | <p>Newbie question (I'm just getting started with Python and Pydev):</p>
<p>I've created a project "Playground" with (standard?) src/root sub-folder. In there I've created example.py.</p>
<p>How do I import my "example" module into Pydev's interactive console?
">>> import example" gives: "ImportError: No module named... | 8 | 2009-10-22T19:32:55Z | 1,616,005 | <p>I found the answer on the Plone website: <a href="http://plone.org/documentation/tutorial/developing-plone-with-eclipse/setting-up-pythonpath-in-eclipse">Setting up PYTHONPATH in Eclipse project</a>.
This provides a convenient way to set PYTHONPATH on a per project basis. In my case I added "/Playground/src/root" t... | 5 | 2009-10-23T21:30:22Z | [
"python",
"pydev"
] |
How import Pydev project into interactive console? | 1,609,460 | <p>Newbie question (I'm just getting started with Python and Pydev):</p>
<p>I've created a project "Playground" with (standard?) src/root sub-folder. In there I've created example.py.</p>
<p>How do I import my "example" module into Pydev's interactive console?
">>> import example" gives: "ImportError: No module named... | 8 | 2009-10-22T19:32:55Z | 14,227,168 | <p>Following the PYTHONPATH advice above, I used a bit of a hack to get this working. If I understand your question, you want to have the current working directory in the IPython environment set to the directory in which your active file resides. So if you are editing D:/projects/file.py, you want the pwd() command (in... | 0 | 2013-01-09T01:58:40Z | [
"python",
"pydev"
] |
Suds + JIRA = SAXException | 1,609,666 | <p>I'm using Python 2.6 and suds 0.3.7 to interact with JIRA 4.0.</p>
<p>When I connect to the JIRA server, I get information on all the issues just fine.</p>
<p>However, when I want to update an issue, I get a SAXException from suds (presumably):</p>
<blockquote>
<p>WebFault: Server raised fault:
org.xml.sax.S... | 3 | 2009-10-22T20:09:58Z | 1,610,182 | <p>How about increasing the verbosity to see what is being sent? Or use wireshark. You could also do the same with SOAPpy and compare exactly what is sent. Debugging soap errors is usually like this for me :-/ </p>
<p>~Matt</p>
| 1 | 2009-10-22T21:50:05Z | [
"python",
"soap",
"jira",
"suds"
] |
Suds + JIRA = SAXException | 1,609,666 | <p>I'm using Python 2.6 and suds 0.3.7 to interact with JIRA 4.0.</p>
<p>When I connect to the JIRA server, I get information on all the issues just fine.</p>
<p>However, when I want to update an issue, I get a SAXException from suds (presumably):</p>
<blockquote>
<p>WebFault: Server raised fault:
org.xml.sax.S... | 3 | 2009-10-22T20:09:58Z | 1,622,578 | <p>Actually, by just changing the library from suds to SOAPpy, everything started working with no other modifications. Kind of annoying. I skipped SOAPpy because it seemed to have been abandoned and more complex to install, compared to suds. But SOAPpy works!</p>
<p>Thanks, all.</p>
| 1 | 2009-10-26T00:13:31Z | [
"python",
"soap",
"jira",
"suds"
] |
Suds + JIRA = SAXException | 1,609,666 | <p>I'm using Python 2.6 and suds 0.3.7 to interact with JIRA 4.0.</p>
<p>When I connect to the JIRA server, I get information on all the issues just fine.</p>
<p>However, when I want to update an issue, I get a SAXException from suds (presumably):</p>
<blockquote>
<p>WebFault: Server raised fault:
org.xml.sax.S... | 3 | 2009-10-22T20:09:58Z | 2,282,739 | <p>This will be solved if you switch to suds 3.0.9 (beta) ... the only one to have the fix.</p>
| 1 | 2010-02-17T17:06:33Z | [
"python",
"soap",
"jira",
"suds"
] |
I need __closure__ | 1,609,716 | <p>I just checked out this very interesting mindmap:</p>
<p><a href="http://www.mindmeister.com/10510492/python-underscore">http://www.mindmeister.com/10510492/python-underscore</a></p>
<p>And I was wondering what some of the new ones mean, like <code>__code__</code> and <code>__closure__</code>. I googled around but... | 7 | 2009-10-22T20:18:19Z | 1,609,739 | <p>From <a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html">What's New in Python 3.0</a></p>
<p>The function attributes named <code>func_X</code> have been renamed to use the <code>__X__</code> form, freeing up these names in the function attribute namespace for user-defined attributes. To wit, <code>func_closu... | 7 | 2009-10-22T20:23:27Z | [
"python",
"python-3.x"
] |
I need __closure__ | 1,609,716 | <p>I just checked out this very interesting mindmap:</p>
<p><a href="http://www.mindmeister.com/10510492/python-underscore">http://www.mindmeister.com/10510492/python-underscore</a></p>
<p>And I was wondering what some of the new ones mean, like <code>__code__</code> and <code>__closure__</code>. I googled around but... | 7 | 2009-10-22T20:18:19Z | 1,609,743 | <p>These are Python's <a href="http://diveintopython.net/object_oriented_framework/special_class_methods.html" rel="nofollow">special</a> methods.</p>
| 0 | 2009-10-22T20:24:36Z | [
"python",
"python-3.x"
] |
I need __closure__ | 1,609,716 | <p>I just checked out this very interesting mindmap:</p>
<p><a href="http://www.mindmeister.com/10510492/python-underscore">http://www.mindmeister.com/10510492/python-underscore</a></p>
<p>And I was wondering what some of the new ones mean, like <code>__code__</code> and <code>__closure__</code>. I googled around but... | 7 | 2009-10-22T20:18:19Z | 1,609,747 | <p>They used to be called </p>
<pre><code>func_closure (now __closure__), func_code (now __code__)
</code></pre>
<p>(that should help googling).</p>
<p>A short explanation <a href="http://www.python.org/doc/2.6.2/reference/datamodel.html" rel="nofollow">from here</a> below.</p>
<ul>
<li>func_closure: None or a tupl... | 4 | 2009-10-22T20:25:05Z | [
"python",
"python-3.x"
] |
I need __closure__ | 1,609,716 | <p>I just checked out this very interesting mindmap:</p>
<p><a href="http://www.mindmeister.com/10510492/python-underscore">http://www.mindmeister.com/10510492/python-underscore</a></p>
<p>And I was wondering what some of the new ones mean, like <code>__code__</code> and <code>__closure__</code>. I googled around but... | 7 | 2009-10-22T20:18:19Z | 1,609,752 | <p>You actually have analogous fields in CPython 2.x:</p>
<pre><code>>>> first = lambda x: lambda y: x
>>> f = first(2)
>>> type(f.func_code)
<type 'code'>
>>> map(type, f.func_closure)
[<type 'cell'>]
</code></pre>
<p><strong>Edit:</strong> For more details on the mean... | 6 | 2009-10-22T20:26:29Z | [
"python",
"python-3.x"
] |
Python 3 xmlrpc for remote objects | 1,609,749 | <p>I am trying to implement a remote object implementation using xmlrpc, and python 3.
I have tried the example at <a href="http://docs.python.org/3.1/library/xmlrpc.server.html?highlight=xmlrpc#simplexmlrpcserver-example" rel="nofollow">http://docs.python.org/3.1/library/xmlrpc.server.html?highlight=xmlrpc#simplexmlrp... | 0 | 2009-10-22T20:25:37Z | 1,610,349 | <p>Perhaps I'm misunderstanding your question, but... Have you tried running the server code on another machine, and the client code (changing the 'localhost' value in the first line of the client code <code>s = xmlrpc.client.ServerProxy('<a href="http://localhost:8000" rel="nofollow">http://localhost:8000</a>')</code>... | 0 | 2009-10-22T22:27:23Z | [
"python",
"python-3.x",
"remoteobject"
] |
Python 3 xmlrpc for remote objects | 1,609,749 | <p>I am trying to implement a remote object implementation using xmlrpc, and python 3.
I have tried the example at <a href="http://docs.python.org/3.1/library/xmlrpc.server.html?highlight=xmlrpc#simplexmlrpcserver-example" rel="nofollow">http://docs.python.org/3.1/library/xmlrpc.server.html?highlight=xmlrpc#simplexmlrp... | 0 | 2009-10-22T20:25:37Z | 8,414,488 | <p>Update the localhost value to the following:</p>
<p>For the server : <code>s = SimpleXMLRPCServer(("ServerIp", 8000))</code></p>
<p>For the client : <code>s = xmlrpc.client.ServerProxy("http://ServerIp:8000/")</code></p>
| 1 | 2011-12-07T11:21:36Z | [
"python",
"python-3.x",
"remoteobject"
] |
How do I display notifications from `django-notification`? | 1,609,775 | <p>I've been reading the docs for <a href="http://pypi.python.org/pypi/django-notification/0.1.5" rel="nofollow"><code>django-notification</code></a>, and they seem to cover creating notifications just fine, but not how to display them to users. Is there a good reference for this out there, and my Google-fu has just fa... | 5 | 2009-10-22T20:31:19Z | 1,609,800 | <p>Tale a look at <a href="http://pinaxproject.com" rel="nofollow">Pinax</a> the source can be found on github. They use notifications a lot for their project site <a href="http://code.pinaxproject.com" rel="nofollow">http://code.pinaxproject.com</a> .</p>
<p><strong>Edit:</strong><br />
I just gave it a look. It seem... | 1 | 2009-10-22T20:37:43Z | [
"python",
"django",
"django-notification"
] |
How do I display notifications from `django-notification`? | 1,609,775 | <p>I've been reading the docs for <a href="http://pypi.python.org/pypi/django-notification/0.1.5" rel="nofollow"><code>django-notification</code></a>, and they seem to cover creating notifications just fine, but not how to display them to users. Is there a good reference for this out there, and my Google-fu has just fa... | 5 | 2009-10-22T20:31:19Z | 1,953,614 | <p>The answer is you have to build it into your own templates. This can be as simple as the following snippet:</p>
<pre><code><table>
<caption>{% trans "Notices" %}</caption>
<thead>
<tr>
<th>{% trans "Type" %}</th>
<th>{% trans "... | 3 | 2009-12-23T15:58:13Z | [
"python",
"django",
"django-notification"
] |
How to impose a time limit on a whole script in Python | 1,609,869 | <p>The user is entering a python script in a Java GUI python-editor and can run it from the editor. Is there a way to take the user's script and impose a time limit on the total script? </p>
<p>I'm familiar with how to this with functions / signal.alarm(but I'm on windows & unix Jython) but the only solution I hav... | 0 | 2009-10-22T20:49:31Z | 1,610,267 | <p>This is just a guess, but maybe wrap it with Threading or Multiprocessing? Have a timer thread that kills it when it times out. </p>
| 0 | 2009-10-22T22:08:03Z | [
"python",
"time",
"scripting",
"limit"
] |
How to impose a time limit on a whole script in Python | 1,609,869 | <p>The user is entering a python script in a Java GUI python-editor and can run it from the editor. Is there a way to take the user's script and impose a time limit on the total script? </p>
<p>I'm familiar with how to this with functions / signal.alarm(but I'm on windows & unix Jython) but the only solution I hav... | 0 | 2009-10-22T20:49:31Z | 1,610,594 | <p>Use a <a href="http://docs.python.org/library/threading.html?highlight=timer#timer-objects" rel="nofollow">threading.Timer</a> to run a function in a separate thread after a specified delay (the max duration you want for your program), and in that function use <a href="http://docs.python.org/library/thread.html#thre... | 4 | 2009-10-22T23:31:00Z | [
"python",
"time",
"scripting",
"limit"
] |
sqlite3 Operation Error when doing many commits rapidly | 1,610,154 | <p>I get</p>
<pre><code>sqlite3.OperationalError: SQL logic error or missing database
</code></pre>
<p>when I run an application I've been working on. What follows is a narrowed-down but complete sample that exhibits the problem for me. This sample uses two tables; one to store users and one to record whether user ... | 2 | 2009-10-22T21:42:49Z | 1,610,290 | <p>As the "lite" part of the name implies, sqlite3 is meant for light-weight database use, not massive scalable concurrency like some of the Big Boys. Seems to me that what's happening here is that sqlite hasn't finished writing the last change you requested when you make another request</p>
<p>So, some options I see ... | 2 | 2009-10-22T22:12:49Z | [
"python",
"sqlite3"
] |
C# equivalence of python maketrans and translate | 1,610,217 | <p>Hi:
Where could I find code of a C# equivalence of Python maketrans and translate?
Thanks!</p>
| 1 | 2009-10-22T21:58:14Z | 1,610,375 | <p>This should take you most of the way there:</p>
<pre><code>public class MakeTrans
{
private readonly Dictionary<char, char> d;
public MakeTrans(string intab, string outab)
{
d = Enumerable.Range(0, intab.Length).ToDictionary(i => intab[i], i => outab[i]);
//d = new Dictionary... | 0 | 2009-10-22T22:32:41Z | [
"c#",
"python"
] |
How to query a Django model defining a IP range with two int fields (IP, mask) | 1,610,227 | <p>I have:</p>
<pre><code>class Range(models.Model):
ip = models.IntegerField() # as produced by socket.inet_aton + struct.unpack
mask = models.IntegerField()
</code></pre>
<p>Given a certain IP, how can I get all the ranges that match this specific IP using the Django models?</p>
<p>If I were using raw SQL,... | 2 | 2009-10-22T22:00:25Z | 1,610,452 | <p>The QuerySet API in Django 1.0 now includes the 'extra' method, described <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra" rel="nofollow">here</a> in the Django docs. The extra method allows you to pass custom WHERE clauses to your QuerySet, which should allow you to use the bitwise compari... | 4 | 2009-10-22T22:51:10Z | [
"python",
"django",
"django-models"
] |
How to query a Django model defining a IP range with two int fields (IP, mask) | 1,610,227 | <p>I have:</p>
<pre><code>class Range(models.Model):
ip = models.IntegerField() # as produced by socket.inet_aton + struct.unpack
mask = models.IntegerField()
</code></pre>
<p>Given a certain IP, how can I get all the ranges that match this specific IP using the Django models?</p>
<p>If I were using raw SQL,... | 2 | 2009-10-22T22:00:25Z | 1,611,837 | <p>To do faster query fitting the range you'd better store lower and upper IP of range as integer. Then selection of needed objects should be as simple as <code>Range.objects.filter(ip_low__le=ip, ip_up__ge=ip)</code>.</p>
| 2 | 2009-10-23T07:17:09Z | [
"python",
"django",
"django-models"
] |
How to query a Django model defining a IP range with two int fields (IP, mask) | 1,610,227 | <p>I have:</p>
<pre><code>class Range(models.Model):
ip = models.IntegerField() # as produced by socket.inet_aton + struct.unpack
mask = models.IntegerField()
</code></pre>
<p>Given a certain IP, how can I get all the ranges that match this specific IP using the Django models?</p>
<p>If I were using raw SQL,... | 2 | 2009-10-22T22:00:25Z | 4,179,658 | <p>I would recommend using python's iptools :</p>
<p><a href="http://code.google.com/p/python-iptools/" rel="nofollow">http://code.google.com/p/python-iptools/</a></p>
| 0 | 2010-11-14T20:59:57Z | [
"python",
"django",
"django-models"
] |
How do I unindent using IDLE (Python gui) | 1,610,305 | <p>I want to write the following statment in IDLE (Python GUI)</p>
<pre>
>>> if x == 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
</pre>
<p>How can I get the unindention for the elif statment ?</p>
<p>Some additional facts:</p>
<ol>
<li>I tried backspace and shift + tab, that doesn'... | 4 | 2009-10-22T22:18:38Z | 1,610,340 | <p>ctrl+[ should do the trick.</p>
| 14 | 2009-10-22T22:25:08Z | [
"python",
"user-interface"
] |
How do I unindent using IDLE (Python gui) | 1,610,305 | <p>I want to write the following statment in IDLE (Python GUI)</p>
<pre>
>>> if x == 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
</pre>
<p>How can I get the unindention for the elif statment ?</p>
<p>Some additional facts:</p>
<ol>
<li>I tried backspace and shift + tab, that doesn'... | 4 | 2009-10-22T22:18:38Z | 1,610,342 | <p>Try typing it like this. You'll notice the cursor moves to the start of the line after the <code>pass</code></p>
<pre><code>>>> if x == 0:
x = 0
print('Negative changed to zero')
pass
elif x == 0:
print('other stuff')
</code></pre>
| 1 | 2009-10-22T22:25:30Z | [
"python",
"user-interface"
] |
How do I unindent using IDLE (Python gui) | 1,610,305 | <p>I want to write the following statment in IDLE (Python GUI)</p>
<pre>
>>> if x == 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
</pre>
<p>How can I get the unindention for the elif statment ?</p>
<p>Some additional facts:</p>
<ol>
<li>I tried backspace and shift + tab, that doesn'... | 4 | 2009-10-22T22:18:38Z | 1,610,353 | <p>Backspace works for me.</p>
<p>If you go to Options->Configure IDLE and click on the Keys tab, what options are selected? It might make a difference - I have IDLE Classic Windows.</p>
| 1 | 2009-10-22T22:27:52Z | [
"python",
"user-interface"
] |
How do I unindent using IDLE (Python gui) | 1,610,305 | <p>I want to write the following statment in IDLE (Python GUI)</p>
<pre>
>>> if x == 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
</pre>
<p>How can I get the unindention for the elif statment ?</p>
<p>Some additional facts:</p>
<ol>
<li>I tried backspace and shift + tab, that doesn'... | 4 | 2009-10-22T22:18:38Z | 1,610,619 | <p>If, as you say, you're on Windows, you ought to check out the interactive IDE that comes with Mark Hammond's <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow"><code>PyWin32</code></a>. It's available for all versions of Python including 2.6 and 3.1</p>
<p>It has user settable syntax coloring, code ... | 0 | 2009-10-22T23:38:20Z | [
"python",
"user-interface"
] |
How do I unindent using IDLE (Python gui) | 1,610,305 | <p>I want to write the following statment in IDLE (Python GUI)</p>
<pre>
>>> if x == 0:
... x = 0
... print('Negative changed to zero')
... elif x == 0:
</pre>
<p>How can I get the unindention for the elif statment ?</p>
<p>Some additional facts:</p>
<ol>
<li>I tried backspace and shift + tab, that doesn'... | 4 | 2009-10-22T22:18:38Z | 35,314,626 | <p><code>ctrl + [</code> in Windows</p>
<p><code>command + [</code> in Mac</p>
| 1 | 2016-02-10T11:58:25Z | [
"python",
"user-interface"
] |
confused __iter__ | 1,610,371 | <p>i am a reading the chapter on operator over flow and am very confused how <code>__iter__</code> works. I have gone to several websites to find different examples but still dont quite understand how it works. I am wondering if someone has a really simple approach to on how to understand this function. Main problem... | 15 | 2009-10-22T22:30:55Z | 1,610,418 | <p>A class supporting the __iter__ method will return an iterator object instance: an object supporting the <em>next()</em> method. This object will be usuable in the statements "for" and "in".</p>
| 2 | 2009-10-22T22:43:18Z | [
"python",
"iterator"
] |
confused __iter__ | 1,610,371 | <p>i am a reading the chapter on operator over flow and am very confused how <code>__iter__</code> works. I have gone to several websites to find different examples but still dont quite understand how it works. I am wondering if someone has a really simple approach to on how to understand this function. Main problem... | 15 | 2009-10-22T22:30:55Z | 1,610,437 | <p>As simply as I can put it:</p>
<p><code>__iter__</code> defines a method on a class which will return an iterator (an object that successively yields the next item contained by your object).</p>
<p>The iterator object that <code>__iter__()</code> returns can be pretty much any object, as long as it defines a <code... | 19 | 2009-10-22T22:47:28Z | [
"python",
"iterator"
] |
confused __iter__ | 1,610,371 | <p>i am a reading the chapter on operator over flow and am very confused how <code>__iter__</code> works. I have gone to several websites to find different examples but still dont quite understand how it works. I am wondering if someone has a really simple approach to on how to understand this function. Main problem... | 15 | 2009-10-22T22:30:55Z | 1,610,503 | <p>In Python, an iterator is any object that supports the iterator protocol. Part of that protocol is that the object must have an <code>__iter__()</code> method that returns the iterator object. I suppose this gives you some flexibility so that an object can pass on the iterator responsibilities to an internal class, ... | 2 | 2009-10-22T23:02:00Z | [
"python",
"iterator"
] |
confused __iter__ | 1,610,371 | <p>i am a reading the chapter on operator over flow and am very confused how <code>__iter__</code> works. I have gone to several websites to find different examples but still dont quite understand how it works. I am wondering if someone has a really simple approach to on how to understand this function. Main problem... | 15 | 2009-10-22T22:30:55Z | 1,610,557 | <p>The specs for <code>def __iter__(self):</code> are: it returns an iterator. So, if <code>self</code> is an iterator, <code>return self</code> is clearly appropriate.</p>
<p>"Being an iterator" means "having a <code>__next__(self)</code> method" (in Python 3; in Python 2, the name of the method in question is unfor... | 4 | 2009-10-22T23:18:27Z | [
"python",
"iterator"
] |
confused __iter__ | 1,610,371 | <p>i am a reading the chapter on operator over flow and am very confused how <code>__iter__</code> works. I have gone to several websites to find different examples but still dont quite understand how it works. I am wondering if someone has a really simple approach to on how to understand this function. Main problem... | 15 | 2009-10-22T22:30:55Z | 1,610,583 | <p>An iterator need only define one method*: <code>next()</code> (<code>__next__()</code> in python3), but for an object to be iterable, it must provide an <code>__iter__()</code> method which returns the iterator object. Usually, the object itself defines the <code>next()</code> method, so it just returns itself as th... | 4 | 2009-10-22T23:26:43Z | [
"python",
"iterator"
] |
Kill the process using its name inside linux (Python) | 1,610,609 | <p>this works, but it kills every Python process.</p>
<pre><code>pkill python
</code></pre>
<p>However, I cannot do:</p>
<pre><code>pkill myscript.py
</code></pre>
<p>I have also tried <em>killall</em>, but with no luck either.
Do I have to user regular expressions?</p>
<p>By the way, I want to do this in a python... | 7 | 2009-10-22T23:34:50Z | 1,610,623 | <p>you need to lookup the process id (pid). You can use the command "ps -A | grep NAME" and then apply "kill -9 PID". These commands can easily be translated to python.</p>
<p>Trying to use a "name" (as in pkill) can yield multiple matches and thus unexpected results (at least in the context set above in the question... | 0 | 2009-10-22T23:39:17Z | [
"python",
"linux",
"unix",
"process"
] |
Kill the process using its name inside linux (Python) | 1,610,609 | <p>this works, but it kills every Python process.</p>
<pre><code>pkill python
</code></pre>
<p>However, I cannot do:</p>
<pre><code>pkill myscript.py
</code></pre>
<p>I have also tried <em>killall</em>, but with no luck either.
Do I have to user regular expressions?</p>
<p>By the way, I want to do this in a python... | 7 | 2009-10-22T23:34:50Z | 1,610,628 | <p>Are you able to have the process write it's <code>pid</code> to a file?<br />
In Python you get the pid like this:</p>
<pre><code>import os
os.getpid()
</code></pre>
<p>Killing by name is convenient, but sometimes has undesired consequences as you have seen.</p>
| 2 | 2009-10-22T23:40:17Z | [
"python",
"linux",
"unix",
"process"
] |
Kill the process using its name inside linux (Python) | 1,610,609 | <p>this works, but it kills every Python process.</p>
<pre><code>pkill python
</code></pre>
<p>However, I cannot do:</p>
<pre><code>pkill myscript.py
</code></pre>
<p>I have also tried <em>killall</em>, but with no luck either.
Do I have to user regular expressions?</p>
<p>By the way, I want to do this in a python... | 7 | 2009-10-22T23:34:50Z | 1,610,660 | <p>Did you launch the Python subprocess from the same script you are killing it from? If so, see <a href="http://stackoverflow.com/questions/951980/killing-process-in-shell-script">this question</a> for details. If not, you can use <code>pkill</code>'s -f option to search for the script name in the Python process's ar... | 4 | 2009-10-22T23:46:22Z | [
"python",
"linux",
"unix",
"process"
] |
Kill the process using its name inside linux (Python) | 1,610,609 | <p>this works, but it kills every Python process.</p>
<pre><code>pkill python
</code></pre>
<p>However, I cannot do:</p>
<pre><code>pkill myscript.py
</code></pre>
<p>I have also tried <em>killall</em>, but with no luck either.
Do I have to user regular expressions?</p>
<p>By the way, I want to do this in a python... | 7 | 2009-10-22T23:34:50Z | 1,610,706 | <p>Try this:</p>
<pre><code>echo '#!/usr/bin/env python' > myscript
cat myscript.py >>myscript
chmod +x myscript
./myscript
</code></pre>
<p>Of course you will have to change the code to kill a process named "myscript"
On UNIX systems, an executable file contains a few bytes at the beginning which tell the O... | -1 | 2009-10-23T00:00:58Z | [
"python",
"linux",
"unix",
"process"
] |
Kill the process using its name inside linux (Python) | 1,610,609 | <p>this works, but it kills every Python process.</p>
<pre><code>pkill python
</code></pre>
<p>However, I cannot do:</p>
<pre><code>pkill myscript.py
</code></pre>
<p>I have also tried <em>killall</em>, but with no luck either.
Do I have to user regular expressions?</p>
<p>By the way, I want to do this in a python... | 7 | 2009-10-22T23:34:50Z | 36,828,895 | <p><code>sudo kill -9 `pgrep python`</code></p>
<p>This command will kill all the running python processes</p>
| 1 | 2016-04-24T21:06:52Z | [
"python",
"linux",
"unix",
"process"
] |
AppEngine: Will the items stored in a StringListProperty always remain in the same order? | 1,610,687 | <p>After looking through the docs on App Engine and the <code>StringListProperty</code> or the <code>ListProperty</code> I can't seem to find whether there is a guarantee on the order of the items in the list. That is, I'd like to be certain that the list order stays the same despite putting and getting from the DataSt... | 2 | 2009-10-22T23:56:14Z | 1,610,723 | <p>I can't find it explicitly said in the documentation, but according to a <a href="http://www.youtube.com/watch?v=AgaL6NGpkB8" rel="nofollow">Google I/O talk about the DataStore</a>, StringListProperty will be sorted the same way you put it there.</p>
| 2 | 2009-10-23T00:05:54Z | [
"python",
"google-app-engine"
] |
AppEngine: Will the items stored in a StringListProperty always remain in the same order? | 1,610,687 | <p>After looking through the docs on App Engine and the <code>StringListProperty</code> or the <code>ListProperty</code> I can't seem to find whether there is a guarantee on the order of the items in the list. That is, I'd like to be certain that the list order stays the same despite putting and getting from the DataSt... | 2 | 2009-10-22T23:56:14Z | 1,611,204 | <p>Yep, per <a href="http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#Lists" rel="nofollow">the docs</a>, </p>
<blockquote>
<p>Order is preserved, so when entities
are returned by queries and get(),
list properties will have values in
the same order as when they were
stored.</p>
... | 3 | 2009-10-23T03:11:10Z | [
"python",
"google-app-engine"
] |
python lotus notes: odbc connect error | 1,610,781 | <p>I am developing a client server application for a cross-database system.</p>
<p>I am using Eclipse IDE with Python 2.5 and PyODBC2.5; need to read content from a Lotus Notes database, so run some basic query like - SELECT peronname FROM tablename.</p>
<p>'import pyodbc' is ok - python see it!</p>
<p>But when I tr... | 0 | 2009-10-23T00:23:29Z | 1,979,540 | <p>I think it's odd that you want to try accessing Lotus Notes data vie SQL. When I have interfaced Notes and Python in the past, I always used the Lotus Note COM object to access data. After all, Notes is a document database like CouchDB, not a relational database.</p>
| 0 | 2009-12-30T10:45:48Z | [
"python",
"odbc",
"lotus-notes",
"connect",
"lotus"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.