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
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
1,336,518
<p>In addition to multiprocessing there's also the <a href="http://pypi.python.org/pypi/celery/0.6.0" rel="nofollow">Celery</a> project, if you're using Django.</p>
3
2009-08-26T18:06:35Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
1,336,532
<p>There's also "bucker" by Sylvain Hellegouarch which you can find here:</p> <ul> <li><a href="http://trac.defuze.org/wiki/bucker" rel="nofollow">http://trac.defuze.org/wiki/bucker</a></li> </ul> <p>It describes itself like this:</p> <ul> <li>bucker is a queue system that supports multiple storage for the queue (me...
3
2009-08-26T18:10:01Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
1,336,588
<p>Look at <a href="http://xph.us/software/beanstalkd/" rel="nofollow">beanstalkd</a></p>
2
2009-08-26T18:18:36Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
2,025,357
<p>redqueue? It's implemented in python+tornado framework, speaks memcached protocol and is optionally persistent into log files. Currently it is also able to behave like beanstalkd, the reserve/delete way in memcache protocol as well.</p> <p><a href="http://github.com/superisaac/redqueue" rel="nofollow" title="redque...
2
2010-01-08T03:44:20Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
3,303,344
<p>It's a year late or whatever, but this is something I've hacked together to make a queue of Processes executing them only X number at a time. <a href="http://github.com/goosemo/job_queue" rel="nofollow">http://github.com/goosemo/job_queue</a></p>
1
2010-07-21T20:04:24Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
3,303,367
<p>Pyres is a resque clone built in python. Resque is used by Github as their message queue. Both use Redis as the queue backend and provide a web-based monitoring application.</p> <p><a href="http://binarydud.github.com/pyres/intro.html">http://binarydud.github.com/pyres/intro.html</a></p>
12
2010-07-21T20:08:00Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
3,758,551
<p>Also there is Unix 'at'</p> <p>For more info: man at</p>
-2
2010-09-21T08:34:41Z
[ "python", "job-queue" ]
job queue implementation for python
1,336,489
<p>Do you know/use any distributed job queue for python? Can you share links or tools</p>
13
2009-08-26T18:01:08Z
9,342,317
<p>If you think that Celery is too heavy for your needs then you might want to look at the simple distributed task queue:</p> <ul> <li><a href="https://github.com/rojkov/taskqueue" rel="nofollow">https://github.com/rojkov/taskqueue</a></li> <li><a href="http://simpletaskqueue.readthedocs.org/" rel="nofollow">http://si...
2
2012-02-18T15:05:48Z
[ "python", "job-queue" ]
What's the fastest way to fixup line-endings for SMTP sending?
1,336,524
<p>I'm coding a email application that produces messages for sending via SMTP. That means I need to change all lone \n and \r characters into the canonical \r\n sequence we all know and love. Here's the code I've got now:</p> <pre><code>CRLF = '\r\n' msg = re.sub(r'(?&lt;!\r)\n', CRLF, msg) msg = re.sub(r'\r(?!\n)',...
2
2009-08-26T18:08:15Z
1,336,574
<p>You could start by pre-compiling the regexes, e.g.</p> <pre><code>FIXCR = re.compile(r'\r(?!\n)') FIXLN = re.compile(r'(?&lt;!\r)\n') </code></pre> <p>Then use FIXCR.sub and FIXLN.sub. Next, you could try to combine the regexes into one, with a | thingy, which should also help.</p>
0
2009-08-26T18:15:51Z
[ "python", "smtp", "performance" ]
What's the fastest way to fixup line-endings for SMTP sending?
1,336,524
<p>I'm coding a email application that produces messages for sending via SMTP. That means I need to change all lone \n and \r characters into the canonical \r\n sequence we all know and love. Here's the code I've got now:</p> <pre><code>CRLF = '\r\n' msg = re.sub(r'(?&lt;!\r)\n', CRLF, msg) msg = re.sub(r'\r(?!\n)',...
2
2009-08-26T18:08:15Z
1,336,577
<p>Maybe it is the fact that inserting an extra character in the middle of the string is killing it.</p> <p>When you are substituting the text "hello \r world" it has to actually increase the size of the entire string by one character to "hello \r\n world" .</p> <p>I would suggest looping over the string and looking ...
1
2009-08-26T18:16:39Z
[ "python", "smtp", "performance" ]
What's the fastest way to fixup line-endings for SMTP sending?
1,336,524
<p>I'm coding a email application that produces messages for sending via SMTP. That means I need to change all lone \n and \r characters into the canonical \r\n sequence we all know and love. Here's the code I've got now:</p> <pre><code>CRLF = '\r\n' msg = re.sub(r'(?&lt;!\r)\n', CRLF, msg) msg = re.sub(r'\r(?!\n)',...
2
2009-08-26T18:08:15Z
1,336,648
<p>Something like this? Compile your regex.</p> <pre><code>CRLF = '\r\n' cr_or_lf_regex = re.compile(r'(?:(?&lt;!\r)\n)|(?:\r(?!\n))') </code></pre> <p>Then, when you want to replace stuff use this:</p> <pre><code>cr_or_lf_regex.sub(CRLF, msg) </code></pre> <p><strong>EDIT:</strong> Since the above is actually slow...
-1
2009-08-26T18:30:58Z
[ "python", "smtp", "performance" ]
What's the fastest way to fixup line-endings for SMTP sending?
1,336,524
<p>I'm coding a email application that produces messages for sending via SMTP. That means I need to change all lone \n and \r characters into the canonical \r\n sequence we all know and love. Here's the code I've got now:</p> <pre><code>CRLF = '\r\n' msg = re.sub(r'(?&lt;!\r)\n', CRLF, msg) msg = re.sub(r'\r(?!\n)',...
2
2009-08-26T18:08:15Z
1,337,185
<p>This regex helped:</p> <p><code>re.sub(r'\r\n|\r|\n', '\r\n', msg)</code></p> <p>But this code ended up winning:</p> <p><code>msg.replace('\r\n','\n').replace('\r','\n').replace('\n','\r\n')</code></p> <p>The original regexes took .6s to convert /usr/share/dict/words from \n to \r\n, the new regex took .3s, and ...
2
2009-08-26T20:13:02Z
[ "python", "smtp", "performance" ]
What's the fastest way to fixup line-endings for SMTP sending?
1,336,524
<p>I'm coding a email application that produces messages for sending via SMTP. That means I need to change all lone \n and \r characters into the canonical \r\n sequence we all know and love. Here's the code I've got now:</p> <pre><code>CRLF = '\r\n' msg = re.sub(r'(?&lt;!\r)\n', CRLF, msg) msg = re.sub(r'\r(?!\n)',...
2
2009-08-26T18:08:15Z
1,337,572
<p>Replace them on the fly as you're writing the string to wherever it's going. If you use a regex or anything else you'll be making two passes: one to replace the characters and then one to write it. Deriving a new Stream class and wrapping it around whatever you're writing to is pretty effective; that's the way we ...
1
2009-08-26T21:23:14Z
[ "python", "smtp", "performance" ]
BDB Python Interface Error when Reading BDB
1,336,617
<p>bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- /dbs/supermodels.db: unexpected file type or format')</p> <p>Is this error a result of incompatible BDB versions (1.85 or 3+)? If so, how do I check the versions, trouble-shoot and solve this error?</p>
0
2009-08-26T18:24:43Z
1,338,491
<p>Yes, this certainly could be due to older versions of the db file, but it would help if you posted the code that generated this exception and the full traceback.</p> <p>In the absence of this, are you sure that the database file that you're opening is of the correct type? For example, attempting to open a btree fil...
0
2009-08-27T02:00:50Z
[ "python", "berkeley-db" ]
Specifying constraints for fmin_cobyla in scipy
1,336,777
<p>I use Python 2.5.</p> <p>I am passing bounds to the cobyla optimisation:</p> <pre><code>import numpy from numpy import asarray Initial = numpy.asarray [2, 4, 5, 3] # Initial values to start with #bounding limits (lower,upper) - for visualizing #bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000)] #...
1
2009-08-26T18:53:37Z
1,336,891
<p><code>fmin_cobyla()</code> is not an interior point method. That is, it will pass points that are outside of the bounds ("infeasible points") to the function during the course of the optmization run.</p> <p>On thing that you will need to fix is that <code>b9</code> and <code>b10</code> are not in the form that <cod...
3
2009-08-26T19:17:25Z
[ "python", "function", "lambda", "scipy", "specifications" ]
Specifying constraints for fmin_cobyla in scipy
1,336,777
<p>I use Python 2.5.</p> <p>I am passing bounds to the cobyla optimisation:</p> <pre><code>import numpy from numpy import asarray Initial = numpy.asarray [2, 4, 5, 3] # Initial values to start with #bounding limits (lower,upper) - for visualizing #bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000)] #...
1
2009-08-26T18:53:37Z
1,342,801
<p>for b10, a possible option could be:</p> <pre><code>b10 = lambda x: min(abs(i-j)-d for i,j in itertools.combinations(x,2)) </code></pre> <p>where <em>d</em> is a delta greater than the minimum difference you want between your variables (e.g 0.001)</p>
2
2009-08-27T18:05:36Z
[ "python", "function", "lambda", "scipy", "specifications" ]
Example of subclassing string.Template in Python?
1,336,786
<p>I haven't been able to find a good example of subclassing string.Template in Python, even though I've seen multiple references to doing so in documentation.</p> <p>Are there any examples of this on the web?</p> <p>I want to change the $ to be a different character and maybe change the regex for identifiers.</p>
13
2009-08-26T18:54:53Z
1,336,851
<p>From python <a href="http://docs.python.org/library/string.html">docs</a>:</p> <blockquote> <p>Advanced usage: you can derive subclasses of Template to customize the placeholder syntax, delimiter character, or the entire regular expression used to parse template strings. To do this, you can override t...
19
2009-08-26T19:07:40Z
[ "python", "stringtemplate" ]
Dictionary vs Object - which is more efficient and why?
1,336,791
<p>What is more efficient in Python in terms of memory usage and CPU consumption - Dictionary or Object?</p> <p><strong>Background:</strong> I have to load huge amount of data into Python. I created an object that is just a field container. Creating 4M instances and putting them into a dictionary took about 10 minutes...
76
2009-08-26T18:55:45Z
1,336,829
<p>Attribute access in an object uses dictionary access behind the scenes - so by using attribute access you are adding extra overhead. Plus in the object case, you are incurring additional overhead because of e.g. additional memory allocations and code execution (e.g. of the <code>__init__</code> method).</p> <p>In y...
10
2009-08-26T19:03:57Z
[ "python", "performance", "dictionary", "object" ]
Dictionary vs Object - which is more efficient and why?
1,336,791
<p>What is more efficient in Python in terms of memory usage and CPU consumption - Dictionary or Object?</p> <p><strong>Background:</strong> I have to load huge amount of data into Python. I created an object that is just a field container. Creating 4M instances and putting them into a dictionary took about 10 minutes...
76
2009-08-26T18:55:45Z
1,336,890
<p>Have you tried using <code>__slots__</code>?</p> <p>From the documentation <a href="http://docs.python.org/reference/datamodel.html#slots">http://docs.python.org/reference/datamodel.html#slots</a>:</p> <p>"By default, instances of both old and new-style classes have a dictionary for attribute storage. This wastes ...
107
2009-08-26T19:17:25Z
[ "python", "performance", "dictionary", "object" ]
Dictionary vs Object - which is more efficient and why?
1,336,791
<p>What is more efficient in Python in terms of memory usage and CPU consumption - Dictionary or Object?</p> <p><strong>Background:</strong> I have to load huge amount of data into Python. I created an object that is just a field container. Creating 4M instances and putting them into a dictionary took about 10 minutes...
76
2009-08-26T18:55:45Z
1,336,906
<pre><code>from datetime import datetime ITER_COUNT = 1000 * 1000 def timeit(method): def timed(*args, **kw): s = datetime.now() result = method(*args, **kw) e = datetime.now() print method.__name__, '(%r, %r)' % (args, kw), e - s return result return timed class Obj(...
3
2009-08-26T19:19:29Z
[ "python", "performance", "dictionary", "object" ]
Dictionary vs Object - which is more efficient and why?
1,336,791
<p>What is more efficient in Python in terms of memory usage and CPU consumption - Dictionary or Object?</p> <p><strong>Background:</strong> I have to load huge amount of data into Python. I created an object that is just a field container. Creating 4M instances and putting them into a dictionary took about 10 minutes...
76
2009-08-26T18:55:45Z
1,336,952
<p><strong>There is no question.</strong><br /> You have data, with no other attributes (no methods, nothing). Hence you have a data container (in this case, a dictionary).</p> <p>I usually prefer to think in terms of <strong>data modeling</strong>. If there is some huge performance issue, then I can give up something...
3
2009-08-26T19:28:12Z
[ "python", "performance", "dictionary", "object" ]
Dictionary vs Object - which is more efficient and why?
1,336,791
<p>What is more efficient in Python in terms of memory usage and CPU consumption - Dictionary or Object?</p> <p><strong>Background:</strong> I have to load huge amount of data into Python. I created an object that is just a field container. Creating 4M instances and putting them into a dictionary took about 10 minutes...
76
2009-08-26T18:55:45Z
1,338,150
<p>Have you considered using a <a href="http://docs.python.org/library/collections.html" rel="nofollow">namedtuple</a>? (<a href="http://code.activestate.com/recipes/500261/" rel="nofollow">link for python 2.4/2.5</a>)</p> <p>It's the new standard way of representing structured data that gives you the performance of ...
7
2009-08-26T23:39:22Z
[ "python", "performance", "dictionary", "object" ]
Python dateutil.rrule is incredibly slow
1,336,824
<p>I'm using the python dateutil module for a calendaring application which supports repeating events. I really like the ability to parse ical rrules using the rrulestr() function. Also, using rrule.between() to get dates within a given interval is very fast.</p> <p>However, as soon as I try doing any other operatio...
2
2009-08-26T19:03:10Z
1,337,063
<p>My guess is probably not. The last date before datetime.max means you have to calculate all the recurrences up until datetime.max, and that will reasonably be a LOT of recurrences. It might be possible to add shortcuts for some of the simpler recurrences. If it is every year on the same date for example, you don't r...
4
2009-08-26T19:52:08Z
[ "python", "calendar", "icalendar", "python-dateutil" ]
How do I switch this Proxy to use Proxy-Authentication?
1,336,882
<p>I'm trying to modify my simple Twisted web proxy to use "Proxy-Authentication" (username/password) instead of the current IP based authentication. Problem is, I'm new to Twisted and don't even know where to start. </p> <p>Here is my Factory Class.</p> <pre><code>class ProxyFactory(http.HTTPFactory): def __in...
1
2009-08-26T19:15:15Z
1,462,680
<p>A similar question came up on the Twisted mailing list a while ago:</p> <p><a href="http://www.mail-archive.com/twisted-python@twistedmatrix.com/msg01080.html" rel="nofollow">http://www.mail-archive.com/twisted-python@twistedmatrix.com/msg01080.html</a></p> <p>As I mentioned there, you probably need to subclass so...
1
2009-09-22T21:20:05Z
[ "python", "authentication", "proxy", "twisted" ]
Python: Alternatives to pickling a module
1,336,908
<p>I am working on my program, <a href="http://garlicsim.com" rel="nofollow">GarlicSim</a>, in which a user creates a simulation, then he is able to manipulate it as he desires, and then he can save it to file.</p> <p>I recently tried implementing the saving feature. The natural thing that occured to me is to pickle t...
2
2009-08-26T19:19:50Z
1,336,943
<p>If you have the original code for the simulation package modules, which I presume are dynamically generated, then I would suggest serializing that and reconstructing the modules when loaded. You would do this in the <code>Project.__getstate__()</code> and <code>Project.__setstate__()</code> methods.</p>
1
2009-08-26T19:26:28Z
[ "python", "module", "pickle" ]
Python: Alternatives to pickling a module
1,336,908
<p>I am working on my program, <a href="http://garlicsim.com" rel="nofollow">GarlicSim</a>, in which a user creates a simulation, then he is able to manipulate it as he desires, and then he can save it to file.</p> <p>I recently tried implementing the saving feature. The natural thing that occured to me is to pickle t...
2
2009-08-26T19:19:50Z
1,337,012
<p>If the project somehow has a reference to a module with stuff you need, it sounds like you might want to refactor the use of that module into a class within the module. This is often better anyway, because the use of a module for stuff smells of a big fat global. In my experience, such an application structure will ...
2
2009-08-26T19:39:48Z
[ "python", "module", "pickle" ]
Running doctests through iPython and pseudo-consoles
1,336,980
<p>I've got a fairly basic doctestable file:</p> <pre><code>class Foo(): """ &gt;&gt;&gt; 3+2 5 """ if __name__ in ("__main__", "__console__"): import doctest doctest.testmod(verbose=True) </code></pre> <p>which works as expected when run directly through python.</p> <p>However, in iPython, ...
1
2009-08-26T19:33:33Z
1,337,175
<p>The following works:</p> <pre><code>$ ipython ... In [1]: %run file.py Trying: 3+2 Expecting: 5 ok 1 items had no tests: __main__ 1 items passed all tests: 1 tests in __main__.Foo 1 tests in 2 items. 1 passed and 0 failed. Test passed. In [2]: </code></pre> <p>I have no idea why <code>ipython file...
1
2009-08-26T20:10:54Z
[ "python", "django", "ipython" ]
Running doctests through iPython and pseudo-consoles
1,336,980
<p>I've got a fairly basic doctestable file:</p> <pre><code>class Foo(): """ &gt;&gt;&gt; 3+2 5 """ if __name__ in ("__main__", "__console__"): import doctest doctest.testmod(verbose=True) </code></pre> <p>which works as expected when run directly through python.</p> <p>However, in iPython, ...
1
2009-08-26T19:33:33Z
1,351,905
<p>The root problem is that <code>ipython</code> plays weird tricks with <code>__main__</code> (through its own <code>FakeModule</code> module) so that, by the time <code>doctest</code> is introspecting that "alleged module" through its <code>__dict__</code>, <code>Foo</code> is <em>NOT</em> there -- so doctest doesn't...
8
2009-08-29T17:05:02Z
[ "python", "django", "ipython" ]
SQLAlchemy Inheritance
1,337,095
<p>I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not even sure what type of inheritance (single table, joined table, concrete) I should be using here. I've got a base class with some information that's shared amongst the subclasses, and some data that are completely separate. Sometimes, ...
38
2009-08-26T19:57:53Z
1,337,871
<p>Choosing how to represent the inheritance is mostly a database design issue. For performance single table inheritance is usually best. From a good database design point of view, joined table inheritance is better. Joined table inheritance enables you to have foreign keys to subclasses enforced by the database, it's ...
57
2009-08-26T22:25:10Z
[ "python", "inheritance", "sqlalchemy" ]
SQLAlchemy Inheritance
1,337,095
<p>I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not even sure what type of inheritance (single table, joined table, concrete) I should be using here. I've got a base class with some information that's shared amongst the subclasses, and some data that are completely separate. Sometimes, ...
38
2009-08-26T19:57:53Z
1,337,957
<p>Ants Aasma's solution is much more elegant, but if you are keeping your Class definitions separate from your table definitions intentionally, you need to map your classes to your tables with the mapper function. After you have defined your classes, you need to define your tables:</p> <pre><code>building = Table('bu...
8
2009-08-26T22:42:50Z
[ "python", "inheritance", "sqlalchemy" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
1,337,465
<p>There is good library <a href="http://code.google.com/p/pyrtf-ng/" rel="nofollow">pyrtf-ng</a> for all-purpose RTF handling.</p>
1
2009-08-26T21:01:33Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
1,337,467
<p>Have you checked out <a href="http://code.google.com/p/pyrtf-ng/" rel="nofollow">pyrtf-ng</a>?</p> <p><strong>Update:</strong> The parsing functionality is available if you do a Subversion checkout, but I'm not sure how full-featured it is. (Look in the <code>rtfng.parser.base</code> module.)</p>
3
2009-08-26T21:01:36Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
1,337,815
<p>OpenOffice has a RTF reader. You can use python to script OpenOffice, <a href="http://wiki.services.openoffice.org/wiki/Python" rel="nofollow">see here for more info</a>.</p> <p>You could probably try using the magic com-object on Windows to read anything that smells ms-binary. I wouldn't recommend that though.</p>...
7
2009-08-26T22:10:09Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
1,573,854
<p>I ran into the same thing ans I was trying to code it myself. It's not that easy but here is what I had when I decided to go for a commandline app. Its ruby but you can adapt to python very easily. There is some header garbage to clean up, but you can see more or less the idea.</p> <pre><code>f = File.open('r.rtf',...
0
2009-10-15T17:22:44Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
1,821,405
<p>I've been working on a library called Pyth, which can do this:</p> <p><a href="http://pypi.python.org/pypi/pyth/">http://pypi.python.org/pypi/pyth/</a></p> <p>Converting an RTF file to plaintext looks something like this:</p> <pre><code>from pyth.plugins.rtf15.reader import Rtf15Reader from pyth.plugins.plaintext...
36
2009-11-30T18:07:06Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
6,353,632
<p>Conversely, if you want to write RTFs easily from Python, you can use the third-party module <a href="https://github.com/viking-sudo-rm/rtflib/blob/master/rtflib.py" rel="nofollow">rtflib</a>. It's a fairly new and incomplete module but still very powerful and useful. Below is an example that writes "hello world" in...
0
2011-06-15T05:55:50Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
11,966,087
<p><a href="http://code.google.com/p/pyrtf-ng/" rel="nofollow">PyRTF-ng</a> 0.9.1 has not parsed any of my RTF documents, both with the ParsingException. First document was generated with OpenOffice 3.4, the second one with Mac TextEdit.</p> <p><a href="https://pypi.python.org/pypi/pyth/" rel="nofollow">Pyth</a> 0.5.6...
1
2012-08-15T08:22:55Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
29,842,287
<p>I just came across <a href="http://sourceforge.net/projects/pyrtflib/" rel="nofollow">pyrtflib</a> - there's not much (any) documentation on it, it's kinda a case of installing it and then using the inbuilt help() function to find out what's available and what everything does.</p> <p>Having said that in my little t...
1
2015-04-24T08:24:15Z
[ "python", "text", "rtf" ]
Is there a Python module for converting RTF to plain text?
1,337,446
<p>Ideally, I'd like a module or library that doesn't require superuser access to install; I have limited privileges in my working environment.</p>
20
2009-08-26T20:56:59Z
38,086,182
<p>Here's a link to a script that converts rtf to text using regex: <a href="http://stackoverflow.com/questions/188545/regular-expression-for-extracting-text-from-an-rtf-string">Regular Expression for extracting text from an RTF string</a></p> <p>Also, and updated link on github: <a href="https://gist.github.com/gilso...
1
2016-06-28T20:57:54Z
[ "python", "text", "rtf" ]
Python object @property
1,337,935
<p>I'm trying to create a point class which defines a property called "coordinate". However, it's not behaving like I'd expect and I can't figure out why. </p> <pre><code>class Point: def __init__(self, coord=None): self.x = coord[0] self.y = coord[1] @property def coordinate(self): ...
6
2009-08-26T22:39:35Z
1,337,976
<p>The <code>property</code> method (and by extension, the <code>@property</code> decorator) <a href="http://docs.python.org/library/functions.html#property">requires a new-style class</a> i.e. a class that subclasses <code>object</code>.</p> <p>For instance,</p> <pre><code>class Point: </code></pre> <p>should be</p...
9
2009-08-26T22:47:45Z
[ "python", "new-style-class" ]
Python object @property
1,337,935
<p>I'm trying to create a point class which defines a property called "coordinate". However, it's not behaving like I'd expect and I can't figure out why. </p> <pre><code>class Point: def __init__(self, coord=None): self.x = coord[0] self.y = coord[1] @property def coordinate(self): ...
6
2009-08-26T22:39:35Z
1,337,977
<p>It will work if you derive Point from object:</p> <pre><code>class Point(object): # ... </code></pre>
4
2009-08-26T22:47:46Z
[ "python", "new-style-class" ]
Can I write Python applications using PyObjC that target NON-jailbroken iPhones?
1,338,095
<p>Is it currently possible to compile Python and PyObjC for the iPhone such that AppStore applications can written in Python?</p> <p>If not, is this a purely technical issue or a deliberate policy decision by Apple?</p>
3
2009-08-26T23:18:00Z
1,338,097
<p>no, apple strictly forbids running any kind of interpreter on iphone, and it is completely policy issue.</p>
0
2009-08-26T23:18:54Z
[ "iphone", "python", "pyobjc" ]
Can I write Python applications using PyObjC that target NON-jailbroken iPhones?
1,338,095
<p>Is it currently possible to compile Python and PyObjC for the iPhone such that AppStore applications can written in Python?</p> <p>If not, is this a purely technical issue or a deliberate policy decision by Apple?</p>
3
2009-08-26T23:18:00Z
1,338,105
<p>No: it's Apple's deliberate policy decision (no doubt with some technical underpinnings) to not support interpreters/runtimes on iPhone for most languages -- ObjC (and Javascript within Safari) is what Apple wants you to use, not Python, Java, Ruby, and so forth.</p>
1
2009-08-26T23:20:56Z
[ "iphone", "python", "pyobjc" ]
Configure Django project in a subdirectory using mod_python. Admin not working
1,338,101
<p>HI guys. I was trying to configure my django project in a subdirectory of the root, but didn't get things working.(LOcally it works perfect). I followed the django official django documentarion to deploy a project with mod_python. The real problem is that I am getting "Page not found" errors, whenever I try to go to...
1
2009-08-26T23:19:57Z
1,338,186
<p>I'm using mod_wsgi, so I'm not sure if it's all the same. But in my urls.py, I have:</p> <pre><code>(r'^admin/(.*)', admin.site.root), </code></pre> <p>In my Apache config, I have this:</p> <pre><code>Alias /admin/media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media </code></pre> <p>Your path may ...
0
2009-08-26T23:53:27Z
[ "python", "django", "deployment", "mod-python" ]
Configure Django project in a subdirectory using mod_python. Admin not working
1,338,101
<p>HI guys. I was trying to configure my django project in a subdirectory of the root, but didn't get things working.(LOcally it works perfect). I followed the django official django documentarion to deploy a project with mod_python. The real problem is that I am getting "Page not found" errors, whenever I try to go to...
1
2009-08-26T23:19:57Z
1,338,190
<p>If your settings.py is correct and has your correct INSTALLED_APPS and it works in the development server, then I'd say it's you Apache configuration file.</p> <p>Try running my python app to create Apache configuration files for mod_python + Django. The source is <a href="http://github.com/hughdbrown/Apache-conf/t...
0
2009-08-26T23:54:53Z
[ "python", "django", "deployment", "mod-python" ]
One-liner Python code for setting string to 0 string if empty
1,338,518
<p>What is a one-liner code for setting a string in python to the string, 0 if the string is empty?</p> <pre><code># line_parts[0] can be empty # if so, set a to the string, 0 # one-liner solution should be part of the following line of code if possible a = line_parts[0] ... </code></pre>
10
2009-08-27T02:12:49Z
1,338,529
<pre><code>a = '0' if not line_parts[0] else line_parts[0] </code></pre>
11
2009-08-27T02:15:50Z
[ "python", "string" ]
One-liner Python code for setting string to 0 string if empty
1,338,518
<p>What is a one-liner code for setting a string in python to the string, 0 if the string is empty?</p> <pre><code># line_parts[0] can be empty # if so, set a to the string, 0 # one-liner solution should be part of the following line of code if possible a = line_parts[0] ... </code></pre>
10
2009-08-27T02:12:49Z
1,338,532
<pre><code>a = line_parts[0] or "0" </code></pre> <p>This is one of the nicest Python idioms, making it easy to provide default values. It's often used like this for default values of functions:</p> <pre><code>def fn(arg1, arg2=None): arg2 = arg2 or ["weird default value"] </code></pre>
45
2009-08-27T02:16:41Z
[ "python", "string" ]
java to python conversion: x509 / dsa / sha1withdsa crypto howto?
1,338,546
<p>I've got the following Java code that I'm trying to convert to python, and I'm not really sure how to do this:</p> <pre><code>import java.security.spec.X509EncodedKeySpec; import java.security.KeyFactory; import java.security.PublicKey; import java.security.Signature; byte[] key = KeyReader.read(filestream) //K...
2
2009-08-27T02:22:43Z
1,441,873
<p>I don't exactly understand the Java code, but is this what you are trying to do?</p> <pre><code>from M2Crypto import X509 x509 = X509.load_cert(filename) assert x509.verify() == 1 </code></pre>
1
2009-09-17T23:33:45Z
[ "java", "python", "cryptography", "sha1", "m2crypto" ]
python variable scope
1,338,590
<p>I have started to learn about python and is currently reading through a script written by someone else. I noticed that globals are scattered throughout the script (and I don't like it).. Besides that, I also noticed that when I have code like this</p> <pre><code>def some_function(): foo.some_method() # some...
2
2009-08-27T02:41:30Z
1,338,621
<p>As far as I know, the only way to stop <code>some_function</code> from accessing <code>foo</code> is to eliminate the <code>foo</code> variable from <code>some_function</code>'s scope, possibly like:</p> <pre><code>tmp = foo del foo some_function() foo = tmp </code></pre> <p>Of course, this will crash your (curren...
2
2009-08-27T02:53:18Z
[ "python" ]
python variable scope
1,338,590
<p>I have started to learn about python and is currently reading through a script written by someone else. I noticed that globals are scattered throughout the script (and I don't like it).. Besides that, I also noticed that when I have code like this</p> <pre><code>def some_function(): foo.some_method() # some...
2
2009-08-27T02:41:30Z
1,338,667
<p>That script has really serious issues with style and organization -- for example, if somebody imports it they have to somehow divine the fact that they have to set <code>thescript.foo</code> to an instance of <code>Some_Object</code> before calling <code>some_function</code>... yeurgh!-)</p> <p>It's unfortunate tha...
4
2009-08-27T03:11:48Z
[ "python" ]
python variable scope
1,338,590
<p>I have started to learn about python and is currently reading through a script written by someone else. I noticed that globals are scattered throughout the script (and I don't like it).. Besides that, I also noticed that when I have code like this</p> <pre><code>def some_function(): foo.some_method() # some...
2
2009-08-27T02:41:30Z
1,338,805
<p>In python, something like <code>foo</code> is not a value, it's a <em>name</em>. When you try to access it, python tries to find the value associated with it (like dereferencing a pointer). It does this by first looking in the local scope (the function), then working its way outwards until it reaches the module sc...
1
2009-08-27T04:06:41Z
[ "python" ]
Good way of handling NoneType objects when printing in Python
1,338,690
<p>How do I go about printin a NoneType object in Python?</p> <pre><code># score can be a NonType object logging.info("NEW_SCORE : "+score) </code></pre> <p>Also why is that sometime I see a comma instead of the + above?</p>
4
2009-08-27T03:22:55Z
1,338,693
<pre><code>logging.info("NEW_SCORE : " + str(score)) </code></pre> <p>Proof by Python interpreter:</p> <pre><code>&gt;&gt;&gt; x = None &gt;&gt;&gt; "x: " + x Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: cannot concatenate 'str' and 'NoneType' objects &gt;&gt;&gt; "x...
4
2009-08-27T03:24:24Z
[ "python", "string" ]
Good way of handling NoneType objects when printing in Python
1,338,690
<p>How do I go about printin a NoneType object in Python?</p> <pre><code># score can be a NonType object logging.info("NEW_SCORE : "+score) </code></pre> <p>Also why is that sometime I see a comma instead of the + above?</p>
4
2009-08-27T03:22:55Z
1,338,726
<p>The best approach is:</p> <pre><code>logging.info("NEW_SCORE: %s", score) </code></pre> <p>In most contexts, you'd have to use a <code>%</code> operator between the format string on the left and the value(s) on the right (in a tuple, if more than one). But the <code>logging</code> functions are special: you pass t...
8
2009-08-27T03:39:36Z
[ "python", "string" ]
Good way of handling NoneType objects when printing in Python
1,338,690
<p>How do I go about printin a NoneType object in Python?</p> <pre><code># score can be a NonType object logging.info("NEW_SCORE : "+score) </code></pre> <p>Also why is that sometime I see a comma instead of the + above?</p>
4
2009-08-27T03:22:55Z
1,338,755
<p>For print purpose,you need to str first. A comma is to print with a single space between it..For example:</p> <p>print "hi guys","how are you today"</p> <p><em>this syntax will output:</em></p> <p>hi guys how are you today</p> <p>but it will be different if your syntax like this:</p> <p>print "hi guys"+"how are...
0
2009-08-27T03:49:19Z
[ "python", "string" ]
Good way of handling NoneType objects when printing in Python
1,338,690
<p>How do I go about printin a NoneType object in Python?</p> <pre><code># score can be a NonType object logging.info("NEW_SCORE : "+score) </code></pre> <p>Also why is that sometime I see a comma instead of the + above?</p>
4
2009-08-27T03:22:55Z
14,646,844
<p>if not score==None: logging.info("NEW_SCORE : "+score)</p> <p>or</p> <p>logging.info("NEW_SCORE: %s" % str(score) )</p>
0
2013-02-01T12:58:02Z
[ "python", "string" ]
Parameter binding using GQL in Google App Engine
1,338,704
<p>Okay so I have this mode:</p> <pre><code>class Posts(db.Model): rand1 = db.FloatProperty() #other models here </code></pre> <p>and this controller:</p> <pre><code>class Random(webapp.RequestHandler): def get(self): rand2 = random.random() posts_query = db.GqlQuery("SELECT * FROM Posts WHERE rand1 &gt...
2
2009-08-27T03:28:56Z
1,338,732
<p>Substitute:</p> <pre><code> "...WHERE rand1 &gt; :rand2 ORDER BY rand LIMIT 1") </code></pre> <p>with:</p> <pre><code> "...WHERE rand1 &gt; :rand2 ORDER BY rand LIMIT 1", rand2=rand2) </code></pre> <p>Or</p> <pre><code> "...WHERE rand1 &gt; :1 ORDER BY rand LIMIT 1", rand2) </code></pre> <p>See for more info...
3
2009-08-27T03:40:41Z
[ "python", "django", "google-app-engine", "binding", "gql" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,338,719
<p>Well, you could do it with a bunch of objects.</p> <pre><code>class Config(object): pass config = Config() config.account_receivable = 4 print config.account_receivable </code></pre> <p>Obviously you can extend this class to do more for you. e.g. define <code>__init__</code> so you can create it with argumen...
0
2009-08-27T03:36:29Z
[ "python", "dictionary" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,338,720
<p>Have a look at <a href="http://stackoverflow.com/questions/1305532/convert-python-dict-to-object">http://stackoverflow.com/questions/1305532/convert-python-dict-to-object</a>.</p>
3
2009-08-27T03:37:15Z
[ "python", "dictionary" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,338,730
<p><strong>You need to use one of Python's <a href="http://docs.python.org/reference/datamodel.html#customizing-attribute-access" rel="nofollow">special methods</a>.</strong></p> <pre><code>class config(object): def __init__(self, data): self.data = data def __getattr__(self, name): return self...
2
2009-08-27T03:40:01Z
[ "python", "dictionary" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,338,737
<p>You can do this with collections.namedtuple:</p> <pre><code>from collections import namedtuple config_object = namedtuple('ConfigClass', config.keys())(*config.values()) print config_object.account_receivable </code></pre> <p>You can learn more about namedtuple here:</p> <p><a href="http://docs.python.org/dev/lib...
7
2009-08-27T03:42:05Z
[ "python", "dictionary" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,338,739
<p>For that purpose, lo that many years ago, I invented the simple <code>Bunch</code> idiom; one simple way to implement <code>Bunch</code> is:</p> <pre><code>class Bunch(object): def __init__(self, adict): self.__dict__.update(adict) </code></pre> <p>If <code>config</code> is a dict, you can't use <code>config...
12
2009-08-27T03:42:59Z
[ "python", "dictionary" ]
Accesing dictionary with class attribute
1,338,714
<p>now i am working with python. So one question about dict .... suppose i have a dict that </p> <pre><code>config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'fin...
4
2009-08-27T03:34:08Z
1,339,772
<p>You can subclass dict to return items from itself for undefined attributes:</p> <pre><code>class AttrAccessibleDict(dict): def __getattr__(self, key): try: return self[key] except KeyError: return AttributeError(key) config = AttrAccessibleDict(config) print(config.a...
0
2009-08-27T08:51:58Z
[ "python", "dictionary" ]
Is it crazy to not rely on a caching system like memcached nowadays ( for dynamic sites )?
1,338,777
<p>I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent.</p> <p>I figure I'll just rewrite it from scratch because it's <em>really</em> outdated and in this rewrite I want to implement a cach...
2
2009-08-27T03:57:36Z
1,338,804
<p>Since Python is one of your choices, I would go with Django. Built-in caching mechanism, and I've been using <a href="http://github.com/dcramer/django-debug-toolbar/tree/master" rel="nofollow">this debug_toolbar</a> to help me while developing/profiling.</p> <p>By the way, memcached does <strong>not</strong> work t...
3
2009-08-27T04:06:25Z
[ "php", "python", "memcached", "scalability" ]
Is it crazy to not rely on a caching system like memcached nowadays ( for dynamic sites )?
1,338,777
<p>I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent.</p> <p>I figure I'll just rewrite it from scratch because it's <em>really</em> outdated and in this rewrite I want to implement a cach...
2
2009-08-27T03:57:36Z
1,338,810
<p>If your site performance is fine then there's no reason to add caching. Lots of sites can get by without any cache at all, or by moving to a file-system based cache. It's only the super high traffic sites that need memcached.</p> <p>What's "crazy" is code architecture (or a lack of architecture) that makes adding...
6
2009-08-27T04:08:29Z
[ "php", "python", "memcached", "scalability" ]
Is it crazy to not rely on a caching system like memcached nowadays ( for dynamic sites )?
1,338,777
<p>I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent.</p> <p>I figure I'll just rewrite it from scratch because it's <em>really</em> outdated and in this rewrite I want to implement a cach...
2
2009-08-27T03:57:36Z
1,338,828
<p>Caching, when it works right (==high hit rate), is one of the few general-purpose techniques that can really help with <em>latency</em> -- the harder part of problems generically describes as "performance". You can enhance <em>QPS</em> (queries per second) measures of performance just by throwing more hardware at th...
9
2009-08-27T04:18:05Z
[ "php", "python", "memcached", "scalability" ]
Is it crazy to not rely on a caching system like memcached nowadays ( for dynamic sites )?
1,338,777
<p>I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent.</p> <p>I figure I'll just rewrite it from scratch because it's <em>really</em> outdated and in this rewrite I want to implement a cach...
2
2009-08-27T03:57:36Z
1,338,864
<p>Depending on the specific nature of the codebase and traffic patterns, you might not even need to re-write the whole site. Horribly inefficient code is not such a big deal if it can be bypassed via cache for 99.9% of page requests.</p> <p>When choosing PHP or Python, make sure you figure out where you're going to h...
0
2009-08-27T04:34:43Z
[ "php", "python", "memcached", "scalability" ]
Attribute Error in Python
1,338,847
<p>I'm trying to add a unittest attribute to an object in Python</p> <pre><code>class Boy: def run(self, args): print("Hello") class BoyTest(unittest.TestCase) def test(self) self.assertEqual('2' , '2') def self_test(): suite = unittest.TestSuite() loader = unittest.TestLoader() ...
0
2009-08-27T04:28:57Z
1,338,860
<p>As the argument of <code>loadTestsFromTestCase</code>, you're trying to access <code>Boy.BoyTest</code>, i.e., the <code>BoyTest</code> attribute of class object <code>Boy</code>, which just doesn't exist, as the error msg is telling you. Why don't you just use <code>BoyTest</code> there instead?</p>
3
2009-08-27T04:33:25Z
[ "python", "attributeerror" ]
Attribute Error in Python
1,338,847
<p>I'm trying to add a unittest attribute to an object in Python</p> <pre><code>class Boy: def run(self, args): print("Hello") class BoyTest(unittest.TestCase) def test(self) self.assertEqual('2' , '2') def self_test(): suite = unittest.TestSuite() loader = unittest.TestLoader() ...
0
2009-08-27T04:28:57Z
1,340,156
<p>As Alex has stated you are trying to use BoyTest as an attibute of Boy:</p> <pre><code>class Boy: def run(self, args): print("Hello") class BoyTest(unittest.TestCase) def test(self) self.assertEqual('2' , '2') def self_test(): suite = unittest.TestSuite() loader = unittest.TestL...
-1
2009-08-27T10:23:31Z
[ "python", "attributeerror" ]
accessing base class primitive type in python
1,338,858
<p>I am trying to derive a class from a python primitive, the float, for the purpose of printing a different repr string when it's printed out.</p> <p>How do I access the underlying data from the derived class when I do this?</p> <p>Here's a simplified example of what I am trying to do:</p> <pre><code>class efloat(f...
2
2009-08-27T04:32:57Z
1,338,866
<p>If you don't override <code>__str__</code>, that will still access the underlying method, so:</p> <pre><code>class efloat(float): def __repr__(self): return "here's my number: %s" % self </code></pre> <p>will work. More generally, you could use <code>self+0</code>, <code>self*1</code>, or any other ide...
4
2009-08-27T04:35:38Z
[ "python", "class", "floating-point" ]
accessing base class primitive type in python
1,338,858
<p>I am trying to derive a class from a python primitive, the float, for the purpose of printing a different repr string when it's printed out.</p> <p>How do I access the underlying data from the derived class when I do this?</p> <p>Here's a simplified example of what I am trying to do:</p> <pre><code>class efloat(f...
2
2009-08-27T04:32:57Z
1,339,725
<p>You can call the base class methods, by accessing them off the base class to get an unbound method and call them with self:</p> <pre><code>class myfloat(float): def __str__(self): return "My float is " + float.__str__(self) print(myfloat(4.5)) </code></pre>
2
2009-08-27T08:42:25Z
[ "python", "class", "floating-point" ]
What wrong when SimpleXMLRPC and DBusGMainLoop working in the same time
1,339,003
<p>In python I try create a service that maintain calling event between SflPhone(dbus service) and external app, when I start SimpleXMLRPCServer my service no longer response for any calling event, such as on_call_state_changed function was not called. </p> <p>When I comment out <strong><code>thread.start_new_thread(s...
1
2009-08-27T05:20:50Z
1,339,203
<p>Try adding after ifmain trick:</p> <pre><code>gobject.threads_init() dbus.glib.init_threads() </code></pre>
0
2009-08-27T06:30:36Z
[ "python", "voip", "xml-rpc", "sip", "dbus" ]
How to make this method non-recursive?
1,339,215
<p>Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest.</p> <p>There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. Th...
2
2009-08-27T06:33:42Z
1,339,285
<p>By "go crazy" I assume you mean:</p> <pre><code>&gt;&gt;&gt; Game(10000) # stuff skipped RuntimeError: maximum recursion depth exceeded in cmp </code></pre> <p>You could start at the bottom instead -- a crude change would be:</p> <pre><code># after defining Game() for i in range(10000): Game(i) # Now this wi...
3
2009-08-27T06:53:05Z
[ "python", "recursion", "refactoring" ]
How to make this method non-recursive?
1,339,215
<p>Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest.</p> <p>There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. Th...
2
2009-08-27T06:33:42Z
1,339,473
<p>In general, it is only possible to convert recursive functions into loops when they are <a href="http://en.wikipedia.org/wiki/Primitive%5Frecursive%5Ffunction" rel="nofollow">primitive-recursive</a>; this basically means that they call themselves only once in the body. Your function calls itself multiple times. Such...
4
2009-08-27T07:45:39Z
[ "python", "recursion", "refactoring" ]
How to make this method non-recursive?
1,339,215
<p>Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest.</p> <p>There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. Th...
2
2009-08-27T06:33:42Z
1,339,530
<p>Well, recursion mostly is about being able to execute some code without losing previous contexts and their order. In particular, function frames put and saved onto call stack during recursion, therefore giving constraint on recursion depth because stack size is limited. You can 'increase' your recursion depth by man...
0
2009-08-27T07:58:09Z
[ "python", "recursion", "refactoring" ]
How to make this method non-recursive?
1,339,215
<p>Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest.</p> <p>There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. Th...
2
2009-08-27T06:33:42Z
1,343,492
<p>You could modify your recursive version a bit:</p> <pre><code>def Game(x): if x == 0: return True s = set(digit for digit in str(x) if digit != '0') return any(not Game(x-int(digit)) for digit in s) </code></pre> <p>This way, you don't examine digits multiple times. For example, if you are doing 111, y...
0
2009-08-27T20:06:27Z
[ "python", "recursion", "refactoring" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,339,333
<p>Try <a href="http://guppy-pe.sourceforge.net/" rel="nofollow">Guppy</a>.</p> <p>Basicly, you need more information or be able to extract some. Guppy even provides graphical representation of data.</p>
0
2009-08-27T07:04:24Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,339,344
<p>I think you should use different tools. Apparently, the statistics you got is only about GC objects (i.e. objects which may participate in cycles); most notably, it lacks strings.</p> <p>I recommend to use <a href="http://code.google.com/p/pympler/" rel="nofollow">Pympler</a>; this should provide you with more deta...
1
2009-08-27T07:07:27Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,339,400
<p>Have you tried <a href="http://docs.python.org/library/gc.html#gc.set%5Fdebug">gc.set_debug()</a> ?</p> <p>You need to ask yourself simple questions:</p> <ul> <li>Am I using objects with <code>__del__</code> methods? Do I absolutely, unequivocally, need them?</li> <li>Can I get reference cycles in my code? Can't w...
5
2009-08-27T07:26:36Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,339,419
<p>Do you use any extension? They are a wonderful place for memory leaks, and will not be tracked by python tools.</p>
1
2009-08-27T07:34:49Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,343,115
<p>Is DEBUG=False in settings.py?</p> <p>If not Django will happily store all the SQL queries you make which adds up.</p>
18
2009-08-27T18:52:29Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
1,346,194
<p>See <a href="http://nedbatchelder.com/blog/200809/a%5Fserver%5Fmemory%5Fleak.html">this excellent blog post from Ned Batchelder</a> on how they traced down real memory leak in HP's Tabblo. A classic and worth reading.</p>
5
2009-08-28T10:35:55Z
[ "python", "django", "debugging", "memory-leaks" ]
Python: Memory leak debugging
1,339,293
<p>I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap.</p> <p>Following <a href="http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks">http://www.lshift.net/blog/2008/11/14/tracing-p...
24
2009-08-27T06:55:41Z
4,957,480
<p>See <a href="http://opensourcehacker.com/2008/03/07/debugging-django-memory-leak-with-trackrefs-and-guppy/">http://opensourcehacker.com/2008/03/07/debugging-django-memory-leak-with-trackrefs-and-guppy/</a> . Short answer: if you're running django but not in a web-request-based format, you need to manually run <code>...
29
2011-02-10T13:10:05Z
[ "python", "django", "debugging", "memory-leaks" ]
How to fetch rows from below table using google app engine GQL query (python)?
1,339,346
<pre><code>List_name Email ========== ================== andrew adam@gmail.com adam adam@gmail.com smith adam@gmail.com john adam@gmail.com andrew andrew@gmail.com adam andrew@gmail.com smith andrew@gmail.com john andrew@gmail.com andrew john@gmail.com adam ...
1
2009-08-27T07:07:44Z
1,339,588
<p>If you're accustomed to working with a relational database, Google App Engine can seem unusual. The query syntax is <em>very</em> limited. Instead of putting everything into a simple table and writing complicated queries, you have to put everything into complicated data structures and then write simple queries.</p...
4
2009-08-27T08:14:41Z
[ "python", "google-app-engine" ]
How to fetch rows from below table using google app engine GQL query (python)?
1,339,346
<pre><code>List_name Email ========== ================== andrew adam@gmail.com adam adam@gmail.com smith adam@gmail.com john adam@gmail.com andrew andrew@gmail.com adam andrew@gmail.com smith andrew@gmail.com john andrew@gmail.com andrew john@gmail.com adam ...
1
2009-08-27T07:07:44Z
1,339,610
<p>You can use the <a href="http://docs.python.org/tutorial/datastructures.html" rel="nofollow">set</a> function in python you will be able to remove all the duplication. I don't think there is a way of doing it GQL.</p> <pre><code>&gt;&gt;&gt; basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] &gt;&gt;...
1
2009-08-27T08:18:26Z
[ "python", "google-app-engine" ]
How to add bi-directional manytomanyfields in django admin?
1,339,409
<p>In my models.py i have something like:</p> <pre><code>class LocationGroup(models.Model): name = models.CharField(max_length=200) class Report(models.Model): name = models.CharField(max_length=200) locationgroups = models.ManyToManyField(LocationGroup) </code></pre> <p>admin.py (standard):</p> <pre><c...
11
2009-08-27T07:31:08Z
1,340,600
<p>I think yon can combine this sample code (<a href="http://code.djangoproject.com/ticket/897" rel="nofollow">source</a>) wich breaks sync_db</p> <pre><code>class ItemType(meta.Model): name = meta.CharField(maxlength=100) description = meta.CharField(maxlength=250) properties = meta.ManyToManyField('Prope...
2
2009-08-27T11:55:09Z
[ "python", "django", "django-models" ]
How to add bi-directional manytomanyfields in django admin?
1,339,409
<p>In my models.py i have something like:</p> <pre><code>class LocationGroup(models.Model): name = models.CharField(max_length=200) class Report(models.Model): name = models.CharField(max_length=200) locationgroups = models.ManyToManyField(LocationGroup) </code></pre> <p>admin.py (standard):</p> <pre><c...
11
2009-08-27T07:31:08Z
1,370,357
<p>I think what are you are looking for is <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow">admin inlines</a>. In your admin.py you will want to add something like this:</p> <pre><code>class LocationGroupInline(admin.TabularInline): model = LocationGroup cl...
1
2009-09-02T21:56:07Z
[ "python", "django", "django-models" ]
How to add bi-directional manytomanyfields in django admin?
1,339,409
<p>In my models.py i have something like:</p> <pre><code>class LocationGroup(models.Model): name = models.CharField(max_length=200) class Report(models.Model): name = models.CharField(max_length=200) locationgroups = models.ManyToManyField(LocationGroup) </code></pre> <p>admin.py (standard):</p> <pre><c...
11
2009-08-27T07:31:08Z
1,452,189
<p>The workaround I found was to follow the instructions for <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models">ManyToManyFields with intermediary models</a>. Even though you're not using the 'through' model feature, just pretend as if you were and create a ...
8
2009-09-20T22:29:06Z
[ "python", "django", "django-models" ]
Regexp to literally interpret \t as \t and not tab
1,340,162
<p>I'm trying to match a sequence of text with backslashed in it, like a windows path.</p> <p>Now, when I match with regexp in python, it gets the match, but the module interprets all backslashes followed by a valid escape char (i.e. <code>t</code>) as an escape sequence, which is not what I want.</p> <p>How do I get...
1
2009-08-27T10:25:09Z
1,340,168
<p>Use double backslashes with r like this</p> <pre><code>&gt;&gt;&gt; re.match(r"\\t", r"\t") &lt;_sre.SRE_Match object at 0xb7ce5d78&gt; </code></pre> <p>From python <a href="http://docs.python.org/library/re.html#raw-string-notation">docs</a>:</p> <blockquote> <p>When one wants to match a literal backslash, i...
9
2009-08-27T10:25:57Z
[ "python", "regex" ]
Regexp to literally interpret \t as \t and not tab
1,340,162
<p>I'm trying to match a sequence of text with backslashed in it, like a windows path.</p> <p>Now, when I match with regexp in python, it gets the match, but the module interprets all backslashes followed by a valid escape char (i.e. <code>t</code>) as an escape sequence, which is not what I want.</p> <p>How do I get...
1
2009-08-27T10:25:09Z
1,340,172
<p>Always use the <code>r</code> prefix when defining your regex. This will tell Python to treat the string as raw, so it doesn't do any of the standard processing.</p> <pre><code> regex = r'\t' </code></pre>
-1
2009-08-27T10:26:54Z
[ "python", "regex" ]
back-to-back histograms in matplotlib
1,340,338
<p>There is a nice function that draws <a href="http://www.mathworks.co.uk/matlabcentral/fileexchange/23312" rel="nofollow">back to back histograms</a> in Matlab. I need to create a similar graph in matplotlib. Can anyone show a working code example?</p>
3
2009-08-27T11:02:25Z
1,340,368
<p>This <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg04828.html" rel="nofollow">matplotlib users mailing post</a> has some sample code for a <em>bihistogram</em> that goes up and down instead of left and right. <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/bihistog.htm...
2
2009-08-27T11:07:49Z
[ "python", "matplotlib", "histogram" ]
back-to-back histograms in matplotlib
1,340,338
<p>There is a nice function that draws <a href="http://www.mathworks.co.uk/matlabcentral/fileexchange/23312" rel="nofollow">back to back histograms</a> in Matlab. I need to create a similar graph in matplotlib. Can anyone show a working code example?</p>
3
2009-08-27T11:02:25Z
1,340,499
<p>Thanks to the link pointed by Mark Rushakoff, following is what I finally did</p> <pre><code>import numpy as np from matplotlib import pylab as pl dataOne = get_data_one() dataTwo = get_data_two() hN = pl.hist(dataTwo, orientation='horizontal', normed=0, rwidth=0.8, label='ONE') hS = pl.hist(dataOne, bins=hN[1], ...
4
2009-08-27T11:32:36Z
[ "python", "matplotlib", "histogram" ]
Locally Hosted Google App Engine (WebApp Framework / BigTable)
1,340,887
<p>I have been playing with Google App engine a lot lately, from home on personal projects, and I have been really enjoying it. I've converted a few of my coworkers over and we are interested in using GAE for a few of our projects at work.</p> <p>Our work has to be hosted locally on our own servers. I've done some sea...
1
2009-08-27T12:51:28Z
1,342,175
<p>Webapp is a fine choice for a simple web framework but there are plenty of other simple python web frameworks that have instructions for setting them up in your use case (cherrypy, web.py, etc). Since google developed webapp for gae I don't believe they published instructions for setting it up behind apache.</p> <p...
4
2009-08-27T16:19:59Z
[ "python", "google-app-engine", "mod-wsgi" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,340,934
<p>Personally, I create a tests/ folder in my source directory and try to, more or less, mirror my main source code hierarchy with unit test equivalents (having 1 module = 1 unit test module as a rule of thumb).</p> <p>Note that I'm using <a href="http://code.google.com/p/python-nose/">nose</a> and its philosophy is a...
9
2009-08-27T13:00:42Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,340,964
<p>I generally keep test code in a separate module, and ship the module/package and tests in a single distribution. If the user installs using <code>setup.py</code> they can run the tests from the test directory to ensure that everything works in their environment, but only the module's code ends up under <code>Lib/sit...
4
2009-08-27T13:04:00Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,341,011
<p><code>if __name__ == '__main__'</code>, etc. is great for small tests.</p>
0
2009-08-27T13:12:23Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,341,048
<p>There might be reasons other than testing to use the <code>if __name__ == '__main__'</code> check. Keeping the tests in other modules leaves that option open to you. Also - if you refactor the implementation of a module and your tests are in another module that was not edited - you KNOW the tests have not been cha...
2
2009-08-27T13:17:25Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,341,053
<ol> <li>Where you have to if using a library specifying where unittests should live,</li> <li>in the modules themselves for small projects, or</li> <li>in a <code>tests/</code> subdirectory in your package for larger projects.</li> </ol> <p>It's a matter of what works best for the project you're creating.</p> <p>Som...
8
2009-08-27T13:18:00Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,341,060
<p>I usually have them in a separate folder called most often <em>test/</em>. Personally I am not using the if __name__ == '__main__' check, because I use nosetests and it handles the test detection by itself.</p>
1
2009-08-27T13:20:32Z
[ "python", "unit-testing", "testing" ]
Should Python unittests be in a separate module?
1,340,892
<p>Is there a consensus about the best place to put Python unittests?</p> <p>Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (<code>if __name__ == '__main__'</code>, etc.)), or is it better to include the unittests within different m...
14
2009-08-27T12:52:34Z
1,341,119
<h1>YES, do use a separate module.</h1> <p>It does not really make sense to use the <code>__main__</code> trick. Just assume that you have <strong>several files</strong> in your module, and it does not work anymore, because <strong>you don't want to run each source file</strong> separately when testing your module.</p...
9
2009-08-27T13:31:11Z
[ "python", "unit-testing", "testing" ]
Why saving of MSWord document can silently fail?
1,340,950
<p>I need to change some custom properties values in many files. Here is an example of code - how I do it for a single file:</p> <pre><code>import win32com.client MSWord = win32com.client.Dispatch("Word.Application") MSWord.Visible = False doc = MSWord.Documents.Open(file) doc.CustomDocumentProperties('Some Property...
3
2009-08-27T13:02:27Z
1,341,027
<blockquote> <p>(a) Check to see if you have file write access</p> <p>(b) Make sure you code catches using the COMException</p> <p>(C) are you gracefully terminating excel/words when creating multiple documents </p> </blockquote> <p><strong>Darknight</strong></p>
0
2009-08-27T13:14:56Z
[ "python", "automation", "ms-word", "ole" ]