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 |
|---|---|---|---|---|---|---|---|---|---|
Python value unpacking error | 1,144,953 | <p>I'm building a per-user file browsing/uploading application using Django and when I run this function</p>
<pre><code>
def walkdeep(request, path):
path, dirs, files = walktoo('/home/damon/walktemp/%s' % path)
return render_to_response('walk.html', {
'path' : path[0],
'dirs' : path[1],
... | 0 | 2009-07-17T18:31:32Z | 1,144,987 | <pre><code>path, dirs, files = walktoo('/home/damon/walktemp/%s' % path)
</code></pre>
<p>In this line, you're expecting <code>walktoo</code> to return a tuple of three values, which are then to be unpacked into <code>path</code>, <code>dirs</code>, and <code>files</code>. However, your <code>walktoo</code> function ... | 7 | 2009-07-17T18:38:19Z | [
"python",
"django"
] |
Python value unpacking error | 1,144,953 | <p>I'm building a per-user file browsing/uploading application using Django and when I run this function</p>
<pre><code>
def walkdeep(request, path):
path, dirs, files = walktoo('/home/damon/walktemp/%s' % path)
return render_to_response('walk.html', {
'path' : path[0],
'dirs' : path[1],
... | 0 | 2009-07-17T18:31:32Z | 1,145,235 | <p>Based on your comment to <a href="http://stackoverflow.com/users/9530/adam-rosenfield">Adam Rosenfield</a>, this is another approach to get one layer of os.walk(dir).</p>
<pre><code>path, dirs, files = [_ for _ in os.walk('/home/damon/walktemp/%s' % path)][0]
</code></pre>
<p>This is as an alternative to your walk... | 1 | 2009-07-17T19:33:00Z | [
"python",
"django"
] |
XML parsing expat in python handling data | 1,145,015 | <p>I am attempting to parse an XML file using python expat. I have the following line in my XML file:</p>
<pre><code><Action>&lt;fail/&gt;</Action>
</code></pre>
<p>expat identifies the start and end tags but converts the & lt; to the less than character and the same for the greater than chara... | 0 | 2009-07-17T18:44:04Z | 1,145,032 | <p>expat does not mess up, <code>&lt;</code> is simply the XML encoding for the character <code><</code>. Quite to the contrary, if expat would return the literal <code>&lt;</code>, this would be a bug with respect to the XML spec. That being said, you can of course get the escaped version back by using <cod... | 2 | 2009-07-17T18:49:20Z | [
"python",
"xml",
"parsing",
"expat-parser"
] |
XML parsing expat in python handling data | 1,145,015 | <p>I am attempting to parse an XML file using python expat. I have the following line in my XML file:</p>
<pre><code><Action>&lt;fail/&gt;</Action>
</code></pre>
<p>expat identifies the start and end tags but converts the & lt; to the less than character and the same for the greater than chara... | 0 | 2009-07-17T18:44:04Z | 1,145,808 | <p>Both SAX and StAX parsers are free to break up the strings in whatever way is convenient for them (although StAX has a COALESCE mode for forcing it to assemble the pieces for you).</p>
<p>The reason is that it is often possible to write software in certain cases that streams and doesn't have to care about the overh... | 0 | 2009-07-17T21:37:28Z | [
"python",
"xml",
"parsing",
"expat-parser"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,145,329 | <p>I'm pretty sure there is, as I've even been able to edit/read from the source files of scripts I've run, but the biggest problem would probably be all the shifting that would be done if you started at the beginning of the file. On the other hand, if you go through the file and record all the starting positions of th... | 1 | 2009-07-17T19:51:14Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,145,338 | <p>If you're on Linux/Unix, why not use the split command like <a href="http://www.techiecorner.com/107/how-to-split-large-file-into-several-smaller-files-linux/" rel="nofollow">this guy</a> does?</p>
<pre><code>split --bytes=100m /input/file /output/dir/prefix
</code></pre>
<p>EDIT: then use <a href="http://linux.di... | 2 | 2009-07-17T19:53:04Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,145,341 | <p>If time is not a major factor (or wear and tear on your disk drive):</p>
<ol>
<li>Open handle to file</li>
<li>Read up to the size of your partition / logical break point (due to the xml)</li>
<li>Save the rest of your file to disk (not sure how python handles this as far as directly overwriting file or memory usag... | 0 | 2009-07-17T19:53:35Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,145,417 | <p>You could always parse the XML file and write out say every 10000 elements to there own file. Look at the Incremental Parsing section of this link.
<a href="http://effbot.org/zone/element-iterparse.htm" rel="nofollow">http://effbot.org/zone/element-iterparse.htm</a></p>
| 0 | 2009-07-17T20:06:57Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,145,434 | <p>Say you want to split the file into N pieces, then simply start reading from the back of the file (more or less) and repeatedly call <a href="http://docs.python.org/library/stdtypes.html?highlight=truncate#file.truncate" rel="nofollow">truncate</a>:</p>
<blockquote>
<p>Truncate the file's size. If the optional si... | 7 | 2009-07-17T20:11:07Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,148,604 | <p>Its a time to buy a new hard drive!</p>
<p>You can make backup before trying all other answers and don't get data lost :)</p>
| -1 | 2009-07-18T21:25:10Z | [
"python",
"file"
] |
Change python file in place | 1,145,286 | <p>I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files?</p>
<p>Thanks!</p>
| 8 | 2009-07-17T19:41:37Z | 1,154,128 | <p>Here is my script...</p>
<pre><code>import string
import os
from ftplib import FTP
# make ftp connection
ftp = FTP('server')
ftp.login('user', 'pwd')
ftp.cwd('/dir')
f1 = open('large_file.xml', 'r')
size = 0
split = False
count = 0
for line in f1:
if not split:
file = 'split_'+str(count)+'.xml'
f2 = o... | 0 | 2009-07-20T15:07:04Z | [
"python",
"file"
] |
Using URLS that accept slashes as part of the parameter in Django | 1,145,334 | <p>Is there a way in Django to accept 'n' parameters which are delimited by a '/' (forward slash)?</p>
<p>I was thinking this may work, but it does not. Django still recognizes forward slashes as delimiters.</p>
<pre><code>(r'^(?P<path>[-\w]+/)$', 'some.view', {}),
</code></pre>
| 0 | 2009-07-17T19:52:05Z | 1,145,393 | <p>Certainly, Django can accept any URL which can be described by a regular expression - including one which has a prefix followed by a '/' followed by a variable number of segments separated by '/'. The exact regular expression will depend on what you want to accept - but an example in Django is given by /admin URLs w... | 1 | 2009-07-17T20:02:04Z | [
"python",
"django"
] |
Using URLS that accept slashes as part of the parameter in Django | 1,145,334 | <p>Is there a way in Django to accept 'n' parameters which are delimited by a '/' (forward slash)?</p>
<p>I was thinking this may work, but it does not. Django still recognizes forward slashes as delimiters.</p>
<pre><code>(r'^(?P<path>[-\w]+/)$', 'some.view', {}),
</code></pre>
| 0 | 2009-07-17T19:52:05Z | 1,145,418 | <p>Add the right url to your urlpatterns:</p>
<pre><code># ...
("^foo/(.*)$", "foo"), # or whatever
# ...
</code></pre>
<p>And process it in your view, like AlbertoPL said:</p>
<pre><code>fields = paramPassedInAccordingToThatUrl.split('/')
</code></pre>
| 4 | 2009-07-17T20:06:59Z | [
"python",
"django"
] |
Difference between "inspect" and "interactive" command line flags in Python | 1,145,428 | <p>What is the difference between "inspect" and "interactive" flags?
The <a href="http://docs.python.org/library/sys.html#sys.flags" rel="nofollow">sys.flags function</a> prints both of them.</p>
<p>How can they both have "-i" flag according to the documentation of sys.flags?</p>
<p>How can I set them separately? If ... | 4 | 2009-07-17T20:09:49Z | 1,145,452 | <p><code>man python</code> says about the <code>-i</code> flag:</p>
<blockquote>
<p>When a script is passed as first
argument or the -c option is used,
enter interactive mode after executing
the script or the command. It does
not read the $PYTHONSTARTUP file.
This can be useful to inspect global
... | 0 | 2009-07-17T20:14:52Z | [
"python",
"command-line",
"interpreter"
] |
Difference between "inspect" and "interactive" command line flags in Python | 1,145,428 | <p>What is the difference between "inspect" and "interactive" flags?
The <a href="http://docs.python.org/library/sys.html#sys.flags" rel="nofollow">sys.flags function</a> prints both of them.</p>
<p>How can they both have "-i" flag according to the documentation of sys.flags?</p>
<p>How can I set them separately? If ... | 4 | 2009-07-17T20:09:49Z | 1,145,777 | <p>According to <a href="http://svn.python.org/view/python/trunk/Python/pythonrun.c?view=markup" rel="nofollow">pythonrun.c</a> corresponding <code>Py_InspectFlag</code> and <code>Py_InteractiveFlag</code> are used as follows:</p>
<pre class="lang-c prettyprint-override"><code>int Py_InspectFlag; /* Needed to determ... | 7 | 2009-07-17T21:28:21Z | [
"python",
"command-line",
"interpreter"
] |
How to make easy_install expand a package into directories rather than a single egg file? | 1,145,524 | <p>How exactly do I configure my setup.py file so that when someone runs easy_install the package gets expanded into \site-packages\ as a directory, rather than remaining inside an egg.</p>
<p>The issue I'm encountering is that one of the django apps I've created won't auto-detect if it resides inside an egg.</p>
<p>... | 3 | 2009-07-17T20:29:04Z | 1,145,611 | <p>You add <code>zip_safe = False</code> as an option to setup().</p>
<p>I don't think it has to do with directories. Setuptools will happily eggify packages with loads of directories in it.</p>
<p>Then of course it's another problem that this part of Django doesn't find the package even though it's zipped. It should... | 5 | 2009-07-17T20:46:35Z | [
"python",
"django",
"setuptools",
"easy-install",
"egg"
] |
Connection refused when trying to open, write and close a socket a few times (Python) | 1,145,540 | <p>I have a program that listens on a port waiting for a small amount of data to tell it what to do. I run 5 instances of that program, one on each port from 5000 to 5004 inclusively.</p>
<p>I have a second program written in Python that creates a socket "s", writes the data to port 5000, then closes. It then incremen... | 2 | 2009-07-17T20:32:47Z | 1,146,653 | <p>This sounds a lot like the anti-portscan measure of your firewall kicking in.</p>
| 1 | 2009-07-18T03:40:15Z | [
"python",
"sockets",
"limit",
"max"
] |
Connection refused when trying to open, write and close a socket a few times (Python) | 1,145,540 | <p>I have a program that listens on a port waiting for a small amount of data to tell it what to do. I run 5 instances of that program, one on each port from 5000 to 5004 inclusively.</p>
<p>I have a second program written in Python that creates a socket "s", writes the data to port 5000, then closes. It then incremen... | 2 | 2009-07-17T20:32:47Z | 1,147,701 | <p>I don't know that much about sockets, so this may be really bad style... use at own risk. This code:</p>
<pre><code>#!/usr/bin/python
import threading, time
from socket import *
portrange = range(10000,10005)
class Sock(threading.Thread):
def __init__(self, port):
self.port = port
threading.Thr... | 1 | 2009-07-18T14:38:43Z | [
"python",
"sockets",
"limit",
"max"
] |
Connection refused when trying to open, write and close a socket a few times (Python) | 1,145,540 | <p>I have a program that listens on a port waiting for a small amount of data to tell it what to do. I run 5 instances of that program, one on each port from 5000 to 5004 inclusively.</p>
<p>I have a second program written in Python that creates a socket "s", writes the data to port 5000, then closes. It then incremen... | 2 | 2009-07-17T20:32:47Z | 1,147,733 | <p>Are you running the 2nd Python program from within Idle? If so - try it outside of Idle and see if the results are any different.</p>
| 0 | 2009-07-18T14:53:34Z | [
"python",
"sockets",
"limit",
"max"
] |
py2exe: Compiled Python Windows Application won't run because of DLL | 1,145,662 | <p>I will confess I'm very new to Python and I don't really know what I'm doing yet. Recently I created a very small Windows application using Python 2.6.2 and wxPython 2.8. And it works great; I'm quite pleased with how well it works normally. By normally I mean when I invoke it directly through the Python interpreter... | 6 | 2009-07-17T21:01:13Z | 1,145,698 | <p>I believe installing <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en" rel="nofollow">Microsoft C++ Redistributable Package</a> will install the DLL you need correctly.</p>
| 2 | 2009-07-17T21:09:43Z | [
"python",
"wxpython",
"py2exe"
] |
py2exe: Compiled Python Windows Application won't run because of DLL | 1,145,662 | <p>I will confess I'm very new to Python and I don't really know what I'm doing yet. Recently I created a very small Windows application using Python 2.6.2 and wxPython 2.8. And it works great; I'm quite pleased with how well it works normally. By normally I mean when I invoke it directly through the Python interpreter... | 6 | 2009-07-17T21:01:13Z | 1,145,725 | <p>You can't just copy msvcr*.dll - they need to be set up using the rules for side-by-side assemblies. You can do this by installing the redistributable package as Sam points out, or you can put them alongside your executables as long as you obey the rules.</p>
<p>See the section "Deploying Visual C++ library DLLs a... | 8 | 2009-07-17T21:14:48Z | [
"python",
"wxpython",
"py2exe"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,735 | <p>Negative, no pointers. You should not need them with the way the language is designed. However, I heard a nasty rumor that you could use the: <a href="http://starship.python.net/crew/theller/ctypes/" rel="nofollow">ctypes</a> module to use them. I haven't used it, but it smells messy to me.</p>
| 0 | 2009-07-17T21:17:29Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,747 | <p>You may want to read <a href="http://rg03.wordpress.com/2007/04/21/semantics-of-python-variable-names-from-a-c-perspective/"><em>Semantics of Python variable names from a C++ perspective</em></a>. The bottom line: <strong>All variables are references</strong>.</p>
<p>More to the point, don't think in terms of varia... | 19 | 2009-07-17T21:20:22Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,769 | <p>Everything in Python is pointers already, but it's called "references" in Python. This is the translation of your code to Python:</p>
<pre><code>a = [1,2] // a has an array
b = a // b points to a
a = 2 // store 2 in a.
print(a) // outputs 2
print(b) // outputs [1,2]
</code></pre>
<p>"Dereferencing" m... | 3 | 2009-07-17T21:24:41Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,826 | <p>As others here have said, all Python variables are essentially pointers.</p>
<p>The key to understanding this from a C perspective is to use the unknown by many id() function. It tells you what address the variable points to.</p>
<pre><code>>>> a = [1,2]
>>> id(a)
28354600
>>> b = a
>... | 4 | 2009-07-17T21:43:05Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,848 | <p>This can be done explicitly.</p>
<pre><code>class ref:
def __init__(self, obj): self.obj = obj
def get(self): return self.obj
def set(self, obj): self.obj = obj
a = ref([1, 2])
b = a
print a.get() # => [1, 2]
print b.get() # => [1, 2]
b.set(2)
print a.get() # => 2
print b.get() # ... | 66 | 2009-07-17T21:49:07Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,862 | <p>This is goofy, but a thought...</p>
<pre><code># Change operations like:
b = &a
# To:
b = "a"
# And change operations like:
*b = 2
# To:
locals()[b] = 2
>>> a = [1,2]
>>> b = "a"
>>> locals()[b] = 2
>>> print(a)
2
>>> print(locals()[b])
2
</code></pre>
<p>But t... | 1 | 2009-07-17T21:53:20Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 1,145,884 | <p>If you're compiling a C-like language, say:</p>
<pre><code>func()
{
var a = 1;
var *b = &a;
*b = 2;
assert(a == 2);
}
</code></pre>
<p>into Python, then all of the "everything in Python is a reference" stuff is a misnomer.</p>
<p>It's true that everything in Python is a reference, but the fact... | 11 | 2009-07-17T22:01:56Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 14,000,962 | <p>Almost exactly like <a href="http://stackoverflow.com/users/20713/ephemient">ephemient</a> <a href="http://stackoverflow.com/a/1145848/1020470">answer</a>, which I voted up, you could use Python's builtin <a href="http://docs.python.org/2/library/functions.html#property" rel="nofollow">property</a> function. It will... | 7 | 2012-12-22T07:32:38Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 26,989,738 | <pre><code>class Pointer(object):
def __init__(self, target=None):
self.target = target
_noarg = object()
def __call__(self, target=_noarg):
if target is not self._noarg:
self.target = target
return self.target
</code></pre>
<pre><code>a = Pointer([1, 2])
b = a
prin... | 0 | 2014-11-18T08:28:52Z | [
"python",
"pointers"
] |
Simulating Pointers in Python | 1,145,722 | <p>I'm trying to cross compile an in house language(ihl) to Python.</p>
<p>One of the ihl features is pointers and references that behave like you would expect from C or C++.</p>
<p>For instance you can do this:</p>
<pre><code>a = [1,2]; // a has an array
b = &a; // b points to a
*b = 2; // derefernce ... | 42 | 2009-07-17T21:13:59Z | 31,242,714 | <p>I think that this example is short and clear. </p>
<p>Here we have class with implicit list:</p>
<pre><code>class A:
foo = []
a, b = A(), A()
a.foo.append(5)
b.foo
ans: [5]
</code></pre>
<p>Looking at this memory profile (using: <code>from memory_profiler import profile</code>), my intuition tells me that thi... | 0 | 2015-07-06T09:52:19Z | [
"python",
"pointers"
] |
MPI signal handling | 1,145,741 | <p>When using <code>mpirun</code>, is it possible to catch signals (for example, the SIGINT generated by <code>^C</code>) in the code being run?</p>
<p>For example, I'm running a parallelized python code. I can <code>except KeyboardInterrupt</code> to catch those errors when running <code>python blah.py</code> by itse... | 3 | 2009-07-17T21:18:05Z | 1,145,984 | <p>The <a href="http://docs.python.org/library/signal.html#module-signal" rel="nofollow">signal</a> module supports setting signal handlers using <code>signal.signal</code>:</p>
<blockquote>
<p>Set the handler for signal signalnum to the function handler. handler can be a callable Python object taking two arguments ... | 0 | 2009-07-17T22:37:22Z | [
"python",
"signals",
"mpi"
] |
MPI signal handling | 1,145,741 | <p>When using <code>mpirun</code>, is it possible to catch signals (for example, the SIGINT generated by <code>^C</code>) in the code being run?</p>
<p>For example, I'm running a parallelized python code. I can <code>except KeyboardInterrupt</code> to catch those errors when running <code>python blah.py</code> by itse... | 3 | 2009-07-17T21:18:05Z | 1,149,142 | <p>If you use <code>mpirun --nw</code>, then <code>mpirun</code> itself should terminate as soon as it's started the subprocesses, instead of waiting for their termination; if that's acceptable then I believe your processes would be able to catch their own signals.</p>
| 0 | 2009-07-19T03:08:53Z | [
"python",
"signals",
"mpi"
] |
Trying to import a module that imports another module, getting ImportError | 1,145,794 | <p>In ajax.py, I have this import statement:</p>
<pre><code>import components.db_init as db
</code></pre>
<p>In components/db_init.py, I have this import statement:</p>
<pre><code># import locals from ORM (Storm)
from storm.locals import *
</code></pre>
<p>And in components/storm/locals.py, it has this:</p>
<pre><... | 0 | 2009-07-17T21:33:07Z | 1,145,820 | <p>I would guess that <code>storm.locals</code>' idea of its package name is different from what you think it is (most likely it thinks it's in <code>components.storm.locals</code>). You can check this by printing <code>__name__</code> at the top of <code>storm.locals</code>, I believe. If you use imports which aren't ... | 2 | 2009-07-17T21:41:32Z | [
"python",
"import",
"packages",
"relative-path"
] |
Trying to import a module that imports another module, getting ImportError | 1,145,794 | <p>In ajax.py, I have this import statement:</p>
<pre><code>import components.db_init as db
</code></pre>
<p>In components/db_init.py, I have this import statement:</p>
<pre><code># import locals from ORM (Storm)
from storm.locals import *
</code></pre>
<p>And in components/storm/locals.py, it has this:</p>
<pre><... | 0 | 2009-07-17T21:33:07Z | 1,145,834 | <p>You either need to </p>
<ul>
<li>add (...)/components/storm to
PYTHONPATH,</li>
<li>use relative imports
in components/storm/locals.py or </li>
<li>import properties instead of storm.properties</li>
</ul>
| 1 | 2009-07-17T21:44:38Z | [
"python",
"import",
"packages",
"relative-path"
] |
SQLAlchemy: Scan huge tables using ORM? | 1,145,905 | <p>I am currently playing around with SQLAlchemy a bit, which is really quite neat.</p>
<p>For testing I created a huge table containing my pictures archive, indexed by SHA1 hashes (to remove duplicates :-)). Which was impressingly fast...</p>
<p>For fun I did the equivalent of a <code>select *</code> over the result... | 26 | 2009-07-17T22:07:02Z | 1,145,941 | <p>Okay, I just found a way to do this myself. Changing the code to</p>
<pre><code>session = Session()
for p in session.query(Picture).yield_per(5):
print(p)
</code></pre>
<p>loads only 5 pictures at a time. It seems like the query will load all rows at a time by default. However, I don't yet understand the discl... | 36 | 2009-07-17T22:23:39Z | [
"python",
"performance",
"orm",
"sqlalchemy"
] |
SQLAlchemy: Scan huge tables using ORM? | 1,145,905 | <p>I am currently playing around with SQLAlchemy a bit, which is really quite neat.</p>
<p>For testing I created a huge table containing my pictures archive, indexed by SHA1 hashes (to remove duplicates :-)). Which was impressingly fast...</p>
<p>For fun I did the equivalent of a <code>select *</code> over the result... | 26 | 2009-07-17T22:07:02Z | 1,146,078 | <p>You can defer the picture to only retrieve on access. You can do it on a query by query basis.
like</p>
<pre><code>session = Session()
for p in session.query(Picture).options(sqlalchemy.orm.defer("picture")):
print(p)
</code></pre>
<p>or you can do it in the mapper </p>
<pre><code>mapper(Picture, pictures, p... | 6 | 2009-07-17T23:06:52Z | [
"python",
"performance",
"orm",
"sqlalchemy"
] |
SQLAlchemy: Scan huge tables using ORM? | 1,145,905 | <p>I am currently playing around with SQLAlchemy a bit, which is really quite neat.</p>
<p>For testing I created a huge table containing my pictures archive, indexed by SHA1 hashes (to remove duplicates :-)). Which was impressingly fast...</p>
<p>For fun I did the equivalent of a <code>select *</code> over the result... | 26 | 2009-07-17T22:07:02Z | 1,217,947 | <p>here's what I usually do for this situation:</p>
<pre><code>def page_query(q):
offset = 0
while True:
r = False
for elem in q.limit(1000).offset(offset):
r = True
yield elem
offset += 1000
if not r:
break
for item in page_query(Session.query... | 21 | 2009-08-02T01:28:45Z | [
"python",
"performance",
"orm",
"sqlalchemy"
] |
How to override Py_GetPrefix(), Py_GetPath()? | 1,145,932 | <p>I'm trying to embed the Python interpreter and need to customize the way the Python standard library is loaded. Our library will be loaded from the same directory as the executable, not from prefix/lib/.</p>
<p>We have been successful in making this work by manually modifying sys.path after calling Py_Initialize(),... | 4 | 2009-07-17T22:18:26Z | 1,146,134 | <p>Have you considered using <code>putenv</code> to adjust <code>PYTHONPATH</code> before calling Py_Initialize?</p>
| 2 | 2009-07-17T23:30:02Z | [
"c++",
"python",
"api"
] |
How to override Py_GetPrefix(), Py_GetPath()? | 1,145,932 | <p>I'm trying to embed the Python interpreter and need to customize the way the Python standard library is loaded. Our library will be loaded from the same directory as the executable, not from prefix/lib/.</p>
<p>We have been successful in making this work by manually modifying sys.path after calling Py_Initialize(),... | 4 | 2009-07-17T22:18:26Z | 1,146,654 | <p>You could set <code>Py_NoSiteFlag = 1</code>, call <code>PyInitialize</code> and import site.py yourself as needed.</p>
| 4 | 2009-07-18T03:41:44Z | [
"c++",
"python",
"api"
] |
How to override Py_GetPrefix(), Py_GetPath()? | 1,145,932 | <p>I'm trying to embed the Python interpreter and need to customize the way the Python standard library is loaded. Our library will be loaded from the same directory as the executable, not from prefix/lib/.</p>
<p>We have been successful in making this work by manually modifying sys.path after calling Py_Initialize(),... | 4 | 2009-07-17T22:18:26Z | 4,229,240 | <p>I see it was asked long ago, but I've just hit the same problem. <code>Py_NoSiteFlag</code> will help with the site module, but generally it's better to rewrite <code>Modules/getpath.c</code>; Python docs <a href="http://docs.python.org/c-api/intro.html#embedding-python" rel="nofollow">officially recommend</a> this ... | 3 | 2010-11-19T20:49:32Z | [
"c++",
"python",
"api"
] |
how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url | 1,145,955 | <p>Say I have the following set of urls in a db</p>
<pre><code>url data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more
</code></pre>
<p>Given any url in the wild, I would like to check to
see if that url belongs to an existing set of ... | 1 | 2009-07-17T22:27:49Z | 1,146,002 | <p>Django has the advantage that its URLs are generally hierarchical. While the entire Django project may well have 100s or more URLs it's probably dealing only with a dozen or less patterns at a time. Do you have any structure in your URLs that you could exploit this way?</p>
<p>Other than that, you could try creatin... | 0 | 2009-07-17T22:40:58Z | [
"python",
"regex",
"url-routing"
] |
how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url | 1,145,955 | <p>Say I have the following set of urls in a db</p>
<pre><code>url data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more
</code></pre>
<p>Given any url in the wild, I would like to check to
see if that url belongs to an existing set of ... | 1 | 2009-07-17T22:27:49Z | 1,146,061 | <p>Before determining that the django approach could not possibly work, try implementing it, and applying a typical workload. For a really thourough approach, you could actually time the cost of each regex and that can guide you in improving the most costly and most frequently used regexes. In particular, you could a... | 0 | 2009-07-17T22:59:39Z | [
"python",
"regex",
"url-routing"
] |
how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url | 1,145,955 | <p>Say I have the following set of urls in a db</p>
<pre><code>url data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more
</code></pre>
<p>Given any url in the wild, I would like to check to
see if that url belongs to an existing set of ... | 1 | 2009-07-17T22:27:49Z | 1,147,370 | <p>You'll certainly need more care in your design of regular expressions. For example, the prefix <code>^(.*)</code> will match any input - and while you may need the prefix to capture a group for various reasons, having it there will mean that you can't really eliminate any of the URLs in your database easily. </p>
<... | 0 | 2009-07-18T12:04:34Z | [
"python",
"regex",
"url-routing"
] |
how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url | 1,145,955 | <p>Say I have the following set of urls in a db</p>
<pre><code>url data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more
</code></pre>
<p>Given any url in the wild, I would like to check to
see if that url belongs to an existing set of ... | 1 | 2009-07-17T22:27:49Z | 1,147,754 | <p>The plan I'm leaning towards is one which picks of the domain name + tld from
a url, uses that as a key to find out all the regexes and than loops through
each of this regex subset to find a match.</p>
<p>I use two tables for this</p>
<pre><code>class Urlregex(db.Model):
"""
the data field is structured as... | 0 | 2009-07-18T15:02:42Z | [
"python",
"regex",
"url-routing"
] |
how would i design a db to contain a set of url regexes (python) that could be matched against an incoming url | 1,145,955 | <p>Say I have the following set of urls in a db</p>
<pre><code>url data
^(.*)google.com/search foobar
^(.*)google.com/alerts barfoo
^(.*)blah.com/foo/(.*) foofoo
... 100's more
</code></pre>
<p>Given any url in the wild, I would like to check to
see if that url belongs to an existing set of ... | 1 | 2009-07-17T22:27:49Z | 1,149,218 | <blockquote>
<p>"2. django does urlresolution by looping through each regex and checking for a match given that there maybe 1000's of urls is this the best way to approach this?"</p>
<p>"3. Are there any existing implementations I can look at?"</p>
</blockquote>
<p>If running a large number of regular expressio... | 1 | 2009-07-19T04:01:23Z | [
"python",
"regex",
"url-routing"
] |
Python xml.dom and bad XML | 1,147,090 | <p>I'm trying to extract some data from various HTML pages using a python program. Unfortunately, some of these pages contain user-entered data which occasionally has "slight" errors - namely tag mismatching.</p>
<p>Is there a good way to have python's xml.dom try to correct errors or something of the sort? Alternativ... | 0 | 2009-07-18T09:24:49Z | 1,147,101 | <p>You could use <a href="http://utidylib.berlios.de/" rel="nofollow">HTML Tidy</a> to clean up, or <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> to parse. Could be that you have to save the result to a temp file, but it should work.</p>
<p>Cheers,</p>
| 3 | 2009-07-18T09:33:48Z | [
"python",
"xml",
"dom",
"expat-parser"
] |
Python xml.dom and bad XML | 1,147,090 | <p>I'm trying to extract some data from various HTML pages using a python program. Unfortunately, some of these pages contain user-entered data which occasionally has "slight" errors - namely tag mismatching.</p>
<p>Is there a good way to have python's xml.dom try to correct errors or something of the sort? Alternativ... | 0 | 2009-07-18T09:24:49Z | 1,147,161 | <p>I used to use BeautifulSoup for such tasks but now I have shifted to <strong>HTML5lib</strong> (<a href="http://code.google.com/p/html5lib/" rel="nofollow">http://code.google.com/p/html5lib/</a>) which works well in many cases where BeautifulSoup fails</p>
<p>other alternative is to use "<strong>Element Soup</stron... | 0 | 2009-07-18T10:05:53Z | [
"python",
"xml",
"dom",
"expat-parser"
] |
Python xml.dom and bad XML | 1,147,090 | <p>I'm trying to extract some data from various HTML pages using a python program. Unfortunately, some of these pages contain user-entered data which occasionally has "slight" errors - namely tag mismatching.</p>
<p>Is there a good way to have python's xml.dom try to correct errors or something of the sort? Alternativ... | 0 | 2009-07-18T09:24:49Z | 1,147,209 | <p><a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> does a decent job at parsing invalid HTML.</p>
<p>According to their documentation <a href="http://codespeak.net/lxml/elementsoup.html" rel="nofollow">Beautiful Soup</a> and <a href="http://codespeak.net/lxml/html5parser.html" rel="nofollow">html5lib</a> ... | 0 | 2009-07-18T10:31:53Z | [
"python",
"xml",
"dom",
"expat-parser"
] |
Python xml.dom and bad XML | 1,147,090 | <p>I'm trying to extract some data from various HTML pages using a python program. Unfortunately, some of these pages contain user-entered data which occasionally has "slight" errors - namely tag mismatching.</p>
<p>Is there a good way to have python's xml.dom try to correct errors or something of the sort? Alternativ... | 0 | 2009-07-18T09:24:49Z | 1,149,208 | <p>If jython is acceptable to you, tagsoup is very good at parsing junk - if it is, I found the jdom libraries far easier to use than other xml alternatives.</p>
<p>This is a snippet from a demo mockup to do with screen scraping from tfl's journey planner:</p>
<pre>
private Document getRoutePage(HashMap params) thro... | 0 | 2009-07-19T03:54:23Z | [
"python",
"xml",
"dom",
"expat-parser"
] |
IE8 automation and https | 1,147,193 | <p>I'm trying to use IE8 through COM to access a secured site (namely, SourceForge), in Python. Here is the script:</p>
<pre><code>from win32com.client import gencache
from win32com.client import Dispatch
import pythoncom
gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}', 0, 1, 1)
class SourceForge(obj... | 1 | 2009-07-18T10:24:07Z | 1,147,227 | <p>I can't open <strong><a href="https://sourceforget.net/" rel="nofollow">https://sourceforget.net/</a></strong> -- not by hand, not by script.</p>
<p>Are you sure this link is right?</p>
| 2 | 2009-07-18T10:39:59Z | [
"python",
"windows",
"winapi"
] |
Create instance of a python class , declared in python, with C API | 1,147,452 | <p>I want to create an instance of a Python class defined in the <code>__main__</code> scope with the C API.</p>
<p>For example, the class is called <code>MyClass</code> and is defined as follows:</p>
<pre><code>class MyClass:
def __init__(self):
pass
</code></pre>
<p>The class type lives under <code>__m... | 5 | 2009-07-18T12:38:40Z | 1,147,840 | <p>I believe the simplest approach is:</p>
<pre><code>/* get sys.modules dict */
PyObject* sys_mod_dict = PyImport_GetModuleDict();
/* get the __main__ module object */
PyObject* main_mod = PyMapping_GetItemString(sys_mod_dict, "__main__");
/* call the class inside the __main__ module */
PyObject* instance = PyObject_... | 15 | 2009-07-18T15:41:44Z | [
"python",
"c",
"python-c-api"
] |
Scrolling through a `wx.ScrolledPanel` with the mouse wheel and arrow keys | 1,147,581 | <p>In my wxPython application I've created a <code>wx.ScrolledPanel</code>, in which there is a big <code>wx.StaticBitmap</code> that needs to be scrolled.</p>
<p>The scroll bars do appear and I can scroll with them, but I'd also like to be able to scroll with the mouse wheel and the arrow keys on the keyboard. It wou... | 5 | 2009-07-18T13:51:37Z | 1,147,996 | <p>Here's an example that should do what you want, I hope. (<strong>Edit</strong>: In retrospect, this doesnt' quite work, for example, when there are two scrolled panels... I'll leave it up here though so peole can downvote it or whatever.) Basically I put everything in a panel inside the frame (generally a good ide... | 0 | 2009-07-18T16:49:11Z | [
"python",
"user-interface",
"wxpython",
"scroll"
] |
Scrolling through a `wx.ScrolledPanel` with the mouse wheel and arrow keys | 1,147,581 | <p>In my wxPython application I've created a <code>wx.ScrolledPanel</code>, in which there is a big <code>wx.StaticBitmap</code> that needs to be scrolled.</p>
<p>The scroll bars do appear and I can scroll with them, but I'd also like to be able to scroll with the mouse wheel and the arrow keys on the keyboard. It wou... | 5 | 2009-07-18T13:51:37Z | 1,157,267 | <p>Problem is on window Frame gets the focus and child panel is not getting the Focus (on ubuntu linux it is working fine). Workaround can be as simple as to redirect Frame focus event to set focus to panel e.g.</p>
<pre><code>import wx, wx.lib.scrolledpanel
class MyFrame(wx.Frame):
def __init__(self, *args, **kw... | 3 | 2009-07-21T04:10:21Z | [
"python",
"user-interface",
"wxpython",
"scroll"
] |
Python Xlib catch/send mouseclick | 1,147,653 | <p>At the moment I'm trying to use Python to detect when the left mouse button is being held and then start to rapidly send this event instead of only once. What I basically want to do is that when the left mouse button is held it clicks and clicks again until you let it go. But I'm a bit puzzled with the whole Xlib, I... | 1 | 2009-07-18T14:19:33Z | 1,147,878 | <p>Actually you want <code>Xlib.X.ButtonPressMask | Xlib.X.ButtonReleaseMask</code>, to get events for button presses and releases (different from key presses and releases). The events are <code>ButtonPress</code> and <code>ButtonRelease</code>, and the <code>detail</code> instance variable gives you the button number... | 4 | 2009-07-18T15:57:55Z | [
"python",
"events",
"mouse",
"click",
"xlib"
] |
How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home? | 1,147,713 | <p>I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer.</p>
<p>Thanks!</p>
| 1 | 2009-07-18T14:45:11Z | 1,147,770 | <p>The easiest way might be to install <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">easy_install</a> using the instructions at that page and then typing the following at the command line:</p>
<pre><code>easy_install libgmail
</code></pre>
<p>If it can't be found, then you can point it directly to t... | 3 | 2009-07-18T15:12:52Z | [
"python"
] |
How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home? | 1,147,713 | <p>I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer.</p>
<p>Thanks!</p>
| 1 | 2009-07-18T14:45:11Z | 1,147,791 | <p>All you have to do is extract it, and put it somewhere (I prefer the Libs folder in your Python directory). Then read the readme. It explains that you need to do:</p>
<pre><code>python setup.py
</code></pre>
<p>in your command line. Then you're done.</p>
| 1 | 2009-07-18T15:21:55Z | [
"python"
] |
How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home? | 1,147,713 | <p>I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer.</p>
<p>Thanks!</p>
| 1 | 2009-07-18T14:45:11Z | 1,147,801 | <p>Let's say you downloaded and unzipped it to <code>C:/libgmail-0.1.11</code>. Open a command prompt and:</p>
<pre><code>cd C:/libgmail-0.1.11
</code></pre>
<p>Then build an Windows installer:</p>
<pre><code>python setup.py bdist --format=wininst
</code></pre>
<p>Then go to <code>C:/libgmail-0.1.11/dist</code> an... | 1 | 2009-07-18T15:25:27Z | [
"python"
] |
How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home? | 1,147,713 | <p>I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer.</p>
<p>Thanks!</p>
| 1 | 2009-07-18T14:45:11Z | 1,148,018 | <p>Extract the archive to a temporary directory, and type "python setup.py <strong>install</strong>".</p>
| 2 | 2009-07-18T17:01:40Z | [
"python"
] |
How to install Python 3rd party libgmail-0.1.11.tar.tar into Python in Windows XP home? | 1,147,713 | <p>I do not know Python, I have installed it only and downloaded the libgmail package. So, please give me verbatim steps in installing the libgmail library. My python directory is c:\python26, so please do not skip any steps in the answer.</p>
<p>Thanks!</p>
| 1 | 2009-07-18T14:45:11Z | 1,148,313 | <p>Here's how I did it:</p>
<ol>
<li>Make sure C:\Python26 and C:\Python26\scripts are both on your system path.</li>
<li>Install <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">setuptools</a>. You'll have to download the source distribution, and extract it. You will likely need something like <a hre... | 1 | 2009-07-18T19:06:04Z | [
"python"
] |
What is the DRY way to configure different log file locations for different settings? | 1,147,812 | <p>I am using python's <code>logging</code> module in a django project. I am performing the basic logging configuration in my <code>settings.py</code> file. Something like this:</p>
<pre><code>import logging
import logging.handlers
logger = logging.getLogger('project_logger')
logger.setLevel(logging.INFO)
LOG_FILE... | 4 | 2009-07-18T15:28:15Z | 1,147,831 | <p>Why don't you put this statements at the end of settings.py and use the DEBUG flal es indicator for developement?</p>
<p>Something like this:</p>
<pre><code>import logging
import logging.handlers
logger = logging.getLogger('project_logger')
logger.setLevel(logging.INFO)
[snip]
if DEBUG:
LOG_FILENAME = '/pa... | 1 | 2009-07-18T15:36:45Z | [
"python",
"django",
"logging"
] |
What is the DRY way to configure different log file locations for different settings? | 1,147,812 | <p>I am using python's <code>logging</code> module in a django project. I am performing the basic logging configuration in my <code>settings.py</code> file. Something like this:</p>
<pre><code>import logging
import logging.handlers
logger = logging.getLogger('project_logger')
logger.setLevel(logging.INFO)
LOG_FILE... | 4 | 2009-07-18T15:28:15Z | 1,148,039 | <p>Found a reasonably "DRY" solution that worked. Thanks to <a href="http://stackoverflow.com/questions/342434/python-logging-in-django/343575#343575">http://stackoverflow.com/questions/342434/python-logging-in-django/343575#343575</a></p>
<p>I now have a log.py which looks something like this:</p>
<pre><code>import ... | 1 | 2009-07-18T17:12:14Z | [
"python",
"django",
"logging"
] |
Difference in SHA512 between python hashlib and sha512sum tool | 1,147,875 | <p>I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library.</p>
<p>Here is what I get on my Ubuntu 8.10:</p>
<pre><code>$ echo test | sha512sum
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123... | 4 | 2009-07-18T15:56:13Z | 1,147,880 | <p>I think the difference is that echo adds a newline character to its output.
Try echo -n test | sha512sum</p>
| 14 | 2009-07-18T15:59:05Z | [
"python",
"digest",
"sha512",
"hashlib"
] |
Difference in SHA512 between python hashlib and sha512sum tool | 1,147,875 | <p>I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library.</p>
<p>Here is what I get on my Ubuntu 8.10:</p>
<pre><code>$ echo test | sha512sum
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123... | 4 | 2009-07-18T15:56:13Z | 1,147,883 | <p><code>echo</code> is adding a newline:</p>
<pre><code>$ python -c 'import hashlib; print hashlib.sha512("test\n").hexdigest()'
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123
</code></pre>
<p>To avoid that, use <code>echo -n</code>.</... | 10 | 2009-07-18T16:00:09Z | [
"python",
"digest",
"sha512",
"hashlib"
] |
Difference in SHA512 between python hashlib and sha512sum tool | 1,147,875 | <p>I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library.</p>
<p>Here is what I get on my Ubuntu 8.10:</p>
<pre><code>$ echo test | sha512sum
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123... | 4 | 2009-07-18T15:56:13Z | 1,148,988 | <p>Different input, different output. Try comparing like with like:</p>
<pre><code>C:\junk>echo test| python -c "import sys, hashlib; x = sys.stdin.read(); print len(x), repr(x); print hashlib.sha512(x).hexdigest()"
5 'test\n'
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c... | 2 | 2009-07-19T00:47:46Z | [
"python",
"digest",
"sha512",
"hashlib"
] |
Python socket accept blocks - prevents app from quitting | 1,148,062 | <p>I've written a very simple python class which waits for connections on a socket. The intention is to stick this class into an existing app and asyncronously send data to connecting clients. </p>
<p>The problem is that when waiting on an socket.accept(), I cannot end my application by pressing ctrl-c. Neither can I ... | 8 | 2009-07-18T17:23:39Z | 1,148,126 | <p>Add <code>self.setDaemon(True)</code> to the <code>__init__</code> before <code>self.start()</code>.</p>
<p>(In Python 2.6 and later, <code>self.daemon = True</code> is preferred).</p>
<p>The key idea is explained <a href="http://docs.python.org/library/threading.html#threading.Thread.daemon">here</a>:</p>
<block... | 9 | 2009-07-18T17:49:38Z | [
"python",
"sockets"
] |
Python socket accept blocks - prevents app from quitting | 1,148,062 | <p>I've written a very simple python class which waits for connections on a socket. The intention is to stick this class into an existing app and asyncronously send data to connecting clients. </p>
<p>The problem is that when waiting on an socket.accept(), I cannot end my application by pressing ctrl-c. Neither can I ... | 8 | 2009-07-18T17:23:39Z | 1,148,237 | <p>I don't recommend the setDaemon feature for normal shutdown. It's sloppy; instead of having a clean shutdown path for threads, it simply kills the thread with no chance for cleanup. It's good to set it, so your program doesn't get stuck if the main thread exits unexpectedly, but it's not a good normal shutdown pat... | 3 | 2009-07-18T18:34:46Z | [
"python",
"sockets"
] |
Possible to access gdata api when using Java App Engine? | 1,148,165 | <p>I have a dilemma where I want to create an application that manipulates google contacts information. The problem comes down to the fact that Python only supports version 1.0 of the api whilst Java supports 3.0.</p>
<p>I also want it to be web-based so I'm having a look at google app engine, but it seems that only t... | 0 | 2009-07-18T18:08:04Z | 1,149,886 | <p>I'm having a look into the google data api protocol which seems to solve the problem.</p>
| 0 | 2009-07-19T13:19:25Z | [
"java",
"python",
"google-app-engine",
"gdata-api"
] |
Possible to access gdata api when using Java App Engine? | 1,148,165 | <p>I have a dilemma where I want to create an application that manipulates google contacts information. The problem comes down to the fact that Python only supports version 1.0 of the api whilst Java supports 3.0.</p>
<p>I also want it to be web-based so I'm having a look at google app engine, but it seems that only t... | 0 | 2009-07-18T18:08:04Z | 1,401,123 | <p>Google Data API Java Client : <a href="http://code.google.com/p/gdata-java-client/" rel="nofollow">link1</a></p>
<p>Getting Started with the Google Data Java Client Library <a href="http://code.google.com/apis/gdata/articles/java%5Fclient%5Flib.html" rel="nofollow">link2</a> </p>
<p>I guess this is what you were l... | 0 | 2009-09-09T18:01:14Z | [
"java",
"python",
"google-app-engine",
"gdata-api"
] |
Possible to access gdata api when using Java App Engine? | 1,148,165 | <p>I have a dilemma where I want to create an application that manipulates google contacts information. The problem comes down to the fact that Python only supports version 1.0 of the api whilst Java supports 3.0.</p>
<p>I also want it to be web-based so I'm having a look at google app engine, but it seems that only t... | 0 | 2009-07-18T18:08:04Z | 2,832,965 | <p>I use GDATA apis for my JAVA appengine webapp. So GDATA can be used with JAVA runtime.</p>
<p>From <a href="http://code.google.com/appengine/kb/java.html" rel="nofollow">http://code.google.com/appengine/kb/java.html</a></p>
<blockquote>
<p>Yes, the Google Data Java client library can be used in App Engine, but y... | 0 | 2010-05-14T09:11:20Z | [
"java",
"python",
"google-app-engine",
"gdata-api"
] |
cx_Oracle and the data source paradigm | 1,148,472 | <p>There is a Java paradigm for database access implemented in the Java <code>DataSource</code>. This object create a useful abstraction around the creation of database connections. The <code>DataSource</code> object keeps database configuration, but will only create database connections on request. This is allows you ... | 3 | 2009-07-18T20:19:18Z | 1,148,530 | <p>I don't think there is a "right" way to do this in Python, except maybe to go one step further and use another layer between yourself and the database.</p>
<p>Depending on the reason for wanting to use the DataSource concept (which I've only ever come across in Java), SQLAlchemy (or something similar) might solve t... | 1 | 2009-07-18T20:50:45Z | [
"python",
"database",
"oracle",
"cx-oracle"
] |
cx_Oracle and the data source paradigm | 1,148,472 | <p>There is a Java paradigm for database access implemented in the Java <code>DataSource</code>. This object create a useful abstraction around the creation of database connections. The <code>DataSource</code> object keeps database configuration, but will only create database connections on request. This is allows you ... | 3 | 2009-07-18T20:19:18Z | 1,148,609 | <p>You'll find relevant information of how to access databases in Python by looking at <a href="http://www.python.org/dev/peps/pep-0249/" rel="nofollow">PEP-249: Python Database API Specification v2.0</a>. <code>cx_Oracle</code> conforms to this specification, as do many database drivers for Python.</p>
<p>In this spe... | 3 | 2009-07-18T21:30:47Z | [
"python",
"database",
"oracle",
"cx-oracle"
] |
cx_Oracle and the data source paradigm | 1,148,472 | <p>There is a Java paradigm for database access implemented in the Java <code>DataSource</code>. This object create a useful abstraction around the creation of database connections. The <code>DataSource</code> object keeps database configuration, but will only create database connections on request. This is allows you ... | 3 | 2009-07-18T20:19:18Z | 1,148,995 | <p>Yes, Python has a similar abstraction.</p>
<p>This is from our local build regression test, where we assure that we can talk to all of our databases whenever we build a new python.</p>
<pre><code>if database == SYBASE:
import Sybase
conn = Sybase.connect('sybasetestdb','mh','secret')
elif database == POSTR... | 0 | 2009-07-19T00:50:08Z | [
"python",
"database",
"oracle",
"cx-oracle"
] |
cx_Oracle and the data source paradigm | 1,148,472 | <p>There is a Java paradigm for database access implemented in the Java <code>DataSource</code>. This object create a useful abstraction around the creation of database connections. The <code>DataSource</code> object keeps database configuration, but will only create database connections on request. This is allows you ... | 3 | 2009-07-18T20:19:18Z | 1,157,015 | <p>I just sucked it up and wrote my own. It allowed me to add things like abstracting the database (Oracle/MySQL/Access/etc), adding logging, error handling with transaction rollbacks, etc.</p>
| 0 | 2009-07-21T02:28:17Z | [
"python",
"database",
"oracle",
"cx-oracle"
] |
Python threads - crashing when they access postgreSQL | 1,148,671 | <p>here is a simple threading program which works fine: </p>
<pre><code>import psycopg2
import threading
import time
class testit(threading.Thread):
def __init__(self, currency):
threading.Thread.__init__(self)
self.currency = currency
def run(self):
global SQLConnection
globa... | 1 | 2009-07-18T21:50:50Z | 1,148,710 | <pre><code>global SQLConnection
global cursor
</code></pre>
<p>Seems you're accessing globals from multiple threads ? You should <strong>never</strong> do that unless those globals are thread safe, or you provide the proper locking yourself.</p>
<p>You now have 2 threads accessing the same connection and the same cur... | 1 | 2009-07-18T22:04:19Z | [
"python",
"postgresql"
] |
Python threads - crashing when they access postgreSQL | 1,148,671 | <p>here is a simple threading program which works fine: </p>
<pre><code>import psycopg2
import threading
import time
class testit(threading.Thread):
def __init__(self, currency):
threading.Thread.__init__(self)
self.currency = currency
def run(self):
global SQLConnection
globa... | 1 | 2009-07-18T21:50:50Z | 1,148,716 | <p>bingo it's working. Someone left an answer but then seems to have removed it, to give each thread its own connection. And yep that solves it. So this code works:</p>
<pre><code>import psycopg2
import threading
import time
class testit(threading.Thread):
def __init__(self, currency):
threading.Thread.__... | 0 | 2009-07-18T22:08:29Z | [
"python",
"postgresql"
] |
using task queues to schedule the fetching/parsing of a number of feeds in appengine python | 1,148,709 | <p>Say I had over 10,000 feeds that I wanted to periodically fetch/parse.
If the period were say 1h that would be 24x10000 = 240,000 fetches.</p>
<p>The current 10k limit of the labs taskqueue api would preclude one from
setting up one task per fetch. How then would one do this?</p>
<p>Update: re: fetching nurls per ... | 0 | 2009-07-18T22:04:17Z | 1,148,720 | <p>2 fetches per task? 3?</p>
| 2 | 2009-07-18T22:10:25Z | [
"python",
"google-app-engine",
"feeds"
] |
using task queues to schedule the fetching/parsing of a number of feeds in appengine python | 1,148,709 | <p>Say I had over 10,000 feeds that I wanted to periodically fetch/parse.
If the period were say 1h that would be 24x10000 = 240,000 fetches.</p>
<p>The current 10k limit of the labs taskqueue api would preclude one from
setting up one task per fetch. How then would one do this?</p>
<p>Update: re: fetching nurls per ... | 0 | 2009-07-18T22:04:17Z | 1,148,729 | <p>Group up the fetches, so instead of queuing 1 fetch you queue up, say, a work unit that does 10 fetches.</p>
| 0 | 2009-07-18T22:16:01Z | [
"python",
"google-app-engine",
"feeds"
] |
using task queues to schedule the fetching/parsing of a number of feeds in appengine python | 1,148,709 | <p>Say I had over 10,000 feeds that I wanted to periodically fetch/parse.
If the period were say 1h that would be 24x10000 = 240,000 fetches.</p>
<p>The current 10k limit of the labs taskqueue api would preclude one from
setting up one task per fetch. How then would one do this?</p>
<p>Update: re: fetching nurls per ... | 0 | 2009-07-18T22:04:17Z | 1,148,869 | <p>Here's the asynchronous urlfetch API:</p>
<p><a href="http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html" rel="nofollow">http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html</a></p>
<p>Set of a bunch of requests with a reasonable deadline (give yourself some ... | 3 | 2009-07-18T23:28:57Z | [
"python",
"google-app-engine",
"feeds"
] |
MetaPython: Adding Methods to a Class | 1,148,827 | <p>I would like to add some methods to a class definition at runtime. However, when running the following code, I get some surprising (to me) results.</p>
<h3>test.py</h3>
<pre><code>class klass(object):
pass
for i in [1,2]:
def f(self):
print(i)
setattr(klass, 'f' + str(i), f)
</code></pre>
<p>I ... | 1 | 2009-07-18T23:03:40Z | 1,148,839 | <p>My guess is that it's because <code>print (i)</code> prints <code>i</code> not <em>by value</em>, but <em>by reference</em>. Thus, when leaving the for loop, <em>i</em> has the value <strong>2</strong>, which will be printed both times. </p>
| 0 | 2009-07-18T23:10:21Z | [
"python",
"binding",
"metaprogramming"
] |
MetaPython: Adding Methods to a Class | 1,148,827 | <p>I would like to add some methods to a class definition at runtime. However, when running the following code, I get some surprising (to me) results.</p>
<h3>test.py</h3>
<pre><code>class klass(object):
pass
for i in [1,2]:
def f(self):
print(i)
setattr(klass, 'f' + str(i), f)
</code></pre>
<p>I ... | 1 | 2009-07-18T23:03:40Z | 1,148,843 | <p>It's the usual problem of binding -- you want early binding for the use of <code>i</code> inside the function and Python is doing late binding for it. You can force the earlier binding this way:</p>
<pre><code>class klass(object):
pass
for i in [1,2]:
def f(self, i=i):
print(i)
setattr(klass, ... | 11 | 2009-07-18T23:11:23Z | [
"python",
"binding",
"metaprogramming"
] |
Rendering common session information in every view | 1,148,854 | <p>I'd like to output some information that depends on session data in Django. Let's take a "Login" / "Logged in as | Logout" fragment for example. It depends on my <code>request.session['user']</code>.</p>
<p>Of course I can put a user object in the context every time I render a page and then switch on <code>{% if u... | 0 | 2009-07-18T23:18:49Z | 1,148,886 | <p>Are you trying to make certain areas of your site only accessible when logged on? Or certain areas of a particular page?</p>
<p>If you want to block off access to a whole URL you can use the @login_required decorator in your functions in your view to block certain access. Also, you can use includes to keep the comm... | 0 | 2009-07-18T23:45:47Z | [
"python",
"django",
"session",
"templates"
] |
Rendering common session information in every view | 1,148,854 | <p>I'd like to output some information that depends on session data in Django. Let's take a "Login" / "Logged in as | Logout" fragment for example. It depends on my <code>request.session['user']</code>.</p>
<p>Of course I can put a user object in the context every time I render a page and then switch on <code>{% if u... | 0 | 2009-07-18T23:18:49Z | 1,148,887 | <p>Use <a href="http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance" rel="nofollow">template inheritance</a> to derive all of your templates from a common base that suitably uses the common parts of the context, and make all your contexts with a factory function that ensures the insertion in the... | 5 | 2009-07-18T23:46:47Z | [
"python",
"django",
"session",
"templates"
] |
Rendering common session information in every view | 1,148,854 | <p>I'd like to output some information that depends on session data in Django. Let's take a "Login" / "Logged in as | Logout" fragment for example. It depends on my <code>request.session['user']</code>.</p>
<p>Of course I can put a user object in the context every time I render a page and then switch on <code>{% if u... | 0 | 2009-07-18T23:18:49Z | 7,569,126 | <p>You may want to use a context processor that includes logic and place it into a variable you can use in any of your pages without adding it to each call.</p>
<p>See more info at <a href="http://stackoverflow.com/questions/3221592/how-to-pass-common-dictionary-data-to-every-pages-in-django">how to pass common dictio... | 0 | 2011-09-27T12:30:14Z | [
"python",
"django",
"session",
"templates"
] |
How to resume program (or exit) after opening webbrowser? | 1,149,233 | <p>I'm making a small Python program, which calls the <code>webbrowser</code> module to open a URL. Opening the URL works wonderfully.</p>
<p>My problem is that once this line of code is reached, the problem is unresponsive. How do I get the program to proceed past this line of code and continue to execute? Below the ... | 2 | 2009-07-19T04:21:16Z | 1,149,254 | <p>The webbrowser module makes a system call to start a separate program (the web browser), then waits ( "blocks" ) for an exit code. This happens any time you start a program from another program. You have to (A) write your own function that does not block waiting for the webbrowser to exit (by using threads, fork(), ... | 0 | 2009-07-19T04:43:24Z | [
"python",
"browser",
"if-statement"
] |
How to resume program (or exit) after opening webbrowser? | 1,149,233 | <p>I'm making a small Python program, which calls the <code>webbrowser</code> module to open a URL. Opening the URL works wonderfully.</p>
<p>My problem is that once this line of code is reached, the problem is unresponsive. How do I get the program to proceed past this line of code and continue to execute? Below the ... | 2 | 2009-07-19T04:21:16Z | 1,149,264 | <p>The easiest thing to do here is probably to fork. I'm pretty sure this doesn't work in windows unfortunately, since I think their process model might be different from unix-like operating systems. The process will be similar, though.</p>
<pre><code>pid = os.fork()
if pid:
# we are the parent, continue on
... | 3 | 2009-07-19T04:56:31Z | [
"python",
"browser",
"if-statement"
] |
How to resume program (or exit) after opening webbrowser? | 1,149,233 | <p>I'm making a small Python program, which calls the <code>webbrowser</code> module to open a URL. Opening the URL works wonderfully.</p>
<p>My problem is that once this line of code is reached, the problem is unresponsive. How do I get the program to proceed past this line of code and continue to execute? Below the ... | 2 | 2009-07-19T04:21:16Z | 1,149,285 | <p>This looks like it depends on which platform you're running on.</p>
<ul>
<li>MacOSX - returns True immediately and opens up browser window. Presumably your desired behavior.</li>
<li>Linux (no X) - Open up links textmode browser. Once this is closed, returns True.</li>
<li>Linux (with X) - Opens up Konquerer (in ... | 4 | 2009-07-19T05:09:51Z | [
"python",
"browser",
"if-statement"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,265 | <p>I think some names for the concept you're thinking about are <a href="http://en.wikipedia.org/wiki/String%5Finterning" rel="nofollow">interning</a> and <a href="http://en.wikipedia.org/wiki/Immutable%5Fobject" rel="nofollow">immutable objects</a>.</p>
<p>As for an answer to your specific questions, I think for #1, ... | 1 | 2009-07-19T04:56:43Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,269 | <p>For the first question you could implement a singleton class design pattern <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow">http://en.wikipedia.org/wiki/Singleton_pattern</a> you should from that restrict the number of instances.</p>
<p>For the second question, I think this kind of explains ... | 3 | 2009-07-19T04:58:43Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,272 | <p>You're talking about giving a class <em>value semantics</em>, which is typically done by creating class instances in the normal way, but remembering each one, and if a matching instance would be created, give the already created instance instead. In python, this can be achieved by overloading a classes <code>__new_... | 5 | 2009-07-19T05:00:00Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,275 | <ol>
<li>Create them in advance and return one of those from <code>__new__</code> instead of creating a new object, or cache created instances (<a href="http://docs.python.org/library/weakref.html#weakref.WeakValueDictionary" rel="nofollow">weakrefs</a> are handy here) and return one of those instead of creating a new ... | 2 | 2009-07-19T05:04:01Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,398 | <p>Looks like #1 has been well answered already and I just want to explain a principle, related to #2, which appears to have been missed by all respondents: for most built-in types, calling the type without parameters (the "default constructor") returns an instance of that type <em>which evaluates as false</em>. That ... | 4 | 2009-07-19T07:08:49Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,415 | <p>To answer the more generic question of how to create constrained instances, it depends on the constraint. Both you examples above are a sort of "singletons", although the second example is a variation where you can have many instances of one class, but you will have only one per input value.</p>
<p>These can both d... | 2 | 2009-07-19T07:31:14Z | [
"python",
"math",
"class"
] |
How to create Classes in Python with highly constrained instances | 1,149,253 | <p>In Python, there are examples of built-in classes with highly constrained instances. For example, "None" is the only instance of its class, and in the bool class there are only two objects, "True" and "False" (I hope I am more-or-less correct so far). </p>
<p>Another good example are integers: if a and b are ... | 2 | 2009-07-19T04:42:10Z | 1,149,503 | <p>Note: this is not really an answer to your question, but more a comment I could not fit in the "comment" space.</p>
<p>Please note that <code>a == b</code> does <strong>NOT</strong> implies that <code>a is b</code>.</p>
<p>It is true only for first handfuls of integers (like first hundred or so - I do not know exa... | 1 | 2009-07-19T08:53:16Z | [
"python",
"math",
"class"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 1,149,354 | <p>Have you tried using a <a href="http://sphinx.pocoo.org/ext/autodoc.html#skipping-members" rel="nofollow">custom method</a> for determining whether a member should be included in the documentation, using <code>autodoc-skip-member</code>?</p>
| 4 | 2009-07-19T06:28:49Z | [
"python",
"documentation",
"python-sphinx"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 1,149,714 | <p>Here's a hint: imagine that private means "secret". </p>
<p>That's why Sphinx won't document them. </p>
<p>If you don't mean "secret", consider changing their names. Avoid using the single-leading-underscore name in general; it doesn't help unless you have a reason to keep the implementation secret.</p>
| -7 | 2009-07-19T11:37:02Z | [
"python",
"documentation",
"python-sphinx"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 1,200,075 | <p>No, private means private to the class and that it shouldn't be used from the public API. It's not meant to mean secret and for those of us wishing to use sphinx for full documentation of classes, excluding private methods is rather annoying.</p>
<p>The previous answer is correct. You will have to use a custom meth... | 2 | 2009-07-29T13:00:36Z | [
"python",
"documentation",
"python-sphinx"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 6,106,855 | <p>One way to get around this is to explicitly force Sphinx to document private members. You can do this by appending <code>automethod</code> to the end of the class level docs:</p>
<pre><code>class SmokeMonster(object):
"""
A large smoke monster that protects the island.
"""
def __init__(self,speed):
... | 8 | 2011-05-24T07:02:59Z | [
"python",
"documentation",
"python-sphinx"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 7,740,295 | <p>if you are using sphinx 1.1 or above, from the sphinx documentation site at <a href="http://sphinx.pocoo.org/ext/autodoc.html">http://sphinx.pocoo.org/ext/autodoc.html</a>,</p>
<pre><code>:special-members:
:private-members:
</code></pre>
| 18 | 2011-10-12T12:47:28Z | [
"python",
"documentation",
"python-sphinx"
] |
How can I use Sphinx' Autodoc-extension for private methods? | 1,149,280 | <p>I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.</p>
<pre><code>.. autoclass:: ClassName
:members:
</code></pre>
<p>The problem is, it only documents the <a href="http://sphinx.pocoo.org/ext/autodoc.html">non-private methods</a> in the ... | 18 | 2009-07-19T05:07:51Z | 30,144,019 | <p>Looking at <a href="https://github.com/sphinx-doc/sphinx/blob/master/sphinx/apidoc.py#L28" rel="nofollow">apidoc code</a>, we can change what sphinx-apidoc generate setting an environment variable:</p>
<pre><code>export SPHINX_APIDOC_OPTIONS='members,special-members,private-members,undoc-members,show-inheritance'
<... | 2 | 2015-05-09T19:14:55Z | [
"python",
"documentation",
"python-sphinx"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.