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: Reading part of a text file | 964,993 | <p>HI all</p>
<p>I'm new to python and programming. I need to read in chunks of a large text file, format looks like the following: </p>
<pre><code><word id="8" form="hibernis" lemma="hibernus1" postag="n-p---nb-" head-"7" relation="ADV"/>
</code></pre>
<p>I need the <code>form</code>, <code>lemma</code> and <... | 4 | 2009-06-08T13:44:32Z | 965,074 | <p>wow, you guys are fast :)
If you want all attributes of a list (and the ordering is known), then you can use something like this:</p>
<pre><code>import re
print re.findall('"(.+?)"',INPUT)
</code></pre>
<p>INPUT is a line like:</p>
<pre><code><word id="8" form="hibernis" lemma="hibernus1" postag="n-p---nb-" he... | 0 | 2009-06-08T14:05:42Z | [
"python"
] |
Python: Reading part of a text file | 964,993 | <p>HI all</p>
<p>I'm new to python and programming. I need to read in chunks of a large text file, format looks like the following: </p>
<pre><code><word id="8" form="hibernis" lemma="hibernus1" postag="n-p---nb-" head-"7" relation="ADV"/>
</code></pre>
<p>I need the <code>form</code>, <code>lemma</code> and <... | 4 | 2009-06-08T13:44:32Z | 965,140 | <p>If it's XML, use <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a> to parse it:</p>
<pre><code>from xml.etree import ElementTree
line = '<word id="8" form="hibernis" lemma="hibernus1" postag="n-p---nb-" head="7" relation="ADV"/>'
element = ElementTree.fromstr... | 5 | 2009-06-08T14:21:16Z | [
"python"
] |
<option> Level control of Select inputs using Django Forms API | 965,082 | <p>I'm wanting to add a label= attribute to an option element of a Select form input using the Django Forms API without overwriting the Select widget's render_options method. Is this possible, if so, how?</p>
<p>Note: I'm wanting to add a label directly to the option (this <em>is</em> valid in the XHTML Strict standa... | 1 | 2009-06-08T14:07:53Z | 965,545 | <p>I'm afraid this isn't possible without subclassing the <code>Select</code> widget to provide your own rendering, as you've guessed. The <a href="http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py#L409" rel="nofollow">code for Select</a> doesn't include any attributes for each <code><option... | 1 | 2009-06-08T15:39:19Z | [
"python",
"django",
"django-forms"
] |
<option> Level control of Select inputs using Django Forms API | 965,082 | <p>I'm wanting to add a label= attribute to an option element of a Select form input using the Django Forms API without overwriting the Select widget's render_options method. Is this possible, if so, how?</p>
<p>Note: I'm wanting to add a label directly to the option (this <em>is</em> valid in the XHTML Strict standa... | 1 | 2009-06-08T14:07:53Z | 967,798 | <p>I just wrote a class to do that:</p>
<pre><code>from django.forms.widgets import Select
from django.utils.encoding import force_unicode
from itertools import chain
from django.utils.html import escape, conditional_escape
class ExtendedSelect(Select):
"""
A subclass of Select that adds the possibility to d... | 2 | 2009-06-09T01:46:06Z | [
"python",
"django",
"django-forms"
] |
Python - simple reading lines from a pipe | 965,210 | <p>I'm trying to read lines from a pipe and process them, but I'm doing something silly and I can't figure out what. The producer is going to keep producing lines indefinitely, like this:</p>
<p>producer.py</p>
<pre><code>import time
while True:
print 'Data'
time.sleep(1)
</code></pre>
<p>The consumer just ... | 16 | 2009-06-08T14:38:32Z | 965,226 | <p>Some old versions of Windows simulated pipes through files (so they were prone to such problems), but that hasn't been a problem in 10+ years. Try adding a</p>
<pre><code> sys.stdout.flush()
</code></pre>
<p>to the producer after the <code>print</code>, and also try to make the producer's stdout unbuffered (by u... | 16 | 2009-06-08T14:42:52Z | [
"python",
"pipe",
"producer-consumer"
] |
Python - simple reading lines from a pipe | 965,210 | <p>I'm trying to read lines from a pipe and process them, but I'm doing something silly and I can't figure out what. The producer is going to keep producing lines indefinitely, like this:</p>
<p>producer.py</p>
<pre><code>import time
while True:
print 'Data'
time.sleep(1)
</code></pre>
<p>The consumer just ... | 16 | 2009-06-08T14:38:32Z | 965,247 | <p>This is about I/O that is bufferized by default with Python. Pass <code>-u</code> option to the interpreter to disable this behavior:</p>
<pre><code>python -u producer.py | python consumer.py
</code></pre>
<p>It fixes the problem for me.</p>
| 7 | 2009-06-08T14:47:28Z | [
"python",
"pipe",
"producer-consumer"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 965,730 | <p>I am not sure that there is an 'official' way (it is not mentioned in the Zen of Python :) )- I tend to use the Config Parser module myself and I think that you will find that pretty common. I prefer that over the python file approach because you can write back to it and dynamically reload if you want.</p>
| 5 | 2009-06-08T16:18:49Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 965,733 | <p>why would Guido blessed something that is out of his scope? No there is nothing particular blessed.</p>
| 2 | 2009-06-08T16:19:31Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 965,742 | <p>It is more of convenience. There is no official way per say. But using XML files would make sense as they can be manipulated by various other applications/libraries.</p>
| 0 | 2009-06-08T16:21:50Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 965,795 | <p>Depends on the predominant intended audience.</p>
<p>If it is programmers who change the file anyway, just use python files like settings.py</p>
<p>If it is end users then, think about ini files.</p>
| 22 | 2009-06-08T16:35:37Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 965,913 | <p>It depends largely on how complicated your configuration is. If you're doing a simple key-value mapping and you want the capability to edit the settings with a text editor, I think ConfigParser is the way to go. </p>
<p>If your settings are complicated and include lists and nested data structures, I'd use XML or JS... | 1 | 2009-06-08T17:02:11Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 966,043 | <p>Don't know if this can be considered "official", but it is in standard library: <a href="http://docs.python.org/library/configparser.html">14.2. ConfigParser â Configuration file parser</a>.</p>
<p>This is, obviously, <em>not</em> an universal solution, though. Just use whatever feels most appropriate to the task... | 6 | 2009-06-08T17:39:45Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 966,074 | <p>Just one more option, PyQt. Qt has a platform independent way of storing settings with the QSettings class. Underneath the hood, on windows it uses the registry and in linux it stores the settings in a hidden conf file. QSettings works very well and is pretty seemless.</p>
| 8 | 2009-06-08T17:50:36Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 967,036 | <p>As many have said, there is no "offical" way. There are, however, many choices. There was <a href="http://pyvideo.org/video/190/pycon-2009--data-storage-in-python---an-overview0">a talk at PyCon</a> this year about many of the available options.</p>
| 25 | 2009-06-08T21:07:31Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 6,214,590 | <p>I use a shelf ( <a href="http://docs.python.org/library/shelve.html">http://docs.python.org/library/shelve.html</a> ):</p>
<pre><code>shelf = shelve.open(filename)
shelf["users"] = ["David", "Abraham"]
shelf.sync() # Save
</code></pre>
| 14 | 2011-06-02T12:37:19Z | [
"python",
"settings"
] |
What's the official way of storing settings for python programs? | 965,694 | <p>Django uses real Python files for settings, Trac uses a .ini file, and some other pieces of software uses XML files to hold this information.</p>
<p>Are one of these approaches blessed by Guido and/or the Python community more than another?</p>
| 38 | 2009-06-08T16:13:02Z | 16,776,259 | <p>For web applications I like using OS environment variables: <code>os.environ.get('CONFIG_OPTION')</code></p>
<p>This works especially well for settings that vary between deploys. You can read more about the rationale behind using env vars here: <a href="http://www.12factor.net/config" rel="nofollow">http://www.12fa... | 0 | 2013-05-27T15:27:02Z | [
"python",
"settings"
] |
Unicode Problem with SQLAlchemy | 966,352 | <p>I know I'm having a problem with a conversion from Unicode but I'm not sure where it's happening.</p>
<p>I'm extracting data about a recent Eruopean trip from a directory of HTML files. Some of the location names have non-ASCII characters (such as é, ô, ü). I'm getting the data from a string representation of ... | 8 | 2009-06-08T18:50:08Z | 966,423 | <p>Try using a column type of Unicode rather than String for the unicode columns:</p>
<pre><code>Base = declarative_base()
class Point(Base):
__tablename__ = 'points'
id = Column(Integer, primary_key=True)
pdate = Column(Date)
ptime = Column(Time)
location = Column(Unicode(32))
weather = Colum... | 7 | 2009-06-08T19:08:56Z | [
"python",
"unicode",
"encoding",
"character-encoding",
"sqlalchemy"
] |
Unicode Problem with SQLAlchemy | 966,352 | <p>I know I'm having a problem with a conversion from Unicode but I'm not sure where it's happening.</p>
<p>I'm extracting data about a recent Eruopean trip from a directory of HTML files. Some of the location names have non-ASCII characters (such as é, ô, ü). I'm getting the data from a string representation of ... | 8 | 2009-06-08T18:50:08Z | 967,144 | <p>From <a href="http://www.sqlalchemy.org/CHANGES">sqlalchemy.org</a></p>
<p>See section 0.4.2</p>
<blockquote>
<p>added new flag to String and
create_engine(),
assert _unicode=(True|False|'warn'|None).
Defaults to <code>False</code> or <code>None</code> on
create _engine() and String, <code>'w... | 7 | 2009-06-08T21:34:59Z | [
"python",
"unicode",
"encoding",
"character-encoding",
"sqlalchemy"
] |
Unicode Problem with SQLAlchemy | 966,352 | <p>I know I'm having a problem with a conversion from Unicode but I'm not sure where it's happening.</p>
<p>I'm extracting data about a recent Eruopean trip from a directory of HTML files. Some of the location names have non-ASCII characters (such as é, ô, ü). I'm getting the data from a string representation of ... | 8 | 2009-06-08T18:50:08Z | 967,171 | <p>I found this article that helped explain my troubles somewhat:</p>
<p><a href="http://www.amk.ca/python/howto/unicode#reading-and-writing-unicode-data">http://www.amk.ca/python/howto/unicode#reading-and-writing-unicode-data</a></p>
<p>I was able to get the desired results by using the 'codecs' module and then chan... | 10 | 2009-06-08T21:41:25Z | [
"python",
"unicode",
"encoding",
"character-encoding",
"sqlalchemy"
] |
debug variable in python | 966,571 | <p>I want to separate the debug outputs from production ones by defining a variable that can be used throughput the module. It cannot be defined in environment. Any suggestions for globals reused across classes in modules?
Additionally is there a way to configure this variable flag for telling appengine that dont use ... | 2 | 2009-06-08T19:35:39Z | 966,617 | <p>Have a look at the <a href="http://www.python.org/doc/2.5/lib/module-logging.html">logging module</a>, which is fully supported by Google App Engine. You can specify logging levels such as debug, warning, error, etc. They will show up in the dev server console, and will also be stored in the request log.</p>
<p>If ... | 12 | 2009-06-08T19:44:59Z | [
"python",
"google-app-engine"
] |
debug variable in python | 966,571 | <p>I want to separate the debug outputs from production ones by defining a variable that can be used throughput the module. It cannot be defined in environment. Any suggestions for globals reused across classes in modules?
Additionally is there a way to configure this variable flag for telling appengine that dont use ... | 2 | 2009-06-08T19:35:39Z | 967,347 | <p>All module-level variables are global to all classes in the module.</p>
<p>Here's my file: <code>mymodule.py</code></p>
<pre><code>import this
import that
DEBUG = True
class Foo( object ):
def __init__( self ):
if DEBUG: print self.__class__, "__init__"
# etc.
class Bar( object ):
def do... | 1 | 2009-06-08T22:31:05Z | [
"python",
"google-app-engine"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 966,995 | <p>Change this line of code:</p>
<pre><code>a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>to this:</p>
<pre><code>a.append(a[j-2] + (j+2)*(j+3)/2)
</code></pre>
| 7 | 2009-06-08T21:00:01Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,011 | <p>You're adding new elements, elements that do not exist yet. Hence you need to use <code>append</code>: since the items do not exist yet, you cannot reference them by index. <a href="http://docs.python.org/3.0/library/stdtypes.html#mutable-sequence-types" rel="nofollow">Overview of operations on mutable sequence type... | 6 | 2009-06-08T21:02:57Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,015 | <p>At <code>j=2</code> you're trying to assign to a[2], which doesn't exist yet. You probably want to use append instead.</p>
| 1 | 2009-06-08T21:03:38Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,016 | <p>Python lists must be pre-initialzed. You need to do a = [0]*23480</p>
<p>Or you can append if you are adding one at a time. I think it would probably be faster to preallocate the array.</p>
| 0 | 2009-06-08T21:03:51Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,019 | <p>Python does not dynamically increase the size of an array when you assign to an element. You have to use a.append(element) to add an element onto the end, or a.insert(i, element) to insert the element at the position before i.</p>
| 0 | 2009-06-08T21:04:21Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,021 | <p>If you want to debug it, just change your code to print out the current index as you go:</p>
<pre><code> a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
print j # <-- this line
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>But you'll probably find that it errors out the second you access <cod... | 1 | 2009-06-08T21:04:52Z | [
"python"
] |
Python error | 966,983 | <pre><code>a=[]
a.append(3)
a.append(7)
for j in range(2,23480):
a[j]=a[j-2]+(j+2)*(j+3)/2
</code></pre>
<p>When I write this code, it gives an error like this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/tcount2.py", line 6, in <module>
a[j]=a[j-2]+(j+2)*(j+3)/2
IndexError: l... | 2 | 2009-06-08T20:57:48Z | 967,048 | <p>The reason for the error is that you're trying, as the error message says, to access a portion of the list that is currently out of range.</p>
<p>For instance, assume you're creating a list of 10 people, and you try to specify who the 11th person on that list is going to be. On your paper-pad, it might be easy to j... | 3 | 2009-06-08T21:09:14Z | [
"python"
] |
Form Validation in Admin with Inline formset and Model form | 967,045 | <p>I have a model, OrderedList, which is intended to be a listing of content objects ordered by the user. The OrderedList has several attributes, including a site which it belongs to.</p>
<p>The content objects are attached to it via an OrderedListRow class, which is brought into OrderedList's admin via an inline form... | 5 | 2009-06-08T21:08:50Z | 969,068 | <p>In the inline formset, <code>self.instance</code> should refer to the parent object, ie the OrderedList.</p>
| 4 | 2009-06-09T09:28:49Z | [
"python",
"django",
"django-admin",
"django-forms"
] |
Form Validation in Admin with Inline formset and Model form | 967,045 | <p>I have a model, OrderedList, which is intended to be a listing of content objects ordered by the user. The OrderedList has several attributes, including a site which it belongs to.</p>
<p>The content objects are attached to it via an OrderedListRow class, which is brought into OrderedList's admin via an inline form... | 5 | 2009-06-08T21:08:50Z | 1,477,327 | <p>I am dealing with the same issue. And unfortunately I don't think the answer above covers things entirely.</p>
<p>If there are changes in both the inline formset and the admin form, accessing self.instance will not give accurate data, since you will base the validation on the database and then save the formset whic... | 1 | 2009-09-25T13:36:34Z | [
"python",
"django",
"django-admin",
"django-forms"
] |
python: find out if running in shell or not (e.g. sun grid engine queue) | 967,369 | <p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p>
<p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.</p>
<p>thanks!</p>
<p>p.</p>
| 6 | 2009-06-08T22:36:56Z | 967,383 | <p>You can use <code>os.getppid()</code> to find out the process id for the parent-process of this one, and then use that process id to determine which program that process is running. More usefully, you could use <code>sys.stdout.isatty()</code> -- that doesn't answer your title question but appears to better solve th... | 6 | 2009-06-08T22:39:46Z | [
"python",
"shell",
"terminal",
"stdout"
] |
python: find out if running in shell or not (e.g. sun grid engine queue) | 967,369 | <p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p>
<p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.</p>
<p>thanks!</p>
<p>p.</p>
| 6 | 2009-06-08T22:36:56Z | 967,384 | <p>The standard way is <code>isatty()</code>.</p>
<pre><code>import sys
if sys.stdout.isatty():
print("Interactive")
else:
print("Non-interactive")
</code></pre>
| 13 | 2009-06-08T22:39:50Z | [
"python",
"shell",
"terminal",
"stdout"
] |
python: find out if running in shell or not (e.g. sun grid engine queue) | 967,369 | <p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p>
<p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.</p>
<p>thanks!</p>
<p>p.</p>
| 6 | 2009-06-08T22:36:56Z | 1,591,429 | <p>I have found the following to work on both Linux and Windows, in both the normal Python interpreter and IPython (though I can't say about IronPython):</p>
<pre><code>isInteractive = hasattr(sys, 'ps1') or hasattr(sys, 'ipcompleter')
</code></pre>
<p>However, note that when using <strong>ipython</strong>, if the fi... | 1 | 2009-10-19T22:14:47Z | [
"python",
"shell",
"terminal",
"stdout"
] |
python: find out if running in shell or not (e.g. sun grid engine queue) | 967,369 | <p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p>
<p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.</p>
<p>thanks!</p>
<p>p.</p>
| 6 | 2009-06-08T22:36:56Z | 8,499,846 | <p>Slightly shorter:</p>
<pre><code>import sys
sys.stdout.isatty()
</code></pre>
| 3 | 2011-12-14T05:26:44Z | [
"python",
"shell",
"terminal",
"stdout"
] |
Curious about differences in vtkMassProperties for VTK 5.04 and VTK 5.4.2 | 967,468 | <p>I have a small python <a href="http://vtk.org" rel="nofollow"><code>VTK</code></a> function that calculates the volume and surface area of an object embedded in a stack of <code>TIFF</code> images. To read the <code>TIFF's</code> into <code>VTK</code>, I have used <code>vtkTIFFReader</code> and processed the result... | 4 | 2009-06-08T23:06:31Z | 990,274 | <p>I have never heard of <a href="http://www.vtk.org/" rel="nofollow">VTK</a> before, but here it goes.</p>
<p>Good thing about opensource software is that you can check the source code directly. Better yet, if there's web-based version control browser, we can talk about it online like this.</p>
<p>Let's see <a href=... | 4 | 2009-06-13T08:03:05Z | [
"python",
"3d",
"vtk"
] |
Binary file IO in python, where to start? | 967,652 | <p>As a self-taught python hobbyist, how would I go about learning to import and export binary files using standard formats?</p>
<p>I'd like to implement a script that takes ePub ebooks (XHTML + CSS in a zip) and converts it to a mobipocket (Palmdoc) format in order to allow the Amazon Kindle to read it (as part of a ... | 10 | 2009-06-09T00:25:36Z | 967,884 | <p>You should probably start with the <a href="http://docs.python.org/library/struct.html">struct</a> module, as you pointed to in your question, and of course, open the file as a binary.</p>
<p>Basically you just start at the beginning of the file and pick it apart piece by piece. It's a hassle, but not a huge probl... | 9 | 2009-06-09T02:19:37Z | [
"python",
"binary",
"io",
"epub",
"mobipocket"
] |
Binary file IO in python, where to start? | 967,652 | <p>As a self-taught python hobbyist, how would I go about learning to import and export binary files using standard formats?</p>
<p>I'd like to implement a script that takes ePub ebooks (XHTML + CSS in a zip) and converts it to a mobipocket (Palmdoc) format in order to allow the Amazon Kindle to read it (as part of a ... | 10 | 2009-06-09T00:25:36Z | 970,191 | <p>For teaching yourself python tools that work with binary files,
<a href="http://www.pythonchallenge.com/" rel="nofollow">this will get you going</a>. Fun too. Exercises with binaries, zips, images... lots more.</p>
| 0 | 2009-06-09T13:50:12Z | [
"python",
"binary",
"io",
"epub",
"mobipocket"
] |
Binary file IO in python, where to start? | 967,652 | <p>As a self-taught python hobbyist, how would I go about learning to import and export binary files using standard formats?</p>
<p>I'd like to implement a script that takes ePub ebooks (XHTML + CSS in a zip) and converts it to a mobipocket (Palmdoc) format in order to allow the Amazon Kindle to read it (as part of a ... | 10 | 2009-06-09T00:25:36Z | 970,282 | <p>If you want to construct and analyse binary files the struct module will give you the basic tools, but it isn't very friendly, especially if you want to look at things that aren't a whole number of bytes.</p>
<p>There are a few modules that can help, such as <a href="http://pypi.python.org/pypi/BitVector" rel="nofo... | 2 | 2009-06-09T14:08:27Z | [
"python",
"binary",
"io",
"epub",
"mobipocket"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 967,666 | <p>String formatting under python 2.x should do it for you:</p>
<pre><code>>>> print '%.2f' % 315.15321531321
315.15
</code></pre>
<p>This limits the string representation to just 2 decimal places. Note that if you use <code>round(315.153215, 2)</code>, you'll end up with another float value, which is natura... | 12 | 2009-06-09T00:32:27Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 967,670 | <p>If you just want to display it shortened, you can use the <code>"%f"</code> formating flag:</p>
<pre><code>value = 315.123123123
print "Value is: %.2f" % value
</code></pre>
<p>If you want to really cut off the "additional" digits, do something like:</p>
<pre><code>from math import trunc
value = trunc(value*100)/... | 2 | 2009-06-09T00:33:23Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 967,671 | <p>Built-in function <code>round()</code>:</p>
<pre><code>>>> num = 315.1532153132
>>> round(num, 2)
3.1499999999999998
</code></pre>
| 1 | 2009-06-09T00:33:44Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 967,676 | <p>You have several options - you can round the number using round(), however this can introduce some inaccuracies (315.15 might round to 315.150000003 for example). If you're just looking to truncate the value of the float when you're displaying it, you can specify the width of the output using printf("%.2f", mynumber... | 1 | 2009-06-09T00:34:52Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 967,702 | <p>If you're working with currency amounts, I strongly recommend that you use Python's decimal class instead: <a href="http://docs.python.org/library/decimal.html" rel="nofollow">http://docs.python.org/library/decimal.html</a></p>
| 5 | 2009-06-09T00:50:08Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 22,250,876 | <p>Looks like print "%.2f" does rounding as well.
Here is Python code that rounds and truncates </p>
<pre><code>num = 315.15627
print "rounded = %.2f" % num
print "truncated = %.2f" % (int(num*100)/float(100))
rounded = 315.16
truncated = 315.15
</code></pre>
| 3 | 2014-03-07T13:04:33Z | [
"python",
"truncate"
] |
python truncate after a hundreds? | 967,661 | <p>How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15</p>
<p>how do i do that?</p>
| 8 | 2009-06-09T00:29:59Z | 27,807,216 | <p>When working with <code>Decimal</code> types and currency, where the amount needs to be precise, here is what I came up with for truncating to cents (hundredths):</p>
<pre><code>amount = Decimal(long(amount * 100)) / Decimal(100)
</code></pre>
<p><strong>A little history</strong>: I tried <code>quantize</code> but... | 0 | 2015-01-06T21:09:36Z | [
"python",
"truncate"
] |
Image distortion after sending through a WSGI app in Python | 967,826 | <p>A lot of the time when I send image data over WSGI (using <code>wsgiref</code>), the image comes out distorted. As an example, examine the following:</p>
<p><img src="http://evanfosmark.com/files/goog.gif" alt="distorted Google logo" /></p>
| 1 | 2009-06-09T01:55:14Z | 967,895 | <p>Maybe the result is getting truncated? Try <code>wget</code> or <code>curl</code> to fetch the file directly and <code>cmp</code> it to the original image; that should help debug it. Beyond that, post your full code and environment details even if it's simple.</p>
| 0 | 2009-06-09T02:28:37Z | [
"python",
"wsgi"
] |
Image distortion after sending through a WSGI app in Python | 967,826 | <p>A lot of the time when I send image data over WSGI (using <code>wsgiref</code>), the image comes out distorted. As an example, examine the following:</p>
<p><img src="http://evanfosmark.com/files/goog.gif" alt="distorted Google logo" /></p>
| 1 | 2009-06-09T01:55:14Z | 968,042 | <p>As you haven't posted the code, here is a simple code which correctly works
with python 2.5 on windows</p>
<pre><code>from wsgiref.simple_server import make_server
def serveImage(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'image/png')]
start_response(status, headers)
r... | 3 | 2009-06-09T03:44:22Z | [
"python",
"wsgi"
] |
Image distortion after sending through a WSGI app in Python | 967,826 | <p>A lot of the time when I send image data over WSGI (using <code>wsgiref</code>), the image comes out distorted. As an example, examine the following:</p>
<p><img src="http://evanfosmark.com/files/goog.gif" alt="distorted Google logo" /></p>
| 1 | 2009-06-09T01:55:14Z | 968,045 | <p>It had to do with <code>\n</code> not being converted properly. I'd like to thank Alex Martelli for pointing me in the right direction.</p>
| 1 | 2009-06-09T03:45:18Z | [
"python",
"wsgi"
] |
Installed apps in Django - what about versions? | 967,855 | <p>After looking at the reusable apps chapter of Practical Django Projects and listening to the DjangoCon (Pycon?) lecture, there seems to be an emphasis on making your apps pluggable by installing them into the Python path, namely site-packages. </p>
<p>What I don't understand is what happens when the version of one ... | 1 | 2009-06-09T02:08:14Z | 967,885 | <p>Having multiple versions of the same package gets messy (setuptools can do it, though).</p>
<p>I've found it cleaner to put each project in its own <code>virtualenv</code>. We use <code>virtualevwrapper</code> to manage the virtualenvs easily, and the <code>--no-site-packages</code> option to make every project rea... | 5 | 2009-06-09T02:19:49Z | [
"python",
"django",
"version-control"
] |
Installed apps in Django - what about versions? | 967,855 | <p>After looking at the reusable apps chapter of Practical Django Projects and listening to the DjangoCon (Pycon?) lecture, there seems to be an emphasis on making your apps pluggable by installing them into the Python path, namely site-packages. </p>
<p>What I don't understand is what happens when the version of one ... | 1 | 2009-06-09T02:08:14Z | 968,244 | <p>You definitely don't want to put your Django apps into site-packages if you have more than one Django site.</p>
<p>The best way, as Ken Arnold answered, is to use Ian Bicking's <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> (Virtual Python Environment Builder). This is especially tr... | 0 | 2009-06-09T05:11:28Z | [
"python",
"django",
"version-control"
] |
Installed apps in Django - what about versions? | 967,855 | <p>After looking at the reusable apps chapter of Practical Django Projects and listening to the DjangoCon (Pycon?) lecture, there seems to be an emphasis on making your apps pluggable by installing them into the Python path, namely site-packages. </p>
<p>What I don't understand is what happens when the version of one ... | 1 | 2009-06-09T02:08:14Z | 969,345 | <p>What we do.</p>
<p>We put only "3rd-party" stuff in site-packages. Django, XLRD, PIL, etc.</p>
<p>We keep our overall project structured as a collection of packages and Django projects. Each project is a portion of the overall site. We have two separate behaviors for port 80 and port 443 (SSL).</p>
<pre><code>... | 0 | 2009-06-09T10:51:21Z | [
"python",
"django",
"version-control"
] |
Python Advice for a beginner. Regex, Dictionaries etc? | 968,018 | <p>I'm writing my second python script to try and parse the contents of a config file and would like some noob advice. I'm not sure if its best to use regex to parse my script since its multiple lines? I've also been reading about dictionaries and wondered if this would be good practice. I'm not necessarily looking for... | 3 | 2009-06-09T03:34:33Z | 968,029 | <p>I don't think a regex is adequate for parsing something like this. You could look at a true parser, such as <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a>. Or if the file format is within your control, you might consider XML. There are standard Python libraries for parsing that.</p>
| 2 | 2009-06-09T03:40:27Z | [
"python",
"regex",
"dictionary",
"configuration-files"
] |
Python Advice for a beginner. Regex, Dictionaries etc? | 968,018 | <p>I'm writing my second python script to try and parse the contents of a config file and would like some noob advice. I'm not sure if its best to use regex to parse my script since its multiple lines? I've also been reading about dictionaries and wondered if this would be good practice. I'm not necessarily looking for... | 3 | 2009-06-09T03:34:33Z | 968,066 | <p>There are numorous existing alternatives for this task, json, pickle and yaml to name 3. Unless you really want to implement this yourself, you should use one of these. Even if you do roll your own, following the format of one of the above is still a good idea. </p>
<p>Also, it's a much better idea to use a parser/... | 5 | 2009-06-09T03:51:14Z | [
"python",
"regex",
"dictionary",
"configuration-files"
] |
Python Advice for a beginner. Regex, Dictionaries etc? | 968,018 | <p>I'm writing my second python script to try and parse the contents of a config file and would like some noob advice. I'm not sure if its best to use regex to parse my script since its multiple lines? I've also been reading about dictionaries and wondered if this would be good practice. I'm not necessarily looking for... | 3 | 2009-06-09T03:34:33Z | 968,115 | <p><a href="http://docs.python.org/library/configparser.html" rel="nofollow">ConfigParser</a> module from the standard library is probably the most Pythonic and staight-forward way to parse a configuration file that your python script is using.</p>
<p>If you are restricted to using the particular format you have outli... | 4 | 2009-06-09T04:21:11Z | [
"python",
"regex",
"dictionary",
"configuration-files"
] |
Python Advice for a beginner. Regex, Dictionaries etc? | 968,018 | <p>I'm writing my second python script to try and parse the contents of a config file and would like some noob advice. I'm not sure if its best to use regex to parse my script since its multiple lines? I've also been reading about dictionaries and wondered if this would be good practice. I'm not necessarily looking for... | 3 | 2009-06-09T03:34:33Z | 968,304 | <p>If you can change the configuration file format, you can directly write your file as a Python file.</p>
<h3>config.py</h3>
<pre><code>job = {
'Name' : "host.domain.com-foo",
'Client' : "host.domain.com-fd",
'JobDefs' : "DefaultJob",
'FileSet' : "local",
'Write Bootstrap' : "/etc/foo/host.domain.com-foo.b... | 8 | 2009-06-09T05:32:10Z | [
"python",
"regex",
"dictionary",
"configuration-files"
] |
Python Advice for a beginner. Regex, Dictionaries etc? | 968,018 | <p>I'm writing my second python script to try and parse the contents of a config file and would like some noob advice. I'm not sure if its best to use regex to parse my script since its multiple lines? I've also been reading about dictionaries and wondered if this would be good practice. I'm not necessarily looking for... | 3 | 2009-06-09T03:34:33Z | 968,307 | <p>If your config file can be turned into a python file, just make it a dictionary and import the module.</p>
<pre><code>Job = { "Name" : "host.domain.com-foo",
"Client" : "host.domain.com-fd",
"JobDefs" : "DefaultJob",
"FileSet" : "local",
"Write BootStrap" : "/etc/foo/host.domain.com-... | 5 | 2009-06-09T05:32:44Z | [
"python",
"regex",
"dictionary",
"configuration-files"
] |
installing python libraries | 968,116 | <p>Ok, so i've downloaded the following library:
<a href="http://www.lag.net/paramiko/" rel="nofollow">http://www.lag.net/paramiko/</a></p>
<p>and i can't seem to figure out how to install on my local machine:
Mac OS X 10.4.11</p>
| 1 | 2009-06-09T04:21:27Z | 968,137 | <p>To use the package that you got from the web-site: "python setup.py install
"</p>
<p>My advice is to use easy_install instead of downloading packages straight from the project web-site.</p>
<p>To do this, you must first install <a href="http://pypi.python.org/pypi/setuptools">setuptools</a>.</p>
<p>Then just use ... | 6 | 2009-06-09T04:31:10Z | [
"python",
"package-management"
] |
How to isolate a single color in an image | 968,317 | <p>I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish. </p>
<p>I tried to take only the red color channel but this includes the white spaces in the Image too. </p>
<p>What is a good way to do that?</p>
| 1 | 2009-06-09T05:36:01Z | 968,336 | <p>Use a different color space: <a href="http://en.wikipedia.org/wiki/HSL_color_space" rel="nofollow">http://en.wikipedia.org/wiki/HSL_color_space</a></p>
| 4 | 2009-06-09T05:41:02Z | [
"python",
"image-processing",
"opencv",
"color-space"
] |
How to isolate a single color in an image | 968,317 | <p>I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish. </p>
<p>I tried to take only the red color channel but this includes the white spaces in the Image too. </p>
<p>What is a good way to do that?</p>
| 1 | 2009-06-09T05:36:01Z | 968,351 | <p>How about using a formular like r' = r-(g+b)?</p>
| 0 | 2009-06-09T05:45:06Z | [
"python",
"image-processing",
"opencv",
"color-space"
] |
How to isolate a single color in an image | 968,317 | <p>I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish. </p>
<p>I tried to take only the red color channel but this includes the white spaces in the Image too. </p>
<p>What is a good way to do that?</p>
| 1 | 2009-06-09T05:36:01Z | 2,204,755 | <p>Use the HSV colorspace. Select pixels that have an H value in the range that you consider to contain "red," and an S value large enough that you do not consider it to be neutral, maroon, brown, or pink. You might also need to throw out pixels with low V's. The H dimension is a circle, and red is right where the c... | 1 | 2010-02-05T02:56:26Z | [
"python",
"image-processing",
"opencv",
"color-space"
] |
Calculate the center of a contour/Area | 968,332 | <p>I'm working on a Image-processing chain that seperates a single object by color and contour and then calculates the y-position of this object. </p>
<p>How do I calculate the center of a contour or area with OpenCV?</p>
<p>Opencv links:</p>
<ul>
<li><a href="http://opencv.willowgarage.com/wiki/" rel="nofollow">htt... | 4 | 2009-06-09T05:39:21Z | 968,984 | <p>I don't exactly know what OpenCV is, but I would suggest this:</p>
<p>The Selected cluster of pixels has a maximum width at one point - w - so lets say the area has w vertical columns of pixels. Now I would weight the columns according to how many pixels the column contains, and use these column-wights to determine... | -2 | 2009-06-09T09:06:02Z | [
"python",
"image-processing",
"opencv",
"contour"
] |
Calculate the center of a contour/Area | 968,332 | <p>I'm working on a Image-processing chain that seperates a single object by color and contour and then calculates the y-position of this object. </p>
<p>How do I calculate the center of a contour or area with OpenCV?</p>
<p>Opencv links:</p>
<ul>
<li><a href="http://opencv.willowgarage.com/wiki/" rel="nofollow">htt... | 4 | 2009-06-09T05:39:21Z | 969,506 | <p>You can get the center of mass in the y direction by first calculating the <a href="http://www.cs.indiana.edu/cgi-pub/oleykin/website/OpenCVHelp/ref/OpenCVRef%5FCv.htm#decl%5FcvMoments">Moments</a>. Then the center of mass is given by <code>yc = M01 / M00</code>, where M01 and M00 are fields in the structure returne... | 10 | 2009-06-09T11:31:19Z | [
"python",
"image-processing",
"opencv",
"contour"
] |
Python regex for alphanumerics not working | 968,553 | <pre><code>from django import forms
class ActonForm(forms.Form):
creator = forms.RegexField('^[a-zA-Z0-9\-' ]$',max_length=30, min_length=3)
data = {'creator': 'hello'
}
f = ActonForm(data)
print f.is_valid()
</code></pre>
<p>Why doesn't this work? have i made a wrong regular expression? I wanted a name f... | -1 | 2009-06-09T06:55:22Z | 968,564 | <p>It kind of shows in the syntax highlighting. The apostrophe in the regex isn't escaped, it should be like this:</p>
<pre><code>forms.RegexField('^[a-zA-Z0-9\\-\' ]$',max_length=30, min_length=3)
</code></pre>
<p><strong>Edit:</strong> When escaping things in the regular expression, you need double backslashes. I d... | 1 | 2009-06-09T06:57:53Z | [
"python",
"regex",
"google-app-engine"
] |
breakpoint in eclipse for appengine | 968,701 | <p>I have pydev on eclipse and would like to debug handlers. I put breakpoint on a handler and start project in debug mode. When I click on the hyperlink corresponding to handler the control does not come back to breakpoint. Am I missing something here?
Also the launch is for google app engine application in python.</p... | 3 | 2009-06-09T07:45:09Z | 969,003 | <p>The simplest way to debug is to use the builtin python module <code>pdb</code> and debug from the shell.</p>
<p>Just set the trace in the handler you want to debug.</p>
<pre><code>import pdb
pdb.set_trace()
</code></pre>
<p>How do U run the server, from within the eclipse or from the shell. If it is from the shel... | 0 | 2009-06-09T09:11:18Z | [
"python",
"eclipse",
"debugging",
"google-app-engine",
"pydev"
] |
breakpoint in eclipse for appengine | 968,701 | <p>I have pydev on eclipse and would like to debug handlers. I put breakpoint on a handler and start project in debug mode. When I click on the hyperlink corresponding to handler the control does not come back to breakpoint. Am I missing something here?
Also the launch is for google app engine application in python.</p... | 3 | 2009-06-09T07:45:09Z | 969,586 | <p>I'm using eclipse with PyDev with appengine and I debug all the time, it's completely possible !</p>
<p>What you have to do is start the program in debug, but you have to start the dev_appserver in debug, not the handler directly. The main module you have to debug is:</p>
<pre><code><path_to_gae>/dev_appserv... | 4 | 2009-06-09T11:49:27Z | [
"python",
"eclipse",
"debugging",
"google-app-engine",
"pydev"
] |
fetching row numbers in a database-independent way - django | 969,074 | <p>Let's say that I have a <strong>'Scores'</strong> table with fields <strong>'User'</strong>,<strong>'ScoreA'</strong>, <strong>'ScoreB'</strong>, <strong>'ScoreC'</strong>. In a leaderboard view I fetch and order a queryset by any one of these score fields that the visitor selects. The template paginates the queryse... | 0 | 2009-06-09T09:31:18Z | 969,233 | <p>Why can't you compute the rank in the template?</p>
<pre><code>{% for row in results_to_display %}
<tr><td>{{forloop.counter}}</td><td>{{row.scorea}}</td>...
{% endfor %}
</code></pre>
<p>Or, you can compute the rank in the view function.</p>
<pre><code>def fetch_ranked_scores( r... | 2 | 2009-06-09T10:20:35Z | [
"python",
"django",
"django-orm"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 969,141 | <p>Try <code>help()</code> or <code>dir()</code>. AFAIR there's no builtin support for pdf-related tasks in plain Python installation. Another way to find help for Python modules is to google ;)</p>
<p>Docs: </p>
<p><a href="http://docs.python.org/library/functions.html#help" rel="nofollow">http://docs.python.org/lib... | 0 | 2009-06-09T09:48:11Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 969,283 | <p>In console type help(object):</p>
<pre><code>Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(dir)
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) -> list... | 1 | 2009-06-09T10:36:05Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 969,323 | <p>You can use help to access the docstrings of the different modules you have imported, e.g., try the following:</p>
<pre><code>help(math)
</code></pre>
<p>and you'll get an error,</p>
<pre><code>import math
help(math)
</code></pre>
<p>and you will get a list of the available methods in the module, but only AFTER ... | 4 | 2009-06-09T10:45:55Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 970,043 | <p>help( "modules")</p>
<pre><code>>>> help( "modules" )
Please wait a moment while I gather a list of all available modules...
C:\Program Files\Python26\lib\pkgutil.py:110: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to ... | 4 | 2009-06-09T13:20:43Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 970,106 | <p>The <code>pydoc -k</code> flag searches the documentation.</p>
<pre><code>pydoc -k <keyword>
Search for a keyword in the synopsis lines of all available modules.
</code></pre>
<p>From a terminal, run..</p>
<pre><code>$ pydoc -k pdf
</code></pre>
<p>..for example:</p>
<pre><code>$ pydoc -k pdf
PdfImage... | 7 | 2009-06-09T13:30:28Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 970,501 | <p>(Years later) I now use <a href="https://pip.pypa.io/en/stable/reference/pip_search/" rel="nofollow">pip search</a><br>
and <a href="https://pypi.python.org/pypi/yolk/0.4.3" rel="nofollow">yolk</a> -M or -H packagename: -M for metadata, -H to browse to its web page .</p>
<hr>
<p>To search PyPI (Python Package Inde... | 2 | 2009-06-09T14:48:35Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 4,670,427 | <p>You can search for modules containing "pdf" in their description by running the command <code>help("modules pdf")</code>.</p>
| 4 | 2011-01-12T15:20:34Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 24,565,848 | <p>Thinking recursively:</p>
<pre><code>>>> help(help)
Help on _Helper in module site object:
class _Helper(builtins.object)
| Define the builtin 'help'.
| This is a wrapper around **pydoc.help** (with a twist).
|
...
</code></pre>
<p>from here:</p>
<pre><code>>>> import pydoc
>>>... | 1 | 2014-07-04T02:24:08Z | [
"python"
] |
How to search help using python console | 969,093 | <p>Is there any way to search for a particular package/function using keywords in the Python console?</p>
<p>For example, I may want to search "pdf" for pdf related tasks.</p>
| 6 | 2009-06-09T09:37:17Z | 26,696,112 | <p>pip is an excellent resource. If pip is installed (if you don't have it, instructions are <a href="http://pip.readthedocs.org/en/latest/installing.html" rel="nofollow">here</a>), then using the Windows command shell you can do the following:</p>
<pre><code>pip search pdf
</code></pre>
<p>It returns a plethora of o... | 3 | 2014-11-02T04:35:09Z | [
"python"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 969,134 | <p>If you don't mind a switch to Subversion, Eclipse has its SubClipse plugin.</p>
| 1 | 2009-06-09T09:46:01Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 969,176 | <p>I believe Eclipse does have CVS support built in - or at least it did have when I last used it a couple of years ago.</p>
<p>For further information on how to use CVS with Eclipse see the <a href="http://wiki.eclipse.org/index.php/CVS%5FFAQ" rel="nofollow">Eclipse CVS FAQ</a></p>
| 0 | 2009-06-09T09:59:04Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 969,236 | <p>I tried Eclipse+Subclipse and Eclipse+Bazaar plugin. Both work very well, but I have found that Tortoise versions of those version source control tools are so good that I resigned from Eclipse plugins. On Windows Tortoise XXX are my choice. They integrate with shell (Explorer or TotalCommander), changes icon overlay... | 1 | 2009-06-09T10:20:47Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 969,541 | <p>As others have indicated, there are plugins available for Eclipse for SVN, Bazar, Mercurial and Git.</p>
<p>Even so, despite their presence, I find using the command line the most comfortable.</p>
<pre><code>svn commit -m 'now committing'
</code></pre>
<p>Assuming you are not committing for more than several time... | 1 | 2009-06-09T11:41:24Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 969,642 | <p>Last time I tried this, Eclipse did not support direct access to local repositories in the same way that command line cvs does because command line cvs has both client and server functionality whereas Eclipse only has client functionality and needs to go through (e.g.) pserver, so you would probably need to have a c... | 4 | 2009-06-09T11:56:44Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 976,961 | <blockquote>
<p>I recently moved my house and don't have yet an access to internet.</p>
</blockquote>
<p>CVS and SVN are the Centralized Version control systems. Rather than having to install them on your local system just for single version control, you could use DVCS like Mercurial or Git.</p>
<p>When you clone a... | 0 | 2009-06-10T17:12:59Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 976,996 | <p>I would definitely recommend switching over to a different VCSâI prefer <a href="http://selenic.com/mercurial/" rel="nofollow">Mercurial</a>, along with a lot of the Python community. That way, you'll be able to work locally, but still have the ability to publish your changes to the world later.</p>
<p>You can in... | 1 | 2009-06-10T17:21:03Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
Eclipse + local CVS + PyDev | 969,121 | <p>I tried several Python IDEs (on Windows platform) but finally I found only Eclipse + PyDev meeting my needs. This set of tools is really comfortable and easy to use. I'm currently working on a quite bigger project. I'd like to have a possibility to use CVS or any other version control system which would be installed... | 4 | 2009-06-09T09:43:21Z | 977,044 | <p>I use Eclipse with a local CVS repository without issue. The only catch is that you cannot use the ":local:" CVS protocol. Since you're on Windows, I recommend installing <a href="http://tortoisecvs.org/" rel="nofollow">TortoiseCVS</a> and then configuring the included CVSNT server as follows:</p>
<ul>
<li>Control ... | 0 | 2009-06-10T17:29:56Z | [
"python",
"eclipse",
"cvs",
"pydev"
] |
How to agnostically link any object/Model from another Django Model? | 969,211 | <p>I'm writing a simple CMS based on Django. Most content management systems rely on having a fixed page, on a fixed URL, using a template that has one or many editable regions. To have an editable region, you require a Page. For the system to work out which page, you require the URL.</p>
<p>The problem comes when you... | 1 | 2009-06-09T10:11:28Z | 969,300 | <p>django-tagging uses Django's <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/" rel="nofollow">contenttypes</a> framework. The docs do a much better job of explaining it than I can, but the simplest description of it would be "generic foreign key that can point to any other model."</p>
<p>Thi... | 6 | 2009-06-09T10:39:50Z | [
"python",
"django",
"django-models",
"content-management-system"
] |
How to agnostically link any object/Model from another Django Model? | 969,211 | <p>I'm writing a simple CMS based on Django. Most content management systems rely on having a fixed page, on a fixed URL, using a template that has one or many editable regions. To have an editable region, you require a Page. For the system to work out which page, you require the URL.</p>
<p>The problem comes when you... | 1 | 2009-06-09T10:11:28Z | 1,201,454 | <p>You want a way to display some object-specific content on a generic template, given a specific object, correct?</p>
<p>In order to support both models and other objects, we need two intermediate models; one to handle strings, and one to handle models. We could do it with one model, but this is less performant. Thes... | 2 | 2009-07-29T16:24:58Z | [
"python",
"django",
"django-models",
"content-management-system"
] |
How to agnostically link any object/Model from another Django Model? | 969,211 | <p>I'm writing a simple CMS based on Django. Most content management systems rely on having a fixed page, on a fixed URL, using a template that has one or many editable regions. To have an editable region, you require a Page. For the system to work out which page, you require the URL.</p>
<p>The problem comes when you... | 1 | 2009-06-09T10:11:28Z | 1,223,361 | <p>It's pretty straightforward to use the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#ref-contrib-contenttypes" rel="nofollow">contenttypes</a> framework to implement the lookup strategy you are describing:</p>
<pre><code>class Block(models.Model):
content_type = models.ForeignKey(Conte... | 2 | 2009-08-03T16:43:19Z | [
"python",
"django",
"django-models",
"content-management-system"
] |
Function parameters hint Eclipse with PyDev | 969,466 | <p>Seems like newbie's question, but I just can't find the answer. Can I somehow see function parameters hint like in Visual Studio by pressing Ctrl+Shift+Space when cursor is in function call like this:</p>
<pre><code>someObj.doSomething("Test", "hello, wold", 4|)
</code></pre>
<p>where | is my cursor position. Ctrl... | 6 | 2009-06-09T11:20:50Z | 969,483 | <p>Try "<code>CTRL+space</code>" after a '<code>,</code>', not after a parameter.<br />
The function parameters are displayed just after the '<code>(</code>' or after a '<code>,</code>' + "<code>CTRL+space</code>".</p>
| 10 | 2009-06-09T11:26:06Z | [
"python",
"eclipse",
"pydev"
] |
Function parameters hint Eclipse with PyDev | 969,466 | <p>Seems like newbie's question, but I just can't find the answer. Can I somehow see function parameters hint like in Visual Studio by pressing Ctrl+Shift+Space when cursor is in function call like this:</p>
<pre><code>someObj.doSomething("Test", "hello, wold", 4|)
</code></pre>
<p>where | is my cursor position. Ctrl... | 6 | 2009-06-09T11:20:50Z | 1,606,937 | <p>Parameters will show up just after a '(', which is how I re-displayed mine for ages. I recently discovered that 'CTRL + Shift + Space' will show the parameters anywhere in a function call. Saved me some valuable seconds.</p>
| 3 | 2009-10-22T12:40:02Z | [
"python",
"eclipse",
"pydev"
] |
Can I automatically change my PYTHONPATH when activating/deactivating a virtualenv? | 969,553 | <p>I would like to have a different PYTHONPATH from my usual in a particular virtualenv. How do I set this up automatically? I realize that it's possible to hack the <code>bin/activate</code> file, is there a better/more standard way?</p>
| 13 | 2009-06-09T11:44:14Z | 969,703 | <p>Here is the hacked version of <code>bin/activate</code> for reference. It sets the PYTHONPATH correctly, but unsetting does not work. </p>
<pre><code>
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH=... | 1 | 2009-06-09T12:09:29Z | [
"python",
"virtualenv"
] |
Can I automatically change my PYTHONPATH when activating/deactivating a virtualenv? | 969,553 | <p>I would like to have a different PYTHONPATH from my usual in a particular virtualenv. How do I set this up automatically? I realize that it's possible to hack the <code>bin/activate</code> file, is there a better/more standard way?</p>
| 13 | 2009-06-09T11:44:14Z | 969,727 | <p>This <a href="http://groups.google.com/group/django-users/msg/5316bd02d34b7544">django-users post</a> is probably going to help you a lot. It suggests using <a href="http://www.doughellmann.com/projects/virtualenvwrapper/">virtualenvwrapper</a> to wrap virtualenv, to use the <a href="http://www.doughellmann.com/docs... | 19 | 2009-06-09T12:15:34Z | [
"python",
"virtualenv"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 969,758 | <pre><code>def postings(posts):
sets = (set(l) for l in posts)
return sorted(reduce(set.intersection, sets))
</code></pre>
<p>... you could try and take advantage of the fact that the lists are ordered, but since reduce, generator expressions and set are all implemented in C, you'll probably have a hard time d... | 6 | 2009-06-09T12:22:43Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 969,823 | <p>If these are really long (or even infinite) sequences, and you don't want to load everything into a set in advance, you can implement this with a 1-item lookahead on each iterator.</p>
<pre><code>EndOfIter = object() # Sentinel value
class PeekableIterator(object):
def __init__(self, it):
self.it = it
... | 3 | 2009-06-09T12:35:22Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 969,967 | <p>What about this:</p>
<pre><code>import heapq
def inalliters(iterators):
heap=[(iterator.next(),iterator) for iterator in iterators]
heapq.heapify(heap)
maximal = max(heap)[0]
while True:
value,iterator = heapq.heappop(heap)
if maximal==value: yield value
nextvalue=iterator.next()
heapq.heap... | 2 | 2009-06-09T13:09:15Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 969,987 | <p>This solution will compute the intersection of your iterators. It works by advancing the iterators one step at a time and looking for the same value in all of them. When found, such values are yielded -- this makes the <code>intersect</code> function a generator itself.</p>
<pre><code>import operator
def intersect... | 6 | 2009-06-09T13:11:37Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 970,062 | <p>I want to show that there's an elegant solution, which <strong>only iterates forward once</strong>. Sorry, I don't know the Python well enough, so I use fictional classes. This one reads <code>input</code>, an array of iterators, and writes to <code>output</code> on-the-fly without ever going back or using any array... | 1 | 2009-06-09T13:23:02Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 978,816 | <pre><code>import heapq, itertools
def intersect(*its):
for key, values in itertools.groupby(heapq.merge(*its)):
if len(list(values)) == len(its):
yield key
>>> list(intersect(*postings))
[100, 322]
</code></pre>
| 15 | 2009-06-11T00:49:14Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
Joining a set of ordered-integer yielding Python iterators | 969,709 | <p>Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence.</p>
<p>After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Pytho... | 16 | 2009-06-09T12:11:00Z | 18,188,205 | <p>This one runs in <code>O(n*m)</code> where <code>n</code> is the sum of all iterator lengths, and <code>m</code> is the number of lists. It can be made <code>O(n*logm)</code> by using a heap in line 6.</p>
<pre><code>def intersection(its):
if not its: return
vs = [next(it) for it in its]
m = max(vs)
while ... | 0 | 2013-08-12T13:26:36Z | [
"python",
"join",
"code-golf",
"iterator",
"generator"
] |
automatic keystroke to stay logged in | 969,849 | <p>I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I... | 1 | 2009-06-09T12:40:42Z | 969,860 | <p>wrap the calling of your python app in a .bat file and put a shortcut to that .bat file in startup. </p>
| 1 | 2009-06-09T12:42:34Z | [
"python",
"authentication"
] |
automatic keystroke to stay logged in | 969,849 | <p>I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I... | 1 | 2009-06-09T12:40:42Z | 969,863 | <p>If you use firefox, just install the <a href="https://addons.mozilla.org/en-US/firefox/addon/115" rel="nofollow">ReloadEvery</a> extension.</p>
| 1 | 2009-06-09T12:43:46Z | [
"python",
"authentication"
] |
automatic keystroke to stay logged in | 969,849 | <p>I have a web based email application that logs me out after 10 minutes of inactivity ("For security reasons"). I would like to write something that either a) imitates a keystroke b) pings an ip or c) some other option every 9 minutes so that I stay logged in. I am on my personal laptop in an office with a door, so I... | 1 | 2009-06-09T12:40:42Z | 969,870 | <p>Assuming you use Windows, you can add a bat file containing the python run command in the Startup folder.</p>
<p>Example keeploggedin.bat</p>
<pre><code>C:\Steve\Projects\Python> python pytest.py
</code></pre>
| 3 | 2009-06-09T12:45:44Z | [
"python",
"authentication"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.