title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Algorithm should I create a new thread? | 1,808,806 | <p>Is there an algorithm that checks whether creating a new thread pays off performance wise?
I'll set a maximum of threads that can be created anyway but if I add just one task it wouldn't be an advantage to start a new thread for that.
The programming language I use is python.</p>
<h2>Edit 1#</h2>
<p>Can this quest... | 0 | 2009-11-27T13:33:46Z | 1,808,868 | <p>python (at least standard CPython) is a special case, because it won't run more than one thread at a time, therefore if you are doing number-crunching on a multiple cores, then pure python isn't really the best choice.</p>
<p>In CPython, while running python code, only one thread is executing. It protected by the <... | 4 | 2009-11-27T13:45:28Z | [
"python",
"math",
"multithreading"
] |
Python doctest: Skip entire block? | 1,809,037 | <p>I've got a Python module with docstrings in class methods, and a real-world example in the module docstring. The distinction is that the method-docstrings have been carefully crafted to be utterly repeatable tests, while the real-world example is just a copy'n'paste of the history from a Linux shell - which happened... | 7 | 2009-11-27T14:17:13Z | 1,809,089 | <p>If it's not an actual doctest by any means, you can just assign the value to a variable. For example,</p>
<pre><code>example_usage = """
Real-world example:
# python2.5
...
"""
</code></pre>
<p>will cause that "test" to not be evaluated.</p>
<p>It might be better to use <code>__example_usage__</code> (or somet... | 2 | 2009-11-27T14:28:02Z | [
"python",
"doctest"
] |
Python doctest: Skip entire block? | 1,809,037 | <p>I've got a Python module with docstrings in class methods, and a real-world example in the module docstring. The distinction is that the method-docstrings have been carefully crafted to be utterly repeatable tests, while the real-world example is just a copy'n'paste of the history from a Linux shell - which happened... | 7 | 2009-11-27T14:17:13Z | 1,809,516 | <p>My solution has been to trim the the 3-character <code>>>></code> and <code>...</code> leaders where I want doctest to skip over them, making them 2-characters.</p>
<p>So</p>
<pre><code>"""
>>> from packagename import module
>>> module.show_real_world_usage()
'Hello world!'
"""
</code></... | 6 | 2009-11-27T16:00:58Z | [
"python",
"doctest"
] |
Python doctest: Skip entire block? | 1,809,037 | <p>I've got a Python module with docstrings in class methods, and a real-world example in the module docstring. The distinction is that the method-docstrings have been carefully crafted to be utterly repeatable tests, while the real-world example is just a copy'n'paste of the history from a Linux shell - which happened... | 7 | 2009-11-27T14:17:13Z | 7,622,355 | <p>Wrap the example in a function and then skip the function call:</p>
<pre><code>"""
>>> def example():
>>> from packagename import module
>>> module.show_real_world_usage()
>>> example() # doctest: +SKIP
'Hello world!'
"""
</code></pre>
| 8 | 2011-10-01T19:09:20Z | [
"python",
"doctest"
] |
NHibernate and python | 1,809,201 | <p>We have an existing C# project based on NHibernate and WPF. I am asked to convert it to Linux and to consider other implementation like Python. But for some reason, they like NHibernate a lot and want to keep it.</p>
<p>Do you know if it's possible to keep the NHibernate stuff and make it work with Python ? I am u... | 0 | 2009-11-27T14:50:07Z | 1,809,219 | <p>Check out Django. They have a nice ORM and I believe it has tools to attempt a reverse-engineer from the DB schema.</p>
| 0 | 2009-11-27T14:55:39Z | [
"python",
"nhibernate",
"orm"
] |
NHibernate and python | 1,809,201 | <p>We have an existing C# project based on NHibernate and WPF. I am asked to convert it to Linux and to consider other implementation like Python. But for some reason, they like NHibernate a lot and want to keep it.</p>
<p>Do you know if it's possible to keep the NHibernate stuff and make it work with Python ? I am u... | 0 | 2009-11-27T14:50:07Z | 1,809,238 | <p>What about running your project under Mono on Linux? Mono seems to support NHibernate, which means you may be able to get away with out rewriting large chunks of your application.</p>
<p>Also, if you really wanted to get Python in on the action, you could use IronPython along with Mono.</p>
| 2 | 2009-11-27T14:59:35Z | [
"python",
"nhibernate",
"orm"
] |
NHibernate and python | 1,809,201 | <p>We have an existing C# project based on NHibernate and WPF. I am asked to convert it to Linux and to consider other implementation like Python. But for some reason, they like NHibernate a lot and want to keep it.</p>
<p>Do you know if it's possible to keep the NHibernate stuff and make it work with Python ? I am u... | 0 | 2009-11-27T14:50:07Z | 1,809,266 | <p>NHibernate is not specific to C#, but it is specific to .NET.</p>
<p>IronPython is a .NET language from which you could use NHibernate.</p>
<p>.NET and NHibernate can run on Linux through Mono. I'm not sure how good Mono's support is for WPF.</p>
<p>I'm not sure if IronPython runs on Linux, but that would seem t... | 4 | 2009-11-27T15:06:04Z | [
"python",
"nhibernate",
"orm"
] |
NHibernate and python | 1,809,201 | <p>We have an existing C# project based on NHibernate and WPF. I am asked to convert it to Linux and to consider other implementation like Python. But for some reason, they like NHibernate a lot and want to keep it.</p>
<p>Do you know if it's possible to keep the NHibernate stuff and make it work with Python ? I am u... | 0 | 2009-11-27T14:50:07Z | 1,809,308 | <p><a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a> is the most powerful ORM in Python so far.</p>
| 1 | 2009-11-27T15:13:41Z | [
"python",
"nhibernate",
"orm"
] |
How to get the current open file line in python? | 1,809,232 | <p>Suppose you open a file, and do an seek() somewhere in the file, how do you know the current file line ?</p>
<p>(I personally solved with an ad-hoc file class that maps the seek position to the line after scanning the file, but I wanted to see other hints and to add this question to stackoverflow, as I was not able... | 6 | 2009-11-27T14:58:20Z | 1,809,342 | <p>Here's how I would approach the problem, using as much laziness as possible:</p>
<pre><code>from random import randint
from itertools import takewhile, islice
file = "/etc/passwd"
f = open(file, "r")
f.seek(randint(10,250))
pos = f.tell()
print "pos=%d" % pos
def countbytes(iterable):
bytes = 0
for item... | 3 | 2009-11-27T15:22:08Z | [
"python",
"file",
"seek",
"line-count"
] |
How to get the current open file line in python? | 1,809,232 | <p>Suppose you open a file, and do an seek() somewhere in the file, how do you know the current file line ?</p>
<p>(I personally solved with an ad-hoc file class that maps the seek position to the line after scanning the file, but I wanted to see other hints and to add this question to stackoverflow, as I was not able... | 6 | 2009-11-27T14:58:20Z | 1,809,372 | <p>When you use seek(), python gets to use pointer offsets to jump to the desired position in the file. But in order to know the current line number, you have to examine each character up to that position. So you might as well abandon seek() in favor of read():</p>
<p>Replace</p>
<pre><code>f = open(filename, "r")
f.... | 4 | 2009-11-27T15:32:45Z | [
"python",
"file",
"seek",
"line-count"
] |
python script optimization for app engine | 1,809,335 | <p>i have the following script i am using to scrap data from my uni website and insert into a GAE Db</p>
<pre><code>from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import re
import datetime
__author__ = "Nash Rafeeq"
url = "http://webspace.apiit.edu.my/schedule/timetable.jsp"
viewurl = "http... | 2 | 2009-11-27T15:20:38Z | 1,809,355 | <p><a href="http://en.wikipedia.org/wiki/Divide%5Fand%5Fconquer%5Falgorithm" rel="nofollow">Divide and conquer</a>.</p>
<ol>
<li>Make a list of tasks (e.g. urls to scrape/parse)</li>
<li>Add your tasks into a queue (<a href="http://code.google.com/appengine/docs/python/taskqueue/overview.html" rel="nofollow">appengine... | 4 | 2009-11-27T15:27:53Z | [
"python",
"google-app-engine"
] |
python script optimization for app engine | 1,809,335 | <p>i have the following script i am using to scrap data from my uni website and insert into a GAE Db</p>
<pre><code>from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import re
import datetime
__author__ = "Nash Rafeeq"
url = "http://webspace.apiit.edu.my/schedule/timetable.jsp"
viewurl = "http... | 2 | 2009-11-27T15:20:38Z | 1,809,446 | <p>The first thing you should do is rewrite your script to use the App Engine datastore directly. A large part of the time you're spending is undoubtedly because you're using HTTP requests (two per entry!) to insert data into your datastore. Using the datastore directly with <a href="http://code.google.com/appengine/do... | 2 | 2009-11-27T15:47:06Z | [
"python",
"google-app-engine"
] |
python script optimization for app engine | 1,809,335 | <p>i have the following script i am using to scrap data from my uni website and insert into a GAE Db</p>
<pre><code>from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import re
import datetime
__author__ = "Nash Rafeeq"
url = "http://webspace.apiit.edu.my/schedule/timetable.jsp"
viewurl = "http... | 2 | 2009-11-27T15:20:38Z | 1,809,770 | <p>hi according to tosh and nick i have modified the script as bellow </p>
<pre><code>from google.appengine.api import urlfetch
from BeautifulSoup import BeautifulSoup
from timkeeper.models import Intake
from google.appengine.ext import db
__author__ = "Nash Rafeeq"
url = "http://webspace.apiit.edu.my/schedule/tim... | 1 | 2009-11-27T16:57:25Z | [
"python",
"google-app-engine"
] |
Library for getting information from any windows on screen | 1,809,397 | <p>I am looking for a library to get some information about the active windows: a list of all the windows, absolute/relative position of the window, and the size.</p>
<p>There is a function in GTK+ called <code>get_window_list_toplevels()</code> or <code>get_root_window()</code> but I get only information for the wind... | 0 | 2009-11-27T15:38:18Z | 1,809,804 | <p><code>gdk_screen_get_toplevel_windows</code> (<a href="http://library.gnome.org/devel/gdk/stable/GdkScreen.html#gdk-screen-get-toplevel-windows" rel="nofollow">doc</a>) should return list of all toplevel windows on a given screen.</p>
| 0 | 2009-11-27T17:09:01Z | [
"c++",
"python",
"windows",
"gtk"
] |
Library for getting information from any windows on screen | 1,809,397 | <p>I am looking for a library to get some information about the active windows: a list of all the windows, absolute/relative position of the window, and the size.</p>
<p>There is a function in GTK+ called <code>get_window_list_toplevels()</code> or <code>get_root_window()</code> but I get only information for the wind... | 0 | 2009-11-27T15:38:18Z | 1,830,283 | <p>Window management works very differently on different platforms, so each major platform will probably need a separate back end.</p>
<p>Under Linux, you may want to look at <a href="http://library.gnome.org/devel/libwnck/stable/" rel="nofollow">libwnck</a> (Window Navigator Construction Kit) which provides the detai... | 0 | 2009-12-02T02:24:26Z | [
"c++",
"python",
"windows",
"gtk"
] |
Truncating unicode so it fits a maximum size when encoded for wire transfer | 1,809,531 | <p>Given a Unicode string and these requirements:</p>
<ul>
<li>The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape)</li>
<li>The encoded string has a maximum length</li>
</ul>
<p>For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 byt... | 22 | 2009-11-27T16:04:58Z | 1,809,553 | <p>For JSON formatting (unicode escape, e.g. <code>\uabcd</code>), I am using the following algorithm to achieve this:</p>
<ul>
<li>Encode the Unicode string into the backslash-escape format which it would eventually be in the JSON version</li>
<li>Truncate 3 bytes more than my final limit</li>
<li>Use a regular expre... | 1 | 2009-11-27T16:09:42Z | [
"python",
"json",
"unicode",
"truncate"
] |
Truncating unicode so it fits a maximum size when encoded for wire transfer | 1,809,531 | <p>Given a Unicode string and these requirements:</p>
<ul>
<li>The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape)</li>
<li>The encoded string has a maximum length</li>
</ul>
<p>For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 byt... | 22 | 2009-11-27T16:04:58Z | 1,809,570 | <p>One of UTF-8's properties is that it is easy to resync, that is find the unicode character boundaries easily in the encoded bytestream. All you need to do is to cut the encoded string at max length, then walk backwards from the end removing any bytes that are > 127 -- those are part of, or the start of a multibyte c... | 8 | 2009-11-27T16:12:30Z | [
"python",
"json",
"unicode",
"truncate"
] |
Truncating unicode so it fits a maximum size when encoded for wire transfer | 1,809,531 | <p>Given a Unicode string and these requirements:</p>
<ul>
<li>The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape)</li>
<li>The encoded string has a maximum length</li>
</ul>
<p>For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 byt... | 22 | 2009-11-27T16:04:58Z | 1,809,662 | <p>This will do for UTF8, If you like to do it in regex.</p>
<pre><code>import re
partial="\xc2\x80\xc2\x80\xc2"
re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$","",partial)
"\xc2\x80\xc2\x80"
</code></pre>
<p>Its cover from U+0080 (2 bytes) to U+10FFFF (4 bytes) utf8 strings</p>
<p... | 3 | 2009-11-27T16:33:49Z | [
"python",
"json",
"unicode",
"truncate"
] |
Truncating unicode so it fits a maximum size when encoded for wire transfer | 1,809,531 | <p>Given a Unicode string and these requirements:</p>
<ul>
<li>The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape)</li>
<li>The encoded string has a maximum length</li>
</ul>
<p>For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 byt... | 22 | 2009-11-27T16:04:58Z | 1,820,949 | <pre><code>def unicode_truncate(s, length, encoding='utf-8'):
encoded = s.encode(encoding)[:length]
return encoded.decode(encoding, 'ignore')
</code></pre>
<p>Here is an example for unicode string where each character is represented with 2 bytes in UTF-8: </p>
<pre><code>>>> unicode_truncate(u'абв... | 19 | 2009-11-30T16:45:24Z | [
"python",
"json",
"unicode",
"truncate"
] |
How do I create a unique property in python on google app engine? | 1,809,754 | <p>In some database technologies, for a attribute in a record, you can guarantee uniqueness of that attribute within the entire database. An example of this might be a email_address attribute in a User record. By setting email_address to unique, you guarantee that a particular email address can only appear in one recor... | 3 | 2009-11-27T16:54:12Z | 1,809,934 | <p>The only help you get from GAE's datastore regarding "uniqueness" is via entities' keys -- but then, I see the URL you quote also noticed that and shows one way to exploit this fact. To get anywhere beyond keys, you need to perform your checks at application level (before you put an entity, or a change to a unique s... | 4 | 2009-11-27T17:42:52Z | [
"python",
"database",
"google-app-engine"
] |
How do I create a unique property in python on google app engine? | 1,809,754 | <p>In some database technologies, for a attribute in a record, you can guarantee uniqueness of that attribute within the entire database. An example of this might be a email_address attribute in a User record. By setting email_address to unique, you guarantee that a particular email address can only appear in one recor... | 3 | 2009-11-27T16:54:12Z | 1,813,019 | <p>I use record.key().id() <a href="http://niklasro.blogspot.com/2009/08/sitemapxmlgz-generator.html" rel="nofollow">blogged</a> how, <a href="http://blog.notdot.net/" rel="nofollow">Nick Johnson's</a> blog has pro expert advice</p>
| 2 | 2009-11-28T16:54:17Z | [
"python",
"database",
"google-app-engine"
] |
How do I create a unique property in python on google app engine? | 1,809,754 | <p>In some database technologies, for a attribute in a record, you can guarantee uniqueness of that attribute within the entire database. An example of this might be a email_address attribute in a User record. By setting email_address to unique, you guarantee that a particular email address can only appear in one recor... | 3 | 2009-11-27T16:54:12Z | 3,134,520 | <p>I have implemented it in the following way by overriding the put method and using the key.name</p>
<pre><code>class Program(db.Model):
name = db.StringProperty("Title")
slug = db.StringProperty("Slug")
def put(self):
if Program.get_by_key_name(self.slug):
raise UniqueConstraintViolat... | 2 | 2010-06-28T17:11:38Z | [
"python",
"database",
"google-app-engine"
] |
Creating hierarchy tree from dictionary of pages' contents | 1,809,758 | <p>The following key:value pairs are 'page' and 'page contents'.</p>
<pre><code>{
'section-a.html':{'contents':'section-b.html section-c.html section-d.html'},
'section-b.html':{'contents':'section-d.html section-e.html'},
'section-c.html':{'contents':'product-a.html product-b.html product-c.html product-d.html'... | 1 | 2009-11-27T16:54:37Z | 1,809,813 | <p>Here's a simple approach -- it's O(N squared), so, not all that highly scalable, but will serve you well for a reasonable book size (if you have, say, millions of pages, you need to be thinking about a very different and less simple approach;-).</p>
<p>First, make a more usable dict, mapping page to set of contents... | 2 | 2009-11-27T17:11:50Z | [
"python",
"data-structures",
"tree",
"hierarchical-trees"
] |
Creating hierarchy tree from dictionary of pages' contents | 1,809,758 | <p>The following key:value pairs are 'page' and 'page contents'.</p>
<pre><code>{
'section-a.html':{'contents':'section-b.html section-c.html section-d.html'},
'section-b.html':{'contents':'section-d.html section-e.html'},
'section-c.html':{'contents':'product-a.html product-b.html product-c.html product-d.html'... | 1 | 2009-11-27T16:54:37Z | 1,809,825 | <p><strong>EDIT</strong> With the question explained a bit better I think the following might be what you need, or could at least provide something of a starting point.</p>
<pre><code>data = {
'section-a.html':{'contents':'section-b.html section-c.html section-d.html'},
'section-b.html':{'contents':'section-d.html... | 0 | 2009-11-27T17:13:44Z | [
"python",
"data-structures",
"tree",
"hierarchical-trees"
] |
Creating hierarchy tree from dictionary of pages' contents | 1,809,758 | <p>The following key:value pairs are 'page' and 'page contents'.</p>
<pre><code>{
'section-a.html':{'contents':'section-b.html section-c.html section-d.html'},
'section-b.html':{'contents':'section-d.html section-e.html'},
'section-c.html':{'contents':'product-a.html product-b.html product-c.html product-d.html'... | 1 | 2009-11-27T16:54:37Z | 1,812,798 | <p>Here's an illustration for your question. It is easier to reason about graphs when you have a picture.</p>
<p>First, abbreviate the data:</p>
<pre><code>#!/usr/bin/perl -pe
s/section-([a-e])\.html/uc$1/eg; s/product-([a-e])\.html/$1/g
</code></pre>
<p>Result:</p>
<pre><code># graph as adj list
DATA = {
'A':{'c... | 0 | 2009-11-28T15:30:15Z | [
"python",
"data-structures",
"tree",
"hierarchical-trees"
] |
Why say x = x in Python? | 1,809,805 | <p>In <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/mlab.py?revision=6648&view=markup&pathrev=6648" rel="nofollow">this file</a>, in the function <code>cross_from_below(x, threshold)</code>, there is a line that says <code>threshold = threshold</code>. What's ... | 4 | 2009-11-27T17:09:05Z | 1,809,824 | <p>There is no point to that assignment. It's probably just left over and should be removed. The next function is nearly identical, and doesn't have it.</p>
| 14 | 2009-11-27T17:13:34Z | [
"python",
"identity",
"equals"
] |
Why say x = x in Python? | 1,809,805 | <p>In <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/mlab.py?revision=6648&view=markup&pathrev=6648" rel="nofollow">this file</a>, in the function <code>cross_from_below(x, threshold)</code>, there is a line that says <code>threshold = threshold</code>. What's ... | 4 | 2009-11-27T17:09:05Z | 1,809,831 | <p>It could mean something. For example, if <code>threshold</code> was a property of a class, then assigning it could call a setter method.</p>
<p>But in this case, I think it's a typo. I've looked at the <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/mlab.py?view=diff... | 3 | 2009-11-27T17:16:05Z | [
"python",
"identity",
"equals"
] |
Why say x = x in Python? | 1,809,805 | <p>In <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/mlab.py?revision=6648&view=markup&pathrev=6648" rel="nofollow">this file</a>, in the function <code>cross_from_below(x, threshold)</code>, there is a line that says <code>threshold = threshold</code>. What's ... | 4 | 2009-11-27T17:09:05Z | 1,809,832 | <p>No, in the specific example you quote, that line is (harmless but) redundant -- indeed the very next function (cross threshold from above rather than from below) is almost identical (save of course for the direction of the comparisons), lacks that extra assignment, yet works just the same way.</p>
<p>The one and on... | 8 | 2009-11-27T17:16:12Z | [
"python",
"identity",
"equals"
] |
Why say x = x in Python? | 1,809,805 | <p>In <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/mlab.py?revision=6648&view=markup&pathrev=6648" rel="nofollow">this file</a>, in the function <code>cross_from_below(x, threshold)</code>, there is a line that says <code>threshold = threshold</code>. What's ... | 4 | 2009-11-27T17:09:05Z | 1,809,878 | <p>Or it could be one of those cases where it made sense at some point to write something like : </p>
<pre><code> self.threshold = threshold
</code></pre>
<p>because the function was a method of some class that needed to kept the threshold. (In which case, it would mean something else, wouldn't it ?)</p>
| 1 | 2009-11-27T17:29:25Z | [
"python",
"identity",
"equals"
] |
Scrapy SgmlLinkExtractor question | 1,809,817 | <p>I am trying to make the SgmlLinkExtractor to work.</p>
<p>This is the signature:</p>
<pre><code>SgmlLinkExtractor(allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths(), tags=('a', 'area'), attrs=('href'), canonicalize=True, unique=True, process_value=None)
</code></pre>
<p>I am just using <code>... | 8 | 2009-11-27T17:12:10Z | 1,810,205 | <p>allow=(r'/aadler/', ...</p>
| 1 | 2009-11-27T18:48:51Z | [
"python",
"web-crawler",
"scrapy"
] |
Scrapy SgmlLinkExtractor question | 1,809,817 | <p>I am trying to make the SgmlLinkExtractor to work.</p>
<p>This is the signature:</p>
<pre><code>SgmlLinkExtractor(allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths(), tags=('a', 'area'), attrs=('href'), canonicalize=True, unique=True, process_value=None)
</code></pre>
<p>I am just using <code>... | 8 | 2009-11-27T17:12:10Z | 1,818,537 | <p>You are overriding the "parse" method it appears. "parse", is a private method in CrawlSpider used to follow links.</p>
| 9 | 2009-11-30T08:33:50Z | [
"python",
"web-crawler",
"scrapy"
] |
Scrapy SgmlLinkExtractor question | 1,809,817 | <p>I am trying to make the SgmlLinkExtractor to work.</p>
<p>This is the signature:</p>
<pre><code>SgmlLinkExtractor(allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths(), tags=('a', 'area'), attrs=('href'), canonicalize=True, unique=True, process_value=None)
</code></pre>
<p>I am just using <code>... | 8 | 2009-11-27T17:12:10Z | 4,516,819 | <p>You are missing comma after first element for "rules" to be a tuple..</p>
<pre><code>rules = (Rule(SgmlLinkExtractor(allow=('/careers/n.\w+', )), callback='parse', follow=True),)
</code></pre>
| 1 | 2010-12-23T07:55:13Z | [
"python",
"web-crawler",
"scrapy"
] |
Scrapy SgmlLinkExtractor question | 1,809,817 | <p>I am trying to make the SgmlLinkExtractor to work.</p>
<p>This is the signature:</p>
<pre><code>SgmlLinkExtractor(allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths(), tags=('a', 'area'), attrs=('href'), canonicalize=True, unique=True, process_value=None)
</code></pre>
<p>I am just using <code>... | 8 | 2009-11-27T17:12:10Z | 7,887,642 | <p>if you check documentation a "<strong>Warning</strong>" is clearly written </p>
<p><em>"When writing crawl spider rules, avoid using parse as callback, since the Crawl Spider uses the parse method itself to implement its logic. So if you override the parse method, the crawl spider will no longer work."</em></p>
<... | 3 | 2011-10-25T10:04:30Z | [
"python",
"web-crawler",
"scrapy"
] |
Line-breaking Expression in Python | 1,809,890 | <p>I am beginner in python and facing this problem. So how i can break the below expression in 2-3 lines</p>
<pre><code>totalIncome = (classACost * float(classASeatsSold)) + (classBCost * float(classBSeatsSold)) + (classCCost * float(classCSeatsSold))
</code></pre>
<p>Like this.</p>
<pre><code>totalIncome = (classAC... | 1 | 2009-11-27T17:33:20Z | 1,809,898 | <p>Put your expression in parentheses:</p>
<pre><code>totalIncome = ((classACost * float(classASeatsSold)) +
(classBCost * float(classBSeatsSold)) +
(classCCost * float(classCSeatsSold)))
</code></pre>
| 4 | 2009-11-27T17:36:05Z | [
"python",
"syntax"
] |
Line-breaking Expression in Python | 1,809,890 | <p>I am beginner in python and facing this problem. So how i can break the below expression in 2-3 lines</p>
<pre><code>totalIncome = (classACost * float(classASeatsSold)) + (classBCost * float(classBSeatsSold)) + (classCCost * float(classCSeatsSold))
</code></pre>
<p>Like this.</p>
<pre><code>totalIncome = (classAC... | 1 | 2009-11-27T17:33:20Z | 1,809,948 | <p>You always never have to use line continuation characters in python thanks to parentheses:</p>
<pre><code>totalIncome = ( (classACost * float(classASeatsSold)) +
(classBCost * float(classBSeatsSold)) +
(classCCost * float(classCSeatsSold)) )
</code></pre>
<p>Which gives you the adva... | 14 | 2009-11-27T17:45:35Z | [
"python",
"syntax"
] |
Line-breaking Expression in Python | 1,809,890 | <p>I am beginner in python and facing this problem. So how i can break the below expression in 2-3 lines</p>
<pre><code>totalIncome = (classACost * float(classASeatsSold)) + (classBCost * float(classBSeatsSold)) + (classCCost * float(classCSeatsSold))
</code></pre>
<p>Like this.</p>
<pre><code>totalIncome = (classAC... | 1 | 2009-11-27T17:33:20Z | 1,809,960 | <p>I despise breaking a line over into several lines using 'backslashes'. By wrapping the entire expression on the right hand side of the equals character, you can break the lines without worrying about ensuring there is trailing whitespace or not, such as:</p>
<pre><code>totalIncome = ((classACost * float(classASeats... | 4 | 2009-11-27T17:47:48Z | [
"python",
"syntax"
] |
Line-breaking Expression in Python | 1,809,890 | <p>I am beginner in python and facing this problem. So how i can break the below expression in 2-3 lines</p>
<pre><code>totalIncome = (classACost * float(classASeatsSold)) + (classBCost * float(classBSeatsSold)) + (classCCost * float(classCSeatsSold))
</code></pre>
<p>Like this.</p>
<pre><code>totalIncome = (classAC... | 1 | 2009-11-27T17:33:20Z | 1,811,029 | <p>Just in case you revisit the scene:</p>
<p>You have excessive parentheses already. You also have unnecessary occurrences of float() ... if a cost is a float and a seatsSold is an int, then you don't need float() at all.</p>
<p>Instead of </p>
<pre><code>totalIncome = (classACost * float(classASeatsSold)) + (class... | 1 | 2009-11-27T23:46:28Z | [
"python",
"syntax"
] |
Hide stderr output in unit tests | 1,809,958 | <p>I'm writing a few unit tests of some code which uses sys.stderr.write to report errors in input. This is as it should be, but this clobbers the unit test output. Is there any way to tell Python to not output error messages for single commands, Ã la <code>2> /dev/null</code>?</p>
| 12 | 2009-11-27T17:47:10Z | 1,809,962 | <pre><code>class DevNull(object):
def write(self, data): pass
sys.stderr = DevNull()
</code></pre>
<p>To have a less permanent solution, one could figure out something like as follows:</p>
<pre><code>_stderr = None
def quiet():
global _stderr
if _stderr is None:
_stderr = sys.stderr
sys.s... | 4 | 2009-11-27T17:49:25Z | [
"python",
"unit-testing"
] |
Hide stderr output in unit tests | 1,809,958 | <p>I'm writing a few unit tests of some code which uses sys.stderr.write to report errors in input. This is as it should be, but this clobbers the unit test output. Is there any way to tell Python to not output error messages for single commands, Ã la <code>2> /dev/null</code>?</p>
| 12 | 2009-11-27T17:47:10Z | 1,809,963 | <p>You could create a dummy file object that did nothing with its output, and set stderr to that:</p>
<pre><code>class NullWriter:
def write(self, s):
pass
sys.stderr = NullWriter()
</code></pre>
<p>If you only want to quiet stderr for a specific duration, you can use a <code>with</code> statement like s... | 12 | 2009-11-27T17:49:56Z | [
"python",
"unit-testing"
] |
Hide stderr output in unit tests | 1,809,958 | <p>I'm writing a few unit tests of some code which uses sys.stderr.write to report errors in input. This is as it should be, but this clobbers the unit test output. Is there any way to tell Python to not output error messages for single commands, Ã la <code>2> /dev/null</code>?</p>
| 12 | 2009-11-27T17:47:10Z | 1,809,977 | <p>Another possibility (besides assigning to <code>sys.stderr</code>) is to structure your code to write errors to a file provided, but to default that file to sys.stderr. Then you can provide a DevNull writer during testing.</p>
<p>If you do want to reassign sys.stderr, you can use the unittest framework to manage i... | 4 | 2009-11-27T17:53:31Z | [
"python",
"unit-testing"
] |
Hide stderr output in unit tests | 1,809,958 | <p>I'm writing a few unit tests of some code which uses sys.stderr.write to report errors in input. This is as it should be, but this clobbers the unit test output. Is there any way to tell Python to not output error messages for single commands, Ã la <code>2> /dev/null</code>?</p>
| 12 | 2009-11-27T17:47:10Z | 1,810,086 | <p>I suggest writing a context manager:</p>
<pre><code>import contextlib
import sys
@contextlib.contextmanager
def nostderr():
savestderr = sys.stderr
class Devnull(object):
def write(self, _): pass
def flush(self): pass
sys.stderr = Devnull()
try:
yield
finally:
sy... | 21 | 2009-11-27T18:20:45Z | [
"python",
"unit-testing"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,121 | <pre><code>>>> import ast
>>> print ast.literal_eval("(8, 12.25), (13, 15), (16.75, 18.5)")
((8, 12.25), (13, 15), (16.75, 18.5))
</code></pre>
| 19 | 2009-11-27T18:29:06Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,122 | <p>If you're working with a CSV file, and you want more than the "naive" solution which doesn't handle any errors, you're probably best off using the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python's CSV module</a>.</p>
| 1 | 2009-11-27T18:29:21Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,139 | <p>Download <a href="http://pyparsing.wikispaces.com/" rel="nofollow">PyParsing</a>.</p>
<p>I've worked with it before. You can get some pretty robust parsing behavior out of it, and I think it provides builtins that will handle your entire parsing needs with this sort of thing. Look up commaSeparatedList and nestedEx... | 1 | 2009-11-27T18:35:39Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,218 | <pre><code>def parse(s):
tuples = s.split('), ')
out = []
for x in tuples:
a,b = x.strip('()').split(', ')
out.append((float(a),float(b)))
return out
</code></pre>
<p>this should do the job.</p>
| 2 | 2009-11-27T18:53:35Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,254 | <p>I've used <a href="http://stackoverflow.com/questions/28369/is-safeeval-really-safe">safe_eval</a> for jobs like this in the past. </p>
| 2 | 2009-11-27T19:03:19Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Parsing a string which represents a list of tuples | 1,810,109 | <p>I have strings which look like this one:</p>
<pre><code>"(8, 12.25), (13, 15), (16.75, 18.5)"
</code></pre>
<p>and I would like to convert each of them into a python data structure. Preferably a list (or tuple) of tuples containing a pair of float values.</p>
<p>I could do that with <code>eval("(8, 12.25), (13, 1... | 11 | 2009-11-27T18:25:46Z | 1,810,974 | <p>what's wrong with doing it systematically ? split on ")", then go through the list, remove all "(".</p>
<pre><code>>>> s="(8, 12.25), (13, 15), (16.75, 18.5)"
>>> [ i.replace("(","") for i in s.split(")") ]
['8, 12.25', ', 13, 15', ', 16.75, 18.5', '']
>>> b = [ i.replace("(","") for i in... | 1 | 2009-11-27T23:21:31Z | [
"python",
"data-structures",
"string",
"eval",
"tuples"
] |
Scrapy make_requests_from_url(url) | 1,810,143 | <p>In the Scrapy tutorial there is this method of the BaseSpider:</p>
<blockquote>
<p><a href="http://doc.scrapy.org/topics/spiders.html#scrapy.spider.BaseSpider.make%5Frequests%5Ffrom%5Furl" rel="nofollow">make_requests_from_url(url)</a></p>
<p>A method that receives a URL and
returns a Request object (or a ... | 1 | 2009-11-27T18:36:12Z | 3,747,263 | <p>That's right, the <a href="http://doc.scrapy.org/topics/spiders.html#crawlspider">CrawlSpider</a> is useful and convenient in many cases, but it only covers a subset of all possible spiders. If you need something more complex, you typically subclass <a href="http://doc.scrapy.org/topics/spiders.html#basespider">Base... | 4 | 2010-09-19T20:07:54Z | [
"python",
"web-crawler",
"scrapy"
] |
How can I create a script that manufactures MLA citations? | 1,810,405 | <p>I have a folder full of Windows <code>.URL</code> files. I'd like to translate them into a list of MLA citations for my paper.</p>
<p>Is this a good application of Python? How can I get the page titles? I'm on Windows XP with Python 3.1.1.</p>
| 1 | 2009-11-27T19:46:21Z | 1,810,486 | <p>Given a file that contains an HTML page, you can parse it to extract its title, and BeautifulSoup is the recommended third-party library for the job. Get the BeautifulSoup version compatible with Python 3.1 <a href="http://www.crummy.com/software/BeautifulSoup/download/BeautifulSoup.tar.gz" rel="nofollow">here</a>,... | 2 | 2009-11-27T20:12:50Z | [
"python"
] |
How can I create a script that manufactures MLA citations? | 1,810,405 | <p>I have a folder full of Windows <code>.URL</code> files. I'd like to translate them into a list of MLA citations for my paper.</p>
<p>Is this a good application of Python? How can I get the page titles? I'm on Windows XP with Python 3.1.1.</p>
| 1 | 2009-11-27T19:46:21Z | 1,810,509 | <p>This is a fantastic use for Python! The <code>.URL</code> file format has a syntax like this:</p>
<pre><code>[InternetShortcut]
URL=http://www.example.com/
OtherStuff=irrelevant
</code></pre>
<p>To parse your <code>.URL</code> files, start with <a href="http://docs.python.org/library/configparser.html" rel="nofoll... | 3 | 2009-11-27T20:18:26Z | [
"python"
] |
Handling the different results from parsedatetime | 1,810,432 | <p>I'm trying to learn python after spending the last 15 or so years working only in Perl and only occasionally.</p>
<p>I can't understand how to handle the two different kinds of results from the parse method of Calendar.parse() from parsedatetime</p>
<p>Given this script:</p>
<pre><code>#!/usr/bin/python
import p... | 3 | 2009-11-27T19:52:20Z | 1,810,453 | <p>Use <code>x = time.struct_time(result[0])</code> and you'll get a <code>struct_time</code> (so that you can check <code>x.tm_mon</code> and <code>x.tm_mday</code>) no matter whether that <code>result[0]</code> is a <code>struct_time</code> itself, or just a 9-tuple (I've never heard of <code>parsedatetime</code> so ... | 2 | 2009-11-27T20:01:06Z | [
"python"
] |
Handling the different results from parsedatetime | 1,810,432 | <p>I'm trying to learn python after spending the last 15 or so years working only in Perl and only occasionally.</p>
<p>I can't understand how to handle the two different kinds of results from the parse method of Calendar.parse() from parsedatetime</p>
<p>Given this script:</p>
<pre><code>#!/usr/bin/python
import p... | 3 | 2009-11-27T19:52:20Z | 5,903,760 | <p>I know this is an old question but I ran into this yesterday and the answer here is incomplete (it will fail in the case that parse() returns a datetime).</p>
<p>From the parsedatetime docs:</p>
<p>parse() returns a tuple ( result, type ) where type specifies one of:</p>
<pre><code> 0 = not parsed at all
1 =... | 15 | 2011-05-05T20:36:23Z | [
"python"
] |
Hide console for Tkinter app on OSX | 1,810,497 | <p>I'm trying to hide the Terminal when I launch a GUI Tkinter based app, but when I double click the app.py file on OSX, the Terminal window appears. I've tried changing the extension to .pyw and tried launching it with /usr/bin/pythonw, but no matter what, the Terminal window still appears. </p>
<p>I've even tried... | 2 | 2009-11-27T20:15:36Z | 1,810,580 | <p>By double-clicking a <code>.py</code> file on OS X, you are likely launching a Python gui instance via the <code>Python Launcher.app</code> supplied with OS X Pythons. You can verify that by selecting the <code>.py</code> file in the Finder and doing a <code>Get Info</code> on it. Python Launcher is a very simple-... | 6 | 2009-11-27T20:47:36Z | [
"python",
"osx",
"tkinter",
"tk"
] |
Hide console for Tkinter app on OSX | 1,810,497 | <p>I'm trying to hide the Terminal when I launch a GUI Tkinter based app, but when I double click the app.py file on OSX, the Terminal window appears. I've tried changing the extension to .pyw and tried launching it with /usr/bin/pythonw, but no matter what, the Terminal window still appears. </p>
<p>I've even tried... | 2 | 2009-11-27T20:15:36Z | 3,836,306 | <p>'console hide' doesn't hide the Terminal in OS X. It hides Tk's built-in console, which is really a relic from the MacOS Classic days (and which is still commonly used on Windows). </p>
| 0 | 2010-10-01T03:13:12Z | [
"python",
"osx",
"tkinter",
"tk"
] |
Hide console for Tkinter app on OSX | 1,810,497 | <p>I'm trying to hide the Terminal when I launch a GUI Tkinter based app, but when I double click the app.py file on OSX, the Terminal window appears. I've tried changing the extension to .pyw and tried launching it with /usr/bin/pythonw, but no matter what, the Terminal window still appears. </p>
<p>I've even tried... | 2 | 2009-11-27T20:15:36Z | 36,872,059 | <p>Adding to the answer by Ned Deily, im my case when I tried to launch the Python application using an AppleScript application, it did not work initially. I discovered that it has something to to with some kind of encoding error (I am using UTF-8 and in the past I had felt need to configure it to UTF-8).</p>
<p>So, a... | 0 | 2016-04-26T17:41:12Z | [
"python",
"osx",
"tkinter",
"tk"
] |
Dynamically binding Python methods to an instance correctly binds the method names, but not the method | 1,810,514 | <p>I'm writing a client for a group of RESTful services. The body of the REST calls have the same XML structure, given parameters. There are several dozen calls, and I will not be implementing all of them. As such, I want to make them easy to specify and easy to use. The REST methods are grouped by functionality in sep... | 3 | 2009-11-27T20:19:16Z | 1,810,561 | <p>The lambda is calling <code>m</code>, pulling it from the local scope. After the end of the for loop, <code>m</code> is set to <code>two</code>. Calling <code>c.one</code> or <code>c.two</code> will result in <code>two</code> being called.</p>
<p>You can tell that <code>two</code> is being called by looking at the ... | 3 | 2009-11-27T20:38:54Z | [
"python",
"types"
] |
Dynamically binding Python methods to an instance correctly binds the method names, but not the method | 1,810,514 | <p>I'm writing a client for a group of RESTful services. The body of the REST calls have the same XML structure, given parameters. There are several dozen calls, and I will not be implementing all of them. As such, I want to make them easy to specify and easy to use. The REST methods are grouped by functionality in sep... | 3 | 2009-11-27T20:19:16Z | 1,810,576 | <p>The problem is the variable <code>m</code> is left as <code>two</code> at the end of the loop, and that affects the definitions made during the loop. You can fix it by creating closures with nested functions:</p>
<pre><code>for m in (one, two):
def make_method(m):
def new_method(self, *args, **kwargs):
... | 3 | 2009-11-27T20:45:37Z | [
"python",
"types"
] |
Python: Calling a method of an instance's member by name using __getattribute__ | 1,810,526 | <p>I have a class that contains a member object. I would like to call the member's methods as if they were methods of the container class.</p>
<p>The following example illustrates (however in a different context) what I would like to do.</p>
<p>Suppose we have two classes representing two different kinds of products:... | 2 | 2009-11-27T20:22:31Z | 1,810,549 | <p>Use <code>__getattr__</code> instead of <code>__getattribute__</code>. If you use <code>__getattribute__</code>, you will get infinite recursion when evaluating <code>self.product</code>. </p>
<p><code>__getattr__</code> only gets called when the attribute wasn't otherwise found, so won't cause this.</p>
| 2 | 2009-11-27T20:34:02Z | [
"python"
] |
Python: Calling a method of an instance's member by name using __getattribute__ | 1,810,526 | <p>I have a class that contains a member object. I would like to call the member's methods as if they were methods of the container class.</p>
<p>The following example illustrates (however in a different context) what I would like to do.</p>
<p>Suppose we have two classes representing two different kinds of products:... | 2 | 2009-11-27T20:22:31Z | 1,810,595 | <p>You could use <code>__getattr__</code> instead of <code>__getattribute__</code> as has been suggested. That will be called for any attribute access for an attribute that does not exist.</p>
<p>If you do really want to override (nearly) ALL attribute access, then continue to use <code>__getattribute__</code> and def... | 3 | 2009-11-27T20:51:07Z | [
"python"
] |
Python: Calling a method of an instance's member by name using __getattribute__ | 1,810,526 | <p>I have a class that contains a member object. I would like to call the member's methods as if they were methods of the container class.</p>
<p>The following example illustrates (however in a different context) what I would like to do.</p>
<p>Suppose we have two classes representing two different kinds of products:... | 2 | 2009-11-27T20:22:31Z | 14,762,948 | <blockquote>
<p>Now a funny thing... If I define first the member self.product, as
shown above, the program works normally. However, if I try to define
first the member self.box_code, the program suffers the recursive loop
problem again. Does anybody know why?</p>
</blockquote>
<p>If you write <code>self.box_c... | 1 | 2013-02-07T23:17:01Z | [
"python"
] |
A simple spider question | 1,810,652 | <p>I am a newbie trying to achive this simple task by using Scrapy with no luck so far. I am asking your advice about how to do this with Scrapy or with any other tool (with Python). Thank you.</p>
<p>I want to</p>
<ol>
<li><p>start from a page that lists bios of attorneys whose last name start with A: initial_url = ... | 0 | 2009-11-27T21:14:51Z | 1,810,849 | <p>Not sure I fully understand what you're asking, but maybe you need to get the absolute URL to each bio and retrieve the source code for that page:</p>
<pre><code>import urllib2
bio_page = urllib.urlopen(bio_url).read()
</code></pre>
<p>Then use a regular expressions or other parsing to get the attorney's law schoo... | 0 | 2009-11-27T22:31:22Z | [
"python",
"web-crawler"
] |
How to set the current working directory in Python? | 1,810,743 | <p>How to set the current working directory in Python?</p>
| 201 | 2009-11-27T21:53:48Z | 1,810,760 | <p>Try <a href="http://docs.python.org/library/os.html#os.chdir"><code>os.chdir</code></a></p>
<blockquote>
<pre><code>os.chdir(path)
</code></pre>
<p>Â Â Â Â Â Â Â Â Change the current working directory to path. Availability: Unix, Windows.</p>
</blockquote>
| 274 | 2009-11-27T21:59:59Z | [
"python",
"current-working-directory"
] |
How to set the current working directory in Python? | 1,810,743 | <p>How to set the current working directory in Python?</p>
| 201 | 2009-11-27T21:53:48Z | 1,810,762 | <p>Perhaps this is what you are looking for:</p>
<pre><code>import os
os.chdir(default_path)
</code></pre>
| 67 | 2009-11-27T22:00:09Z | [
"python",
"current-working-directory"
] |
How to set the current working directory in Python? | 1,810,743 | <p>How to set the current working directory in Python?</p>
| 201 | 2009-11-27T21:53:48Z | 33,550,959 | <p>You need to import the <code>os</code> module and then you can use the <code>chdir()</code> method, but don't forget to use the quotations (<code>''</code>) inside the parenthesis:</p>
<pre><code>import os
os.chdir('default_path')
</code></pre>
| -3 | 2015-11-05T17:24:41Z | [
"python",
"current-working-directory"
] |
How to set the current working directory in Python? | 1,810,743 | <p>How to set the current working directory in Python?</p>
| 201 | 2009-11-27T21:53:48Z | 34,971,949 | <pre><code>import os;
print os.getcwd(); # Prints the working directory
</code></pre>
<p>To set the working directory:</p>
<pre><code>os.chdir('c:\\Users\uname\desktop\python') # Provide the path here
</code></pre>
| 5 | 2016-01-24T03:41:21Z | [
"python",
"current-working-directory"
] |
How to make article spinner regex? | 1,810,861 | <p>Let's say I have teh following:</p>
<blockquote>
<p>{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}</p>
</blockquote>
<p>And I want that to turn into any of the following:</p>
<pre><code>Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
</code></pre>
<p>Paying attention ... | 2 | 2009-11-27T22:36:49Z | 1,810,928 | <p>I would use re.finditer and build a basic parse tree to determine the nesting level. To do it, I would use the span attribute of the regex match object:</p>
<pre><code>text = '{{Hello|Hi|Hey} {world|earth} | {Goodbye|farewell} {noobs|n3wbz|n00blets}}'
import re
re_bracks = re.compile(r'{.+?}')
# subclass list for... | 1 | 2009-11-27T23:05:29Z | [
"c#",
".net",
"python",
"spinner",
"article"
] |
How to make article spinner regex? | 1,810,861 | <p>Let's say I have teh following:</p>
<blockquote>
<p>{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}</p>
</blockquote>
<p>And I want that to turn into any of the following:</p>
<pre><code>Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
</code></pre>
<p>Paying attention ... | 2 | 2009-11-27T22:36:49Z | 1,810,969 | <p>I'd recommend taking a look at <a href="http://dev.null.org/dadaengine/" rel="nofollow">the dada engine</a> for inspiration.</p>
<p>I've done an implementation of something inspired by this in scheme and leveraged scheme's AST to express my needs.</p>
<p>Specifically, I'd recommend strongly against trying to use a... | 1 | 2009-11-27T23:19:26Z | [
"c#",
".net",
"python",
"spinner",
"article"
] |
How to make article spinner regex? | 1,810,861 | <p>Let's say I have teh following:</p>
<blockquote>
<p>{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}</p>
</blockquote>
<p>And I want that to turn into any of the following:</p>
<pre><code>Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
</code></pre>
<p>Paying attention ... | 2 | 2009-11-27T22:36:49Z | 1,811,051 | <p>A simple way with <a href="http://docs.python.org/library/re.html?highlight=re.sub#re.subn" rel="nofollow">re.subn</a>, which can also accept a function instead of a replacement string:</p>
<pre><code>import re
from random import randint
def select(m):
choices = m.group(1).split('|')
return choices[randint... | 5 | 2009-11-27T23:56:47Z | [
"c#",
".net",
"python",
"spinner",
"article"
] |
How to make article spinner regex? | 1,810,861 | <p>Let's say I have teh following:</p>
<blockquote>
<p>{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}</p>
</blockquote>
<p>And I want that to turn into any of the following:</p>
<pre><code>Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
</code></pre>
<p>Paying attention ... | 2 | 2009-11-27T22:36:49Z | 1,811,080 | <p>Should be fairly simple, just disallow a brace set from including another, then repeatedly call doing replacements from the inner matches outwards:</p>
<pre><code>def replacebrace(match):
return random.choice(match.group(1).split('|'))
def randomizebraces(s):
while True:
s1= re.sub(r'\{([^{}]*)\}', r... | 4 | 2009-11-28T00:09:37Z | [
"c#",
".net",
"python",
"spinner",
"article"
] |
How to make article spinner regex? | 1,810,861 | <p>Let's say I have teh following:</p>
<blockquote>
<p>{{Hello|Hi|Hey} {world|earth} |
{Goodbye|farewell} {noobs|n3wbz|n00blets}}</p>
</blockquote>
<p>And I want that to turn into any of the following:</p>
<pre><code>Hello world
Goodbye noobs
Hi earth
farewell n3wbz
// etc.
</code></pre>
<p>Paying attention ... | 2 | 2009-11-27T22:36:49Z | 1,811,530 | <p>This <a href="http://pyparsing.wikispaces.com/file/view/invRegex.py" rel="nofollow">regex inverter</a> uses <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a> to generate matching strings (with some restrictions - unlimited repetition symbols like + and * are not allowed). If you replace {}'s w... | 2 | 2009-11-28T04:15:33Z | [
"c#",
".net",
"python",
"spinner",
"article"
] |
Django: How to filter User's that belong to a specific group | 1,810,891 | <p>I'm looking to narrow a query set for a form field that has a foreignkey to the User's table down to the group that a user belongs to.</p>
<p>The groups have been previously associated by me. The model might have something like the following:</p>
<pre><code> myuser = models.ForeignKey(User)
</code></pre>
<p>An... | 21 | 2009-11-27T22:51:30Z | 1,810,985 | <p>You'll want to use <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships">Django's convention for joining across relationships</a> to join to the group table in your query set.</p>
<p>Firstly, I recommend giving your relationship a <code>related_name</code>. This makes th... | 31 | 2009-11-27T23:26:38Z | [
"python",
"django"
] |
Django: How to filter User's that belong to a specific group | 1,810,891 | <p>I'm looking to narrow a query set for a form field that has a foreignkey to the User's table down to the group that a user belongs to.</p>
<p>The groups have been previously associated by me. The model might have something like the following:</p>
<pre><code> myuser = models.ForeignKey(User)
</code></pre>
<p>An... | 21 | 2009-11-27T22:51:30Z | 27,374,708 | <p>This is a really old question, but for those googling the answer to this (like I did), please know that the accepted answer is no longer 100% correct. A user can belong to multiple groups, so to correctly check if a user is in some group, you should do:</p>
<pre><code>qs = User.objects.filter(groups__name__in=['foo... | 6 | 2014-12-09T08:49:05Z | [
"python",
"django"
] |
Standard library - higher-precision floating point? | 1,811,010 | <p>So, I'm having some precision issues in Python.</p>
<p>I would like to calculate functions like this:</p>
<pre><code>P(x,y) = exp(-x)/(exp(-x) + exp(-y))
</code></pre>
<p>Where x and y might be >1000. Python's math.exp(-1000) (in 2.6 at least!) doesn't have enough floating point precision to handle this. </p>
... | 4 | 2009-11-27T23:37:42Z | 1,811,020 | <p>I think you are looking for the <a href="http://packages.python.org/bigfloat/" rel="nofollow">bigfloat</a> package for arbitrary precision floating-point reliable arithmetic.</p>
| 3 | 2009-11-27T23:42:34Z | [
"python",
"floating-point"
] |
Standard library - higher-precision floating point? | 1,811,010 | <p>So, I'm having some precision issues in Python.</p>
<p>I would like to calculate functions like this:</p>
<pre><code>P(x,y) = exp(-x)/(exp(-x) + exp(-y))
</code></pre>
<p>Where x and y might be >1000. Python's math.exp(-1000) (in 2.6 at least!) doesn't have enough floating point precision to handle this. </p>
... | 4 | 2009-11-27T23:37:42Z | 1,811,026 | <p>you could divide the top and bottom by <code>exp(-x)</code></p>
<pre><code>P(x,y) = 1/(1 + exp(x-y))
</code></pre>
| 8 | 2009-11-27T23:45:27Z | [
"python",
"floating-point"
] |
Standard library - higher-precision floating point? | 1,811,010 | <p>So, I'm having some precision issues in Python.</p>
<p>I would like to calculate functions like this:</p>
<pre><code>P(x,y) = exp(-x)/(exp(-x) + exp(-y))
</code></pre>
<p>Where x and y might be >1000. Python's math.exp(-1000) (in 2.6 at least!) doesn't have enough floating point precision to handle this. </p>
... | 4 | 2009-11-27T23:37:42Z | 1,811,030 | <pre><code>P(x,y) = exp(-x)/(exp(-x) + exp(-y))
</code></pre>
<p>is equivalent to:</p>
<pre><code>P(x,y) = 1 / (1 + exp(x-y))
</code></pre>
<p>Perhaps the second one works without the use of more precision.</p>
| 4 | 2009-11-27T23:47:20Z | [
"python",
"floating-point"
] |
Standard library - higher-precision floating point? | 1,811,010 | <p>So, I'm having some precision issues in Python.</p>
<p>I would like to calculate functions like this:</p>
<pre><code>P(x,y) = exp(-x)/(exp(-x) + exp(-y))
</code></pre>
<p>Where x and y might be >1000. Python's math.exp(-1000) (in 2.6 at least!) doesn't have enough floating point precision to handle this. </p>
... | 4 | 2009-11-27T23:37:42Z | 1,811,052 | <pre><code>>>> import decimal
>>> decimal.Decimal(-1000).exp()
Decimal('5.075958897549456765291809480E-435')
>>> decimal.getcontext().prec = 60
>>> decimal.Decimal(-1000).exp()
Decimal('5.07595889754945676529180947957433691930559928289283736183239E-435')
</code></pre>
| 8 | 2009-11-27T23:57:18Z | [
"python",
"floating-point"
] |
How can I track python imports | 1,811,095 | <p>I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the ma... | 16 | 2009-11-28T00:15:35Z | 1,811,097 | <p>It shouldn't be possible to get a cyclic import in python because it checks if the module has already been imported before importing it again. You can only import a module once, no matter how many times you call import.</p>
<p>From <a href="http://groups.google.com/group/comp.lang.python/browse%5Fthread/thread/1d80... | 1 | 2009-11-28T00:17:37Z | [
"python",
"import"
] |
How can I track python imports | 1,811,095 | <p>I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the ma... | 16 | 2009-11-28T00:15:35Z | 1,811,099 | <p>Try using <code>python -v</code> to run your program. It will trace the sequence of imports.</p>
<p>Another option is <a href="http://pypi.python.org/pypi/pylint">pylint</a>, which will alert you to all sorts of issues, including cyclic imports.</p>
| 8 | 2009-11-28T00:19:32Z | [
"python",
"import"
] |
How can I track python imports | 1,811,095 | <p>I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the ma... | 16 | 2009-11-28T00:15:35Z | 1,811,161 | <p>You could use one of these scripts to make python module dependency graphs:
<UL>
<LI>
<a href="http://furius.ca/snakefood/">http://furius.ca/snakefood/</a>
</LI>
<LI>
<a href="http://www.tarind.com/depgraph.html">http://www.tarind.com/depgraph.html</a>
</LI>
<LI>
<a href="http://code.activestate.com/recipes/535136/"... | 10 | 2009-11-28T00:43:35Z | [
"python",
"import"
] |
How can I track python imports | 1,811,095 | <p>I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the ma... | 16 | 2009-11-28T00:15:35Z | 1,811,165 | <p>Here's a simple (and slightly rudimentary;-) way to trace "who's trying to import what" in terms of module names:</p>
<pre><code>import inspect
import __builtin__
savimp = __builtin__.__import__
def newimp(name, *x):
caller = inspect.currentframe().f_back
print name, caller.f_globals.get('__name__')
return s... | 13 | 2009-11-28T00:45:33Z | [
"python",
"import"
] |
How can I track python imports | 1,811,095 | <p>I have cyclical import issues adding some new code to a very large app, and I'm trying to determine which files are the most likely causes for this. It there any way to track which files import which files? I did a bit of looking and found the python trace command, but it's just showing a bunch of activity in the ma... | 16 | 2009-11-28T00:15:35Z | 29,736,056 | <p>Maybe to late but you should definitely take a look at </p>
<p><a href="https://github.com/boris-42/profimp" rel="nofollow">https://github.com/boris-42/profimp</a> </p>
<p><img src="http://i.stack.imgur.com/QDun5.png" alt="enter image description here"></p>
| 1 | 2015-04-19T21:24:42Z | [
"python",
"import"
] |
Scrapy SgmlLinkExtractor is ignoring allowed links | 1,811,132 | <p>Please take a look at <a href="http://doc.scrapy.org/topics/spiders.html#crawlspider-example">this spider example</a> in Scrapy documentation. The explanation is:</p>
<blockquote>
<p>This spider would start crawling example.comâs home page, collecting category links, and item links, parsing the latter with the ... | 10 | 2009-11-28T00:34:23Z | 2,074,821 | <p>The <code>parse</code> function is actually implemented and used in the CrawlSpider class, and you're unintentionally overriding it. If you change the name to something else, like <code>parse_item</code>, then the Rule should work.</p>
| 11 | 2010-01-15T21:12:54Z | [
"python",
"web-crawler",
"scrapy"
] |
Where can I find good tutorials and guides on wxPython and wxGlade? | 1,811,164 | <p>Just out of curiosity, aside from their respective sites, have any of you guys found a better resource for figuring out wxPython/wxGlade?</p>
<p>I figured I'd ask while I'm chewing on something else, I plan on using those tools to create a GUI for the project I've started.</p>
| 2 | 2009-11-28T00:45:04Z | 1,811,172 | <p>wxGlade: <a href="http://wiki.wxpython.org/WxGladeTutorial" rel="nofollow">http://wiki.wxpython.org/WxGladeTutorial</a></p>
<p>A video tutorial for wxGlade: <a href="http://showmedo.com/videotutorials/video?name=7850030&fromSeriesID=785" rel="nofollow">http://showmedo.com/videotutorials/video?name=7850030&f... | 2 | 2009-11-28T00:47:12Z | [
"python",
"wxpython",
"wxglade"
] |
Where can I find good tutorials and guides on wxPython and wxGlade? | 1,811,164 | <p>Just out of curiosity, aside from their respective sites, have any of you guys found a better resource for figuring out wxPython/wxGlade?</p>
<p>I figured I'd ask while I'm chewing on something else, I plan on using those tools to create a GUI for the project I've started.</p>
| 2 | 2009-11-28T00:45:04Z | 1,811,191 | <p>For wxpython, apart from the wxpython.org site of course, you might want to look at <a href="http://www.zetcode.com/wxpython/" rel="nofollow">this</a> (slightly dated) tutorial and <a href="http://showmedo.com/videotutorials/series?name=PythonWxPythonBeginnersSeries" rel="nofollow">these</a> five videos. For wxglade... | 0 | 2009-11-28T00:53:31Z | [
"python",
"wxpython",
"wxglade"
] |
Why does my python script randomly get killed? | 1,811,173 | <p>Basically, i have a list of 30,000 URLs.
The script goes through the URLs and downloads them (with a 3 second delay in between).
And then it stores the HTML in a database.</p>
<p>And it loops and loops...</p>
<p>Why does it randomly get "Killed."? I didn't touch anything.</p>
<p>Edit: this happens on 3 of my linu... | 11 | 2009-11-28T00:47:23Z | 1,811,196 | <p>Is it possible that it's hitting an uncaught exception? Are you running this from a shell, or is it being run from cron or in some other automated way? If it's automated, the output may not be displayed anywhere.</p>
| 1 | 2009-11-28T00:56:40Z | [
"python",
"mysql",
"url"
] |
Why does my python script randomly get killed? | 1,811,173 | <p>Basically, i have a list of 30,000 URLs.
The script goes through the URLs and downloads them (with a 3 second delay in between).
And then it stores the HTML in a database.</p>
<p>And it loops and loops...</p>
<p>Why does it randomly get "Killed."? I didn't touch anything.</p>
<p>Edit: this happens on 3 of my linu... | 11 | 2009-11-28T00:47:23Z | 1,811,200 | <p>Looks like you might be running out of memory -- might easily happen on a long-running program if you have a "leak" (e.g., due to accumulating circular references). Does Rackspace offer any easily usable tools to keep track of a process's memory, so you can confirm if this is the case? Otherwise, this kind of thin... | 16 | 2009-11-28T00:58:11Z | [
"python",
"mysql",
"url"
] |
Why does my python script randomly get killed? | 1,811,173 | <p>Basically, i have a list of 30,000 URLs.
The script goes through the URLs and downloads them (with a 3 second delay in between).
And then it stores the HTML in a database.</p>
<p>And it loops and loops...</p>
<p>Why does it randomly get "Killed."? I didn't touch anything.</p>
<p>Edit: this happens on 3 of my linu... | 11 | 2009-11-28T00:47:23Z | 1,811,219 | <p>In cases like this, you should check the log files.</p>
<p>I use Debian and Ubuntu, so the main log file for me is: <code>/var/log/syslog</code></p>
<p>If you use Red Hat, I think that log is: <code>/var/log/messages</code></p>
<p>If something happens that is as exceptional as the kernel killing your process, the... | 9 | 2009-11-28T01:11:42Z | [
"python",
"mysql",
"url"
] |
Why does my python script randomly get killed? | 1,811,173 | <p>Basically, i have a list of 30,000 URLs.
The script goes through the URLs and downloads them (with a 3 second delay in between).
And then it stores the HTML in a database.</p>
<p>And it loops and loops...</p>
<p>Why does it randomly get "Killed."? I didn't touch anything.</p>
<p>Edit: this happens on 3 of my linu... | 11 | 2009-11-28T00:47:23Z | 1,811,350 | <p>Are you using some sort of queue manager or process manager of some sort ?
I got apparently random killed messages when the batch queue manager I was using was sending SIGUSR2 when the time was up. </p>
<p>Otherwise I strongly favor the out of memory option. </p>
| 1 | 2009-11-28T02:30:07Z | [
"python",
"mysql",
"url"
] |
How can I run redemo.py (or equivalent) on a Mac? | 1,811,236 | <p>In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called <code>redemo.py</code>. It's a simple tk application for testing regular expressions.</p>
<p>I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of t... | 1 | 2009-11-28T01:24:12Z | 1,811,244 | <p>Install Python on your Mac, then copy the script over? It should work fine on any Python installation.</p>
| 0 | 2009-11-28T01:27:08Z | [
"python",
"regex"
] |
How can I run redemo.py (or equivalent) on a Mac? | 1,811,236 | <p>In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called <code>redemo.py</code>. It's a simple tk application for testing regular expressions.</p>
<p>I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of t... | 1 | 2009-11-28T01:24:12Z | 1,811,259 | <p>Mac OS X comes with Python pre-installed. As of 10.6.2 it has Python 2.6.1 found at <code>/usr/bin/python</code>. Copy redemo.py to your Mac. Make sure you have X11.app running and open a terminal (Terminal.app is available by default) and just run:</p>
<pre><code>% python /path/to/redemo.py
</code></pre>
<p>As... | 0 | 2009-11-28T01:34:22Z | [
"python",
"regex"
] |
How can I run redemo.py (or equivalent) on a Mac? | 1,811,236 | <p>In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called <code>redemo.py</code>. It's a simple tk application for testing regular expressions.</p>
<p>I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of t... | 1 | 2009-11-28T01:24:12Z | 1,811,263 | <p>Python is part of OS X, but sometimes it's a bit out of date: <a href="http://www.python.org/download/mac/" rel="nofollow">http://www.python.org/download/mac/</a></p>
| 0 | 2009-11-28T01:35:55Z | [
"python",
"regex"
] |
How can I run redemo.py (or equivalent) on a Mac? | 1,811,236 | <p>In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called <code>redemo.py</code>. It's a simple tk application for testing regular expressions.</p>
<p>I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of t... | 1 | 2009-11-28T01:24:12Z | 1,811,271 | <p>You can view the script directly from the python svn repository <a href="http://svn.python.org/view/python/trunk/Tools/scripts/" rel="nofollow">here</a> and can download it:</p>
<pre><code>curl http://svn.python.org/view/*checkout*/python/trunk/Tools/scripts/redemo.py?content-type=text%2Fplain > redemo.py
/usr/b... | 3 | 2009-11-28T01:44:01Z | [
"python",
"regex"
] |
Does my code leak memory (python)? | 1,811,413 | <pre><code> links_list = char.getLinks(words)
for source_url in links_list:
try:
print 'Downloading URL: ' + source_url
urldict = hash_url(source_url)
source_url_short = urldict['url_short']
source_url_hash = urldict['url_short_hash']
if Url.obj... | 0 | 2009-11-28T03:03:52Z | 1,811,444 | <p>If you are doing this in Django, make sure DEBUG is False, otherwise it will cache every query.</p>
<p><a href="http://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory" rel="nofollow">See FAQ</a></p>
| 0 | 2009-11-28T03:29:21Z | [
"python",
"memory",
"memory-management"
] |
Does my code leak memory (python)? | 1,811,413 | <pre><code> links_list = char.getLinks(words)
for source_url in links_list:
try:
print 'Downloading URL: ' + source_url
urldict = hash_url(source_url)
source_url_short = urldict['url_short']
source_url_hash = urldict['url_short_hash']
if Url.obj... | 0 | 2009-11-28T03:03:52Z | 1,811,475 | <p>maybe your process uses too much memory and the server (perhaps shared host) just kills it because you exhaust your memory quota.</p>
<p>here you use a call that may eat up a lot of memory:</p>
<pre><code>links_list = char.getLinks(words)
for source_url in links_list:
...
</code></pre>
<p>Looks like you migh... | 1 | 2009-11-28T03:42:54Z | [
"python",
"memory",
"memory-management"
] |
Does my code leak memory (python)? | 1,811,413 | <pre><code> links_list = char.getLinks(words)
for source_url in links_list:
try:
print 'Downloading URL: ' + source_url
urldict = hash_url(source_url)
source_url_short = urldict['url_short']
source_url_hash = urldict['url_short_hash']
if Url.obj... | 0 | 2009-11-28T03:03:52Z | 1,811,491 | <p>The easiest way to check is to go to the task manager (on Windows - or equivalent on other platforms) and check the memory requirements of the Python process. If it stays constant, there are no memory leaks. If not, you have a memory leak somewhere and you will need to debug</p>
| 0 | 2009-11-28T03:49:14Z | [
"python",
"memory",
"memory-management"
] |
Does my code leak memory (python)? | 1,811,413 | <pre><code> links_list = char.getLinks(words)
for source_url in links_list:
try:
print 'Downloading URL: ' + source_url
urldict = hash_url(source_url)
source_url_short = urldict['url_short']
source_url_hash = urldict['url_short_hash']
if Url.obj... | 0 | 2009-11-28T03:03:52Z | 1,811,557 | <p>Perhaps you should get a job server such as <a href="http://kr.github.com/beanstalkd/" rel="nofollow">beanstalkd</a> and think about doing just one at a time.</p>
<p>The job server will requeue the ones that fail, allowing the rest to complete. You can also run more than one client concurrently should you need to ... | 0 | 2009-11-28T04:30:08Z | [
"python",
"memory",
"memory-management"
] |
Processing (possibly) optional arguments in Python | 1,811,540 | <p>I am working on a series of command line tools which connect to the same server and do related but different things. I'd like users to be able to have a single configuration file where they can place common arguments such as connection information that can be shared across all the tools. Ideally, I'd like somethin... | 1 | 2009-11-28T04:21:38Z | 1,811,582 | <p>This-party module <a href="http://www.gustaebel.de/lars/configparse/manual.html" rel="nofollow">configparse</a> is written to extend <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a> from the standard Python library. As the optparse docs I pointed to mention, "optparse doesnât pre... | 1 | 2009-11-28T04:42:04Z | [
"python",
"command-line",
"optparse",
"configparser"
] |
Processing (possibly) optional arguments in Python | 1,811,540 | <p>I am working on a series of command line tools which connect to the same server and do related but different things. I'd like users to be able to have a single configuration file where they can place common arguments such as connection information that can be shared across all the tools. Ideally, I'd like somethin... | 1 | 2009-11-28T04:21:38Z | 1,811,668 | <p>I've used <a href="http://hg.piranha.org.ua/opster/docs/index.html" rel="nofollow">opster</a>'s middleware feature together with <a href="http://docs.python.org/library/configparser.html#ConfigParser.SafeConfigParser" rel="nofollow">SafeConfigParser</a> to achieve a similar (but slightly simpler) effect as you ask. ... | 0 | 2009-11-28T05:27:03Z | [
"python",
"command-line",
"optparse",
"configparser"
] |
Processing (possibly) optional arguments in Python | 1,811,540 | <p>I am working on a series of command line tools which connect to the same server and do related but different things. I'd like users to be able to have a single configuration file where they can place common arguments such as connection information that can be shared across all the tools. Ideally, I'd like somethin... | 1 | 2009-11-28T04:21:38Z | 1,812,080 | <p>use a dict to store options to your program. </p>
<p>first parse the option file in the user's directory and store every options in a dict (configparse or any other module is welcome). then parse the command line (using any module you want, optparse might fit well), if an arguments specifies a config file, parse th... | 0 | 2009-11-28T09:23:09Z | [
"python",
"command-line",
"optparse",
"configparser"
] |
python GTK container for mjpeg stream | 1,811,624 | <p>I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk.
The stream is a string of bytes from the driver.
What widget would be best for displaying this and would I need to do some intermediate conversion before putting it in the widget? Should I write my ow... | 0 | 2009-11-28T05:02:15Z | 1,821,048 | <p>GTK+ does not contain a native widget capable of decoding and rendering video.</p>
<p>You should probably look into <a href="http://gstreamer.freedesktop.org/" rel="nofollow">GStreamer</a>, which is a streaming-media toolkit built on the same GObject framework as GTK+.</p>
<p>It has the <a href="http://gstreamer.f... | 2 | 2009-11-30T16:59:55Z | [
"python",
"gtk",
"pygtk",
"mjpeg"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.