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
How do I validate a Django form containing a file on App Engine with google-app-engine-django?
1,573,913
<p>I have a model and form like so:</p> <pre><code>class Image(BaseModel): original = db.BlobProperty() class ImageForm(ModelForm): class Meta: model = Image </code></pre> <p>I do the following in my view:</p> <pre><code>form = ImageForm(request.POST, request.FILES, instance=image) if form.is_valid(): </cod...
1
2009-10-15T17:32:13Z
1,574,192
<p>The docs for the constructor say:</p> <blockquote> <p>files: dict of file upload values; Django 0.97 or later only</p> </blockquote> <p>Are you using Django 0.97? The bundled Django is 0.96, unless you explicitly select 1.0 or 1.1. Have you tried validating the form without the files parameter?</p>
0
2009-10-15T18:25:45Z
[ "python", "django", "google-app-engine", "django-forms", "validation" ]
How do I validate a Django form containing a file on App Engine with google-app-engine-django?
1,573,913
<p>I have a model and form like so:</p> <pre><code>class Image(BaseModel): original = db.BlobProperty() class ImageForm(ModelForm): class Meta: model = Image </code></pre> <p>I do the following in my view:</p> <pre><code>form = ImageForm(request.POST, request.FILES, instance=image) if form.is_valid(): </cod...
1
2009-10-15T17:32:13Z
1,618,697
<p>It doesn't work with default django version. And bug is <a href="http://code.google.com/p/googleappengine/issues/detail?id=920" rel="nofollow">reported</a>. </p> <p>BTW, default installation raise other exeption. So possible problem with other part of your code.</p>
4
2009-10-24T18:31:37Z
[ "python", "django", "google-app-engine", "django-forms", "validation" ]
How to find duplicates in MySQL
1,574,064
<p>Suppose I have many columns. If 2 columns match and are exactly the same, then they are duplicates.</p> <pre><code>ID | title | link | size | author </code></pre> <p>Suppose if link and size are similar for 2 rows or more, then those rows are duplicates. How do I get those duplicates into a list and process them?...
2
2009-10-15T18:02:15Z
1,574,082
<p>Will return all records that have dups:</p> <pre><code>SELECT theTable.* FROM theTable INNER JOIN ( SELECT link, size FROM theTable GROUP BY link, size HAVING count(ID) &gt; 1 ) dups ON theTable.link = dups.link AND theTable.size = dups.size </code></pre> <p>I like the subquery b/c I can do things like se...
7
2009-10-15T18:05:46Z
[ "python", "mysql" ]
How to find duplicates in MySQL
1,574,064
<p>Suppose I have many columns. If 2 columns match and are exactly the same, then they are duplicates.</p> <pre><code>ID | title | link | size | author </code></pre> <p>Suppose if link and size are similar for 2 rows or more, then those rows are duplicates. How do I get those duplicates into a list and process them?...
2
2009-10-15T18:02:15Z
1,574,092
<p>Assuming that none of <em>id</em>, <em>link</em> or <em>size</em> can be NULL, and <em>id</em> field is the primary key. This gives you the id's of duplicate rows. Beware that same id can be in the results several times, if there are three or more rows with identical link and size values.</p> <pre><code>select a.id...
1
2009-10-15T18:07:48Z
[ "python", "mysql" ]
How to find duplicates in MySQL
1,574,064
<p>Suppose I have many columns. If 2 columns match and are exactly the same, then they are duplicates.</p> <pre><code>ID | title | link | size | author </code></pre> <p>Suppose if link and size are similar for 2 rows or more, then those rows are duplicates. How do I get those duplicates into a list and process them?...
2
2009-10-15T18:02:15Z
1,574,103
<p>If you want to do it exclusively in <code>SQL</code>, some kind of self-join of the table (on equality of <code>link</code> and <code>size</code>) is required, and can be accompanied by different kinds of elaboration. Since you mention Python as well, I assume you want to do the processing in Python; in that case, s...
0
2009-10-15T18:09:11Z
[ "python", "mysql" ]
How to find duplicates in MySQL
1,574,064
<p>Suppose I have many columns. If 2 columns match and are exactly the same, then they are duplicates.</p> <pre><code>ID | title | link | size | author </code></pre> <p>Suppose if link and size are similar for 2 rows or more, then those rows are duplicates. How do I get those duplicates into a list and process them?...
2
2009-10-15T18:02:15Z
1,574,362
<p>After you remove the duplicates from the MySQL table, you can add a unique index to the table so no more duplicates can be inserted:</p> <pre><code>create unique index theTable_index on theTable (link,size); </code></pre>
1
2009-10-15T19:02:04Z
[ "python", "mysql" ]
Plotting time in Python with Matplotlib
1,574,088
<p>I have an array of timestamps in the format (HH:MM:SS.mmmmmm) and another array of floating point numbers, each corresponding to a value in the timestamp array.</p> <p>Can I plot time on the x axis and the numbers on the y-axis using Matplotlib?</p> <p>I was trying to, but somehow it was only accepting arrays of f...
63
2009-10-15T18:07:10Z
1,574,146
<p>You must first convert your timestamps to Python <code>datetime</code> objects (use <code>datetime.strptime</code>). Then use <code>date2num</code> to convert the dates to matplotlib format.</p> <p>Plot the dates and values using <a href="http://matplotlib.org/api/pyplot_api.html?highlight=plot_date#matplotlib.pypl...
77
2009-10-15T18:18:26Z
[ "python", "graph", "plot", "matplotlib" ]
Plotting time in Python with Matplotlib
1,574,088
<p>I have an array of timestamps in the format (HH:MM:SS.mmmmmm) and another array of floating point numbers, each corresponding to a value in the timestamp array.</p> <p>Can I plot time on the x axis and the numbers on the y-axis using Matplotlib?</p> <p>I was trying to, but somehow it was only accepting arrays of f...
63
2009-10-15T18:07:10Z
16,428,019
<p>You can also plot the timestamp, value pairs using <a href="http://matplotlib.org/api/pyplot_api.html?highlight=plot_date#matplotlib.pyplot.plot" rel="nofollow">pyplot.plot</a> (after parsing them from their string representation). (Tested with matplotlib versions 1.2.0 and 1.3.1.)</p> <p>Example:</p> <pre><code>i...
29
2013-05-07T20:30:05Z
[ "python", "graph", "plot", "matplotlib" ]
How to match columns in MySQL
1,574,418
<p>Everyone knows the "=" sign.</p> <pre><code>SELECT * FROM mytable WHERE column1 = column2; </code></pre> <p>However, what if I have different contents in column1 and column2...but they are VERY similar? (maybe off by a space, or have a word that's different).</p> <p>Is it possible to:</p> <pre><code>SELECT * FRO...
3
2009-10-15T19:11:03Z
1,574,473
<p>What you are looking for is called <a href="http://en.wikipedia.org/wiki/Levenshtein%5Fdistance">Levenstein distance</a>. It gives you the number value which discribes the difference between two strings. </p> <p>In MySQL you have to write stored procedure for that. <a href="http://codejanitor.com/wp/2007/02/10/leve...
5
2009-10-15T19:18:34Z
[ "python", "sql", "mysql", "string", "pattern-matching" ]
How to match columns in MySQL
1,574,418
<p>Everyone knows the "=" sign.</p> <pre><code>SELECT * FROM mytable WHERE column1 = column2; </code></pre> <p>However, what if I have different contents in column1 and column2...but they are VERY similar? (maybe off by a space, or have a word that's different).</p> <p>Is it possible to:</p> <pre><code>SELECT * FRO...
3
2009-10-15T19:11:03Z
1,574,523
<p>Lukasz Lysik posted a reference to a stored procedure that can do the fuzzy match from inside the database. If you will want to do this as an ongoing task, that is your best bet.</p> <p>But if you want to do this as a one-off task, and if you might want to do complicated checks, or if you want to do something comp...
0
2009-10-15T19:28:19Z
[ "python", "sql", "mysql", "string", "pattern-matching" ]
Python object that monitors changes in objects
1,574,458
<p>I want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this:</p> <pre><code>&gt;&gt;&gt; library = Library() &gt;&gt;&gt; library.is_changed(object1) False &gt;&gt;&gt; object1....
3
2009-10-15T19:16:52Z
1,574,538
<p>I haven't heard of anything like this... but you could write it pretty easily. Use a dictionary to store a name:hash pair for each object, then use the <code>pickle</code> module to save the dictionary.</p>
0
2009-10-15T19:30:54Z
[ "python", "hash" ]
Python object that monitors changes in objects
1,574,458
<p>I want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this:</p> <pre><code>&gt;&gt;&gt; library = Library() &gt;&gt;&gt; library.is_changed(object1) False &gt;&gt;&gt; object1....
3
2009-10-15T19:16:52Z
1,574,556
<p>It sounds like you're describing the <a href="http://en.wikipedia.org/wiki/Observer%5Fpattern" rel="nofollow">observer pattern</a>. Check here:</p> <ul> <li><a href="http://rudd-o.com/projects/python-observable/" rel="nofollow">http://rudd-o.com/projects/python-observable/</a> </li> <li><a href="http://twistedmatri...
2
2009-10-15T19:33:28Z
[ "python", "hash" ]
Python object that monitors changes in objects
1,574,458
<p>I want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this:</p> <pre><code>&gt;&gt;&gt; library = Library() &gt;&gt;&gt; library.is_changed(object1) False &gt;&gt;&gt; object1....
3
2009-10-15T19:16:52Z
1,574,755
<p>Here is an implementation for you. Note that the objects you monitor must be hashable and picklable. Note also the use of a <code>WeakKeyDictionary</code> which means that the <code>Monitor</code> won't stop the monitored objects from being deleted.</p> <pre><code>from weakref import WeakKeyDictionary from cPickl...
5
2009-10-15T20:12:01Z
[ "python", "hash" ]
Python object that monitors changes in objects
1,574,458
<p>I want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this:</p> <pre><code>&gt;&gt;&gt; library = Library() &gt;&gt;&gt; library.is_changed(object1) False &gt;&gt;&gt; object1....
3
2009-10-15T19:16:52Z
1,575,197
<p>I am stole idea from Nick Craig-Wood, and change it to Mix-Class. Come out more easyly using, as for me</p> <pre><code>from cPickle import dumps #base class for monitoring changes class ChangesMonitor: _cm_last_dump = None def is_chaged(self): prev_dump = self._cm_last_dump self._cm_last_du...
1
2009-10-15T21:29:05Z
[ "python", "hash" ]
Building Django app using Comet/Orbited on Apache, use mod_wsgi or mod_python?
1,574,513
<p>Building a Django app on a VPS. I am not very experienced with setting up my own server, but I decided to try a VPS this time around. </p> <p>I have been doing a bunch of research to learn how to "properly" setup a LAMPython server using the Apache worker MPM. Naturally, the mod_python vs mod_wsgi debate came up. ...
0
2009-10-15T19:26:32Z
1,574,586
<ol> <li><p>Yes, absolutely.</p></li> <li><p>I would probably use Orbited as implemented by Dark Porter - It's the simplest solution to get your code running, and implemented in pure python. Not to mention, based on Twisted and thus <em>very</em> scalable, and has a well-established community of Django users.</p></li> ...
3
2009-10-15T19:39:19Z
[ "python", "django", "apache", "comet" ]
syntax error on `If` line
1,574,530
<p>My code:</p> <pre><code>#!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 != 0: print aaa1 / aaa2 </code></pre> <p>The error I receive:</p> <pre><code>$ python test2.py File "test2.py", line 7 If aaa2 != 0: print aaa1 / aaa2 ^ SyntaxError: invalid...
1
2009-10-15T19:29:15Z
1,574,542
<p><code>if</code> must be written in lower case.</p> <p>Furthermore,</p> <ul> <li>Write function names in lower case (see <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a>, the Python style guide).</li> <li>Write the body of an <code>if</code>-clause on a separate line.</li> <li>Though in t...
16
2009-10-15T19:31:14Z
[ "python", "syntax" ]
syntax error on `If` line
1,574,530
<p>My code:</p> <pre><code>#!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 != 0: print aaa1 / aaa2 </code></pre> <p>The error I receive:</p> <pre><code>$ python test2.py File "test2.py", line 7 If aaa2 != 0: print aaa1 / aaa2 ^ SyntaxError: invalid...
1
2009-10-15T19:29:15Z
1,574,546
<p>How about</p> <pre><code>def Objects9(aaa1, aaa2): if aaa2 != 0: print aaa1 / aaa2 </code></pre> <p>Python keywords are case sensitive, so you must write 'if' instead of 'If', 'for' instead of 'fOR', et cetera.</p>
3
2009-10-15T19:31:45Z
[ "python", "syntax" ]
syntax error on `If` line
1,574,530
<p>My code:</p> <pre><code>#!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 != 0: print aaa1 / aaa2 </code></pre> <p>The error I receive:</p> <pre><code>$ python test2.py File "test2.py", line 7 If aaa2 != 0: print aaa1 / aaa2 ^ SyntaxError: invalid...
1
2009-10-15T19:29:15Z
1,574,548
<p>It's the capital 'I' on "If". Change it to "if" and it will work.</p>
4
2009-10-15T19:32:11Z
[ "python", "syntax" ]
Efficient way to convert strings from split function to ints in Python
1,574,678
<p>I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is wi...
7
2009-10-15T19:59:54Z
1,574,700
<p>You can <a href="http://docs.python.org/3.0/library/functions.html#map" rel="nofollow"><code>map</code></a> the function <a href="http://docs.python.org/3.0/library/functions.html#int" rel="nofollow"><code>int</code></a> on each substring, or use a <a href="http://www.python.org/dev/peps/pep-0202/" rel="nofollow">li...
4
2009-10-15T20:02:45Z
[ "python", "variables", "casting" ]
Efficient way to convert strings from split function to ints in Python
1,574,678
<p>I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is wi...
7
2009-10-15T19:59:54Z
1,574,703
<p>efficient as in fewer lines of code?</p> <pre><code>(xval,yval,zval) = [int(s) for s in file.split('-')] </code></pre>
9
2009-10-15T20:03:06Z
[ "python", "variables", "casting" ]
Efficient way to convert strings from split function to ints in Python
1,574,678
<p>I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is wi...
7
2009-10-15T19:59:54Z
1,574,718
<p>My original suggestion with a list comprehension.</p> <pre><code>test = '8743-12083-15' lst_int = [int(x) for x in test.split("-")] </code></pre> <p><strong>EDIT:</strong></p> <p>As to which is most efficient (cpu-cyclewise) is something that should always be tested. Some quick testing on my Python 2.6 install in...
24
2009-10-15T20:04:31Z
[ "python", "variables", "casting" ]
Efficient way to convert strings from split function to ints in Python
1,574,678
<p>I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is wi...
7
2009-10-15T19:59:54Z
1,574,802
<p>note: you might want to pick a different name for <code>file</code> as it shadows the buildtin</p> <p>this works in Python 2 and 3</p> <pre><code> xval,yval,zval = map(int,file.split('-')) </code></pre>
3
2009-10-15T20:22:16Z
[ "python", "variables", "casting" ]
Python multiprocessing: restrict number of cores used
1,575,067
<p>I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system.</p> <p>I assume the ...
6
2009-10-15T21:04:33Z
1,575,133
<p>You might want to look into the following package:</p> <p><a href="http://pypi.python.org/pypi/affinity" rel="nofollow">http://pypi.python.org/pypi/affinity</a></p> <p>It is a package that uses sched_setaffinity and sched _getaffinity.</p> <p>The drawback is that it is highly Linux-specific.</p>
3
2009-10-15T21:16:49Z
[ "python", "multiprocessing" ]
Python multiprocessing: restrict number of cores used
1,575,067
<p>I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system.</p> <p>I assume the ...
6
2009-10-15T21:04:33Z
1,575,304
<p>If you are on linux, use taskset when you launch the program</p> <p>A child created via fork(2) inherits its parent’s CPU affinity mask. The affinity mask is preserved across an execve(2).</p> <blockquote> <p>TASKSET(1)<br /> Linux User’s Manual<br /> TASKSET(1)</p> <p>NAME taskset - ret...
2
2009-10-15T21:50:24Z
[ "python", "multiprocessing" ]
Python multiprocessing: restrict number of cores used
1,575,067
<p>I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system.</p> <p>I assume the ...
6
2009-10-15T21:04:33Z
1,575,395
<p>On my dual-core machine the total number of processes is honoured, i.e. if I do</p> <pre><code>p = Pool(1) </code></pre> <p>Then I only see one CPU in use at any given time. The process is free to migrate to a different <em>processor</em>, but then the other processor is idle. I don't see how all your processors c...
2
2009-10-15T22:06:38Z
[ "python", "multiprocessing" ]
Python multiprocessing: restrict number of cores used
1,575,067
<p>I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system.</p> <p>I assume the ...
6
2009-10-15T21:04:33Z
1,575,735
<p>Probably a dumb observation, pls forgive my inexperience in Python.</p> <p>But your while loop polling for the finished tasks is not going to sleep and is consuming one core all time, isn't it?</p> <p>The other thing to notice is that if your tasks are I/O bound, you M should be adjusted to the number of parallel ...
1
2009-10-15T23:50:03Z
[ "python", "multiprocessing" ]
Python multiprocessing: restrict number of cores used
1,575,067
<p>I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system.</p> <p>I assume the ...
6
2009-10-15T21:04:33Z
5,444,316
<p>you might try using pypar module. I am not sure how to use affinity to set cpu affinity of to a certain core using affinity</p>
1
2011-03-26T18:25:00Z
[ "python", "multiprocessing" ]
How to read .ARC files from the Heritrix crawler using Python?
1,575,442
<p>I looked at the Heritrix documentation website, and they listed a Python .ARC file reader. However, it is 404 not found when I clicked on it. <a href="http://crawler.archive.org/articles/developer%5Fmanual/arcs.html" rel="nofollow">http://crawler.archive.org/articles/developer%5Fmanual/arcs.html</a></p> <p>Does any...
1
2009-10-15T22:17:46Z
1,575,561
<p>Nothing a little Googling can't find: <a href="http://archive-access.cvs.sourceforge.net/viewvc/archive-access/archive-access/projects/hedaern/" rel="nofollow">http://archive-access.cvs.sourceforge.net/viewvc/archive-access/archive-access/projects/hedaern/</a></p>
0
2009-10-15T22:51:50Z
[ "python", "web-crawler" ]
Preempting __del__ hmmm
1,575,567
<p>I need to preempt <code>__del__</code> and I want to know what is the right way to do this. Basically my question in code is this..</p> <pre><code>class A: def __init__(self): self.log = logging.getLogger() self.log.debug("In init") self.closed = False def close(self): self...
0
2009-10-15T22:52:42Z
1,575,581
<p><code>__del__</code> isn't a true destructor. It is called before an object is destroyed to free any resources it is holding. It need not worry about freeing memory itself.</p> <p>You can always call the parent class' <code>__del__</code>, too, if you are inheriting a class which may also have open resources.</p>
4
2009-10-15T22:56:30Z
[ "python", "class" ]
Preempting __del__ hmmm
1,575,567
<p>I need to preempt <code>__del__</code> and I want to know what is the right way to do this. Basically my question in code is this..</p> <pre><code>class A: def __init__(self): self.log = logging.getLogger() self.log.debug("In init") self.closed = False def close(self): self...
0
2009-10-15T22:52:42Z
1,575,590
<p>If you're looking to call the GC manually then call gc.collect().</p>
1
2009-10-15T22:59:37Z
[ "python", "class" ]
Preempting __del__ hmmm
1,575,567
<p>I need to preempt <code>__del__</code> and I want to know what is the right way to do this. Basically my question in code is this..</p> <pre><code>class A: def __init__(self): self.log = logging.getLogger() self.log.debug("In init") self.closed = False def close(self): self...
0
2009-10-15T22:52:42Z
1,575,623
<p>Please use the <code>with</code> statement for this.</p> <p>See <a href="http://docs.python.org/reference/compound%5Fstmts.html#the-with-statement" rel="nofollow">http://docs.python.org/reference/compound%5Fstmts.html#the-with-statement</a></p> <blockquote> <p>The with statement guarantees that if the <strong>...
3
2009-10-15T23:10:11Z
[ "python", "class" ]
Ensure that only one instance of a class gets run
1,575,680
<p>I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test..</p> <pre><code>import ...
2
2009-10-15T23:33:01Z
1,575,702
<p>Look up "singleton pattern". It looks like Python you are dealing with, so you might have to search a bit harder. I now there are plenty of examples in C++.</p>
1
2009-10-15T23:41:41Z
[ "python", "singleton" ]
Ensure that only one instance of a class gets run
1,575,680
<p>I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test..</p> <pre><code>import ...
2
2009-10-15T23:33:01Z
1,575,704
<p>What you need is to implement the <a href="http://en.wikipedia.org/wiki/Singleton%5Fpattern" rel="nofollow">Singleton</a> Design pattern in python</p> <p>I've found this <a href="http://code.activestate.com/recipes/52558/" rel="nofollow">implementation</a> I hope it helps</p>
1
2009-10-15T23:42:33Z
[ "python", "singleton" ]
Ensure that only one instance of a class gets run
1,575,680
<p>I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test..</p> <pre><code>import ...
2
2009-10-15T23:33:01Z
1,575,713
<p>See <a href="http://code.activestate.com/recipes/52558/">singleton in python</a>.</p>
5
2009-10-15T23:44:13Z
[ "python", "singleton" ]
Ensure that only one instance of a class gets run
1,575,680
<p>I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test..</p> <pre><code>import ...
2
2009-10-15T23:33:01Z
1,576,188
<p>I believe that the problem with the code shown is that you set <code>self.active=True</code>. This will create an attribute for the instance and set that to <code>True</code>, whereas I believe that you want to set the active of the class itself to <code>True</code>. So, instead of <code>self.active=True</code>, try...
0
2009-10-16T05:11:48Z
[ "python", "singleton" ]
Ensure that only one instance of a class gets run
1,575,680
<p>I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test..</p> <pre><code>import ...
2
2009-10-15T23:33:01Z
15,541,090
<p>When you import a module in python, it is natural singleton. For example, in util.py, you have:</p> <pre><code> class MyClass(object): ...... g_my_obj = MyClass() </code></pre> <p>in a.py, you import g_my_obj:</p> <pre><code>from util import g_my_obj </code></pre> <p>in b.py, you import g_my_obj a...
1
2013-03-21T06:44:47Z
[ "python", "singleton" ]
Python datetime subtraction - wrong results?
1,575,779
<p>I must be doing something wrong here, any ideas?</p> <pre><code>&gt;&gt;&gt; (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 </code></pre> <p>It should be getting more than that many seconds.</p>
1
2009-10-16T00:04:46Z
1,575,787
<p><code>timedelta.seconds</code> isn't the total number of seconds, it's the remainder in seconds after days have been accounted for. Using your example:</p> <pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)) datetime.timedelta(1, 2098) </...
1
2009-10-16T00:09:05Z
[ "python", "datetime" ]
Python datetime subtraction - wrong results?
1,575,779
<p>I must be doing something wrong here, any ideas?</p> <pre><code>&gt;&gt;&gt; (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 </code></pre> <p>It should be getting more than that many seconds.</p>
1
2009-10-16T00:04:46Z
1,575,790
<p><code>timedelta.seconds</code> gives you the <code>seconds</code> field of the timedelta. But it also has a <code>days</code> field (and a <code>milliseconds</code> field).</p> <p>So you would want something like </p> <pre><code>delta = datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16) delt...
9
2009-10-16T00:10:05Z
[ "python", "datetime" ]
Python datetime subtraction - wrong results?
1,575,779
<p>I must be doing something wrong here, any ideas?</p> <pre><code>&gt;&gt;&gt; (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 </code></pre> <p>It should be getting more than that many seconds.</p>
1
2009-10-16T00:04:46Z
1,575,792
<p>It's actually returning a timedelta which has a day field also i.e.</p> <p><code>c.seconds = 2098</code></p> <p>but </p> <p><code>c.days = 1</code></p>
2
2009-10-16T00:10:16Z
[ "python", "datetime" ]
Python datetime subtraction - wrong results?
1,575,779
<p>I must be doing something wrong here, any ideas?</p> <pre><code>&gt;&gt;&gt; (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 </code></pre> <p>It should be getting more than that many seconds.</p>
1
2009-10-16T00:04:46Z
1,575,796
<p><code>datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)</code> returns a <code>datetime.timedelta</code> object which has a <code>days</code> attribute. The difference that you are calculating is actually 1 day and 2098 seconds. </p>
1
2009-10-16T00:11:05Z
[ "python", "datetime" ]
Python callback with SWIG wrapped type
1,575,802
<p>I'm trying to add a python callback to a C++ library as illustrated:</p> <pre><code>template&lt;typename T&gt; void doCallback(shared_ptr&lt;T&gt; data) { PyObject* pyfunc; //I have this already PyObject* args = Py_BuildValue("(O)", data); PyEval_CallObject(pyfunc,args); } </code></pre> <p>This fails beca...
2
2009-10-16T00:13:39Z
1,580,899
<p><code>shared_ptr&lt;T&gt;</code> for unknown <code>T</code> isn't a type, so SWIG can't hope to wrap it. What you need to do is provide a SWIG wrapping for each instance of <code>shared_ptr</code> that you intend to use. So if for example you want to be able to <code>doCallback()</code> with both <code>shared_ptr&...
0
2009-10-16T23:31:33Z
[ "c++", "python", "swig" ]
Python callback with SWIG wrapped type
1,575,802
<p>I'm trying to add a python callback to a C++ library as illustrated:</p> <pre><code>template&lt;typename T&gt; void doCallback(shared_ptr&lt;T&gt; data) { PyObject* pyfunc; //I have this already PyObject* args = Py_BuildValue("(O)", data); PyEval_CallObject(pyfunc,args); } </code></pre> <p>This fails beca...
2
2009-10-16T00:13:39Z
1,597,811
<p>My first answer misunderstood the question completely, so let's try this again.</p> <p>Your central problem is the free type parameter <code>T</code> in the definition of <code>doCallback</code>. As you point out in your question, there's no way to make a SWIG object out of a <code>shared_ptr&lt;T&gt;</code> witho...
0
2009-10-20T23:11:22Z
[ "c++", "python", "swig" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,575,953
<p>In Python:</p> <pre><code>def isfileok(filename): f = open(filename) for line in f: pieces = line.split('\t') if len(pieces) != 8: return False if not pieces[3].isdigit(): return False return True </code></pre> <p>I assume that by "column no. 4" you mean the 4th one, hence the <code>[...
4
2009-10-16T01:00:07Z
[ "python", "perl" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,576,031
<p>In Perl:</p> <pre><code>while (&lt;&gt;) { if (! /^[^\t]+\t[^\t]+\t[^\t]+\t\d+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+$/) { die "Line $. is bad: $_"; } } </code></pre> <p>Checks to see that the line starts with one or more non-tabs, followed by a tab, followed by one or more non-tabs, followed by a tab, followed b...
2
2009-10-16T01:32:48Z
[ "python", "perl" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,576,033
<p>The following Python code should display the line as you have indicated:</p> <pre><code>for n,line in enumerate(open("filename")): line=line.split() if len(line)!=8: print "line %d error" % n+1 if not line[3].isdigit(): print "line %d error" % n+1 </code></pre>
0
2009-10-16T01:34:22Z
[ "python", "perl" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,576,121
<p>In Perl</p> <pre><code>while(&lt;&gt;) { my @F=split/\t/; die "Invalid line: $_" if @F!=8 or $F[3]!~/^-?\d+$/; } </code></pre>
8
2009-10-16T04:46:05Z
[ "python", "perl" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,579,866
<p>It's very easy work for Perl:</p> <pre><code>perl -F\\t -ane'die"Invalid!"if@F!=8||$F[3]!~/^-?\d+$/' CHECKME </code></pre>
4
2009-10-16T19:13:23Z
[ "python", "perl" ]
How can I check that a column in a tab-delimited file has valid values?
1,575,936
<p>I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers.</p> <p>By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer?</p>
1
2009-10-16T00:56:11Z
1,580,440
<h3>validate-input.py</h3> <p>Read files given on the command-line or stdin. Print invalid lines. Return code is zero if there are no errors or one otherwise.</p> <pre><code>import fileinput, sys def error(msg, line): print &gt;&gt; sys.stderr, "%s:%d:%s\terror: %s" % ( fileinput.filename(), fileinput.fi...
1
2009-10-16T21:08:58Z
[ "python", "perl" ]
Python - Twisted and Unit Tests
1,575,966
<p>I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response.</p> <p>Our HTTP server is using Twisted....
16
2009-10-16T01:03:08Z
1,575,983
<p>I believe that for unit testing within Twisted you're supposed to use <a href="http://twistedmatrix.com/trac/wiki/TwistedTrial">TwistedTrial</a> (it's a core component, i.e., comes with the Twisted tarball in the twisted/trial directory). However, as the URL I've pointed to says, the doc is mostly by having a look ...
7
2009-10-16T01:09:02Z
[ "python", "unit-testing", "twisted" ]
Python - Twisted and Unit Tests
1,575,966
<p>I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response.</p> <p>Our HTTP server is using Twisted....
16
2009-10-16T01:03:08Z
1,575,992
<p>Here's some info: <a href="http://twistedmatrix.com/projects/core/documentation/howto/testing.html">Writing tests for Twisted code using Trial</a></p> <p>You should also look at the -help of the trial command. There'a lot of good stuff in trial! But it's not always easy to do testing in a async application. Good lu...
17
2009-10-16T01:12:36Z
[ "python", "unit-testing", "twisted" ]
Python - Twisted and Unit Tests
1,575,966
<p>I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response.</p> <p>Our HTTP server is using Twisted....
16
2009-10-16T01:03:08Z
1,576,026
<p>There is a <a href="http://twistedmatrix.com/trac/ticket/2066" rel="nofollow">known bug</a> with Twisted (that probably won't get fixed) where re-starting the reactor causes a crash.</p> <p>This is why your unit tests don't work. </p> <p>As well as using <a href="http://twistedmatrix.com/projects/core/documentatio...
3
2009-10-16T01:30:33Z
[ "python", "unit-testing", "twisted" ]
Python - Twisted and Unit Tests
1,575,966
<p>I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response.</p> <p>Our HTTP server is using Twisted....
16
2009-10-16T01:03:08Z
1,580,776
<p>As others mentioned, you should be using Trial for unit tests in Twisted.</p> <p>You also should be unit testing from the bottom up - that's what the "unit" in unit testing implies. Test your data and logic before you test your interface. For a HTTP interface, you should be calling processGET, processPOST, etc wi...
4
2009-10-16T22:45:23Z
[ "python", "unit-testing", "twisted" ]
Sorting strings with integers and text in Python
1,575,971
<p>I'm making a stupid little game that saves your score in a highscores.txt file. </p> <p>My problem is sorting the lines. Here's what I have so far. </p> <p>Maybe an alphanumeric sorter for python would help? Thanks.</p> <pre><code>import os.path import string def main(): #Check if the file exists file_...
0
2009-10-16T01:05:07Z
1,575,993
<p>after <code>words = f.readlines()</code>, try something like:</p> <pre><code>headers = words.pop(0) def myway(aline): i = 0 while aline[i].isdigit(): i += 1 score = int(aline[:i]) return score words.sort(key=myway, reverse=True) words.insert(0, headers) </code></pre> <p>The key (;-) idea is to make ...
4
2009-10-16T01:12:40Z
[ "python", "string", "alphanumeric" ]
Sorting strings with integers and text in Python
1,575,971
<p>I'm making a stupid little game that saves your score in a highscores.txt file. </p> <p>My problem is sorting the lines. Here's what I have so far. </p> <p>Maybe an alphanumeric sorter for python would help? Thanks.</p> <pre><code>import os.path import string def main(): #Check if the file exists file_...
0
2009-10-16T01:05:07Z
1,576,151
<p>Doing a simple string sort on your </p> <pre><code>new_score = str(score) + ".........." + name </code></pre> <p>items isn't going to work since, for example str(1000) &lt; str(500). In other words, 1000 will come before 500 in an alphanumeric sort.</p> <p>Alex's answer is good in that it demonstrates the use of...
0
2009-10-16T04:57:44Z
[ "python", "string", "alphanumeric" ]
Sorting strings with integers and text in Python
1,575,971
<p>I'm making a stupid little game that saves your score in a highscores.txt file. </p> <p>My problem is sorting the lines. Here's what I have so far. </p> <p>Maybe an alphanumeric sorter for python would help? Thanks.</p> <pre><code>import os.path import string def main(): #Check if the file exists file_...
0
2009-10-16T01:05:07Z
1,576,203
<p>I guess something went wrong when you pasted from Alex's answer, so here is your code with a sort in there</p> <pre><code> import os.path def main(): #Check if the file exists file_exists = os.path.exists("highscores.txt") score = 500 name = "Nicholas" #If the file doesn't exist, create one w...
0
2009-10-16T05:19:03Z
[ "python", "string", "alphanumeric" ]
Sorting strings with integers and text in Python
1,575,971
<p>I'm making a stupid little game that saves your score in a highscores.txt file. </p> <p>My problem is sorting the lines. Here's what I have so far. </p> <p>Maybe an alphanumeric sorter for python would help? Thanks.</p> <pre><code>import os.path import string def main(): #Check if the file exists file_...
0
2009-10-16T01:05:07Z
1,576,226
<p>I'd like to encourage you to store your high scores in a more robust format. In particular I suggest JSON.</p> <pre><code>import simplejson as json # Python 2.x # import json # Python 3.x d = {} d["version"] = 1 d["highscores"] = [[100, "Steve"], [200, "Ken"], [400, "Denise"]] s = json.dumps(d) print s # prints...
1
2009-10-16T05:26:06Z
[ "python", "string", "alphanumeric" ]
Sorting strings with integers and text in Python
1,575,971
<p>I'm making a stupid little game that saves your score in a highscores.txt file. </p> <p>My problem is sorting the lines. Here's what I have so far. </p> <p>Maybe an alphanumeric sorter for python would help? Thanks.</p> <pre><code>import os.path import string def main(): #Check if the file exists file_...
0
2009-10-16T01:05:07Z
1,576,309
<p>What you want is probably what's generally known as a "Natural Sort". Searching for "natural sort python" gives many results, but there's some good discussion on <a href="http://code.activestate.com/recipes/285264/" rel="nofollow">ASPN</a>.</p>
0
2009-10-16T05:49:38Z
[ "python", "string", "alphanumeric" ]
Python on multiprocessor machines: multiprocessing or a non-GIL interpreter
1,575,985
<p>This is more a style question. For CPU bound processes that really benefit for having multiple cores, do you typically use the multiprocessing module or use threads with an interpreter that doesn't have the GIL? I've used the multiprocessing library only lightly, but also have no experience with anything besides C...
1
2009-10-16T01:10:27Z
1,576,107
<p>Take a look at Parallel Python (<a href="http://www.parallelpython.com" rel="nofollow">www.parallelpython.com</a>) -- I've used to to nicely split up work among the processors on my quad-core box. It even supports clusters!</p>
1
2009-10-16T02:07:05Z
[ "python", "multiprocessing" ]
Python on multiprocessor machines: multiprocessing or a non-GIL interpreter
1,575,985
<p>This is more a style question. For CPU bound processes that really benefit for having multiple cores, do you typically use the multiprocessing module or use threads with an interpreter that doesn't have the GIL? I've used the multiprocessing library only lightly, but also have no experience with anything besides C...
1
2009-10-16T01:10:27Z
1,576,115
<p>I don't really see a "style" argument to be made here, either way -- both <code>multiprocessing</code> in CPython 2.6, and <code>threading</code> in (e.g.) the current versions of Jython and IronPython, let you code in extremely similar ways (and styles;-). So, I'd choose on the basis of very "hard-nosed" considera...
3
2009-10-16T02:09:34Z
[ "python", "multiprocessing" ]
Python pdb not breaking in files properly?
1,576,266
<p>I wish I could provide a simple sample case that occurs using standard library code, but unfortunately it only happens when using one of our in-house libraries that in turn is built on top of sql alchemy.</p> <p>Basically, the problem is that this <code>break</code> command:</p> <pre><code>(Pdb) print sqlalchemy.e...
0
2009-10-16T05:39:53Z
1,580,988
<p>I wonder if somehow there's an old .pyc that can't be deleted because of permissions being messed up. Nuke all of the .pycs in your python-path, and see if that helps.</p> <p><a href="http://rpatterson.net/blog/emacs-pdb-and-eggs" rel="nofollow">This blog post</a> might be related to your trouble.</p>
0
2009-10-17T00:11:11Z
[ "python", "pdb" ]
Python pdb not breaking in files properly?
1,576,266
<p>I wish I could provide a simple sample case that occurs using standard library code, but unfortunately it only happens when using one of our in-house libraries that in turn is built on top of sql alchemy.</p> <p>Basically, the problem is that this <code>break</code> command:</p> <pre><code>(Pdb) print sqlalchemy.e...
0
2009-10-16T05:39:53Z
2,634,056
<p>I don't suppose this is yet another problem caused by setuptools? I ask because I notice the ".egg" in that path...</p>
0
2010-04-14T00:06:24Z
[ "python", "pdb" ]
Python pdb not breaking in files properly?
1,576,266
<p>I wish I could provide a simple sample case that occurs using standard library code, but unfortunately it only happens when using one of our in-house libraries that in turn is built on top of sql alchemy.</p> <p>Basically, the problem is that this <code>break</code> command:</p> <pre><code>(Pdb) print sqlalchemy.e...
0
2009-10-16T05:39:53Z
14,806,375
<p>What version of python are running? I observe similar behavior on python 2.7.3. Curiously, I do <em>not</em> see the same behavior on ipython 0.12.1.</p> <p>In python 2.7.3, the debugger and the stack trace get the point where an exception occurred wrong.</p> <p>In ipython 0.12.1, the debugger and the stack trac...
0
2013-02-11T05:25:00Z
[ "python", "pdb" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
1,576,372
<p>Not Sphinx, but several of the sites at <a href="http://codespeak.net/" rel="nofollow">http://codespeak.net/</a> are done with scripts that take ReST text, generates HTML and uploads them to the site. I didn't write those scripts though, but I've used them.</p> <p>It's a reasonable way to generate sites if the site...
2
2009-10-16T06:06:14Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
1,576,635
<p>Doug hellmann, author of the 'Python Module of the Week' does his site using Sphinx.</p> <p><a href="http://www.doughellmann.com/PyMOTW/" rel="nofollow">http://www.doughellmann.com/PyMOTW/</a></p> <p>He has several posts which cover sphinx topics that can probably help you on your way:</p> <p><a href="http://doug...
11
2009-10-16T07:30:40Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
1,577,278
<p>I redid my personal website (<a href="http://homepage.mac.com/s_lott/steve/" rel="nofollow">http://homepage.mac.com/s_lott/steve/</a>) in Sphinx. It works nicely. <em>Sadly, the SO markup mangles the <code>_</code> in my URL.</em></p> <p>I also rewrote the entire <em>Introduction to Programming for Non-Programmer...
1
2009-10-16T10:21:02Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
1,588,720
<p>I've done it at <a href="http://reinout.vanrees.org/weblog" rel="nofollow">http://reinout.vanrees.org/weblog</a>. The key trick is to add a preprocessor step. I've got my blog entries in a <code>weblog/yyyy/mm/dd/</code> folder structure.</p> <p>A script iterates through that folder structure, creating <code>index...
15
2009-10-19T13:39:15Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
3,218,401
<p>It's worth knowing that there is an RSS extension for sphinx in the sphinx-contrib extensions, called <code>sphinxcontrib.feed</code> It and many other fun Sphinx things live at <a href="http://bitbucket.org/birkenfeld/sphinx-contrib/">http://bitbucket.org/birkenfeld/sphinx-contrib/</a></p> <p>(Disclaimer: I wrote ...
6
2010-07-10T08:03:58Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
9,238,379
<p>As of now (February, 2012), there are different resources available to do what you want:</p> <p>A blog engine based on sphinx: <a href="http://tinkerer.me/">http://tinkerer.me/</a></p> <p>Reinout Van Rees' blog: <a href="https://github.com/reinout/reinout.vanrees.org">https://github.com/reinout/reinout.vanrees.org...
13
2012-02-11T06:41:23Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
13,031,104
<p>If you need to write in <a href="http://docutils.sourceforge.net/rst.html">reStructuredText </a>, you should try <a href="http://docs.getpelican.com/">Pelican</a>. </p> <p>Pelican is a static site generator, written in Python. You'll be able to write your blog entries directly in reStructuredText or Markdown.</p>
10
2012-10-23T13:05:57Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Using Sphinx to write personal websites and blogs
1,576,340
<p><a href="http://sphinx.pocoo.org/">Sphinx</a> is a Python library to generate nice documentation from a set of <a href="http://docutils.sourceforge.net/rst.html">ReST</a> formatted text files.</p> <p>I wonder if any one has written Sphinx plugins to make it <strong>generate personal websites and blogs</strong>.</p>...
31
2009-10-16T05:56:08Z
29,449,180
<p>Check out <a href="http://ablog.readthedocs.org/" rel="nofollow">ABlog for Sphinx</a></p> <p>I am in the process of starting a blog myself using it.</p> <p>I stumbled across it while I was going through my feeds in feedly. I searched about it and found it interesting. It also has Disqus integration, and can genera...
3
2015-04-04T17:08:40Z
[ "python", "plugins", "website", "blogs", "python-sphinx" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
1,576,663
<p>try first of all clean up both of HTML by lxml.html, and the check the difference by difflib</p>
0
2009-10-16T07:41:41Z
[ "python", "html", "diff", "prettify" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
1,576,759
<p>There's <code>diff_prettyHtml()</code> in the <a href="https://code.google.com/p/google-diff-match-patch/" rel="nofollow">diff-match-patch</a> library from Google.</p>
20
2009-10-16T08:15:22Z
[ "python", "html", "diff", "prettify" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
1,579,110
<p>Generally, if you want some HTML to render in a prettier way, you do it by adding CSS.</p> <p>For instance, if you generate the HTML like this:</p> <pre><code>import difflib import sys fromfile = "xxx" tofile = "zzz" fromlines = open(fromfile, 'U').readlines() tolines = open(tofile, 'U').readlines() diff = diffl...
12
2009-10-16T16:40:35Z
[ "python", "html", "diff", "prettify" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
1,593,316
<p>A copy of my own answer from <a href="http://stackoverflow.com/questions/31722/anyone-have-a-diff-algorithm-for-rendered-html/1593296#1593296">here</a>.</p> <p><hr /></p> <p>What about <a href="http://code.google.com/p/daisydiff/" rel="nofollow">DaisyDiff</a> (<a href="http://code.google.com/p/daisydiff/" rel="nof...
1
2009-10-20T08:58:22Z
[ "python", "html", "diff", "prettify" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
29,867,928
<p>I recently posted a python script that does just this: <a href="https://github.com/wagoodman/diff2HtmlCompare" rel="nofollow">diff2HtmlCompare</a> (follow the link for a screenshot). Under the hood it wraps difflib and uses pygments for syntax highlighting.</p>
1
2015-04-25T16:42:34Z
[ "python", "html", "diff", "prettify" ]
Generate pretty diff html in Python
1,576,459
<p>I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). </p> <p>I have tried difflib.HtmlDiff but it's output is less than pretty. </p> <p>Is there a way in Python (or external library) that would generate clean ...
20
2009-10-16T06:39:20Z
35,338,425
<p>Since the .. library from google seams to have no active development any more, I suggest to use <a href="https://github.com/askeing/diff_py" rel="nofollow">diff_py</a></p> <p>From the github page:</p> <blockquote> <p>The simple diff tool which is written by Python. The diff result can be printed in console or to...
0
2016-02-11T11:42:31Z
[ "python", "html", "diff", "prettify" ]
Why does else behave differently in for/while statements as opposed to if/try statements?
1,576,537
<p>I have recently stumbled over a seeming inconsistency in Python's way of dealing with else clauses in different compound statements. Since Python is so well designed, I'm sure that there is a good explanation, but I can't think of it.</p> <p>Consider the following:</p> <pre><code>if condition: do_something() el...
6
2009-10-16T06:58:27Z
1,576,552
<p>The <code>for else</code> construct executes the <code>else</code> clause if no <code>break</code> statement was executed for the loop, <a href="http://docs.python.org/reference/compound_stmts.html#the-for-statement" rel="nofollow">as described here</a> For example, this else clause is never evaluated</p> <pre><co...
13
2009-10-16T07:03:50Z
[ "python", "flow-control" ]
Why does else behave differently in for/while statements as opposed to if/try statements?
1,576,537
<p>I have recently stumbled over a seeming inconsistency in Python's way of dealing with else clauses in different compound statements. Since Python is so well designed, I'm sure that there is a good explanation, but I can't think of it.</p> <p>Consider the following:</p> <pre><code>if condition: do_something() el...
6
2009-10-16T06:58:27Z
1,576,579
<p>Yes, as Eli mentioned, the else clause is executed only if you don't break. It stops you from implementing code like this:</p> <pre><code>for i in range(1,10): if i % 5 == 0: print i break if i % 5 != 0: print "nothing divisible by 5" </code></pre> <p>Which is roughly equivalent here, but han...
4
2009-10-16T07:10:47Z
[ "python", "flow-control" ]
Why does else behave differently in for/while statements as opposed to if/try statements?
1,576,537
<p>I have recently stumbled over a seeming inconsistency in Python's way of dealing with else clauses in different compound statements. Since Python is so well designed, I'm sure that there is a good explanation, but I can't think of it.</p> <p>Consider the following:</p> <pre><code>if condition: do_something() el...
6
2009-10-16T06:58:27Z
1,576,622
<p>Well, it depends how you see it. You can look at the elses like this (excuse the screaming, its the only way to make emphasis in code):</p> <pre><code>if condition: do_something() IF THE PREVIOUS CONDITION WAS FALSE: do_something_else() </code></pre> <p>Now, there is an obvious similarity between if/else and...
5
2009-10-16T07:28:03Z
[ "python", "flow-control" ]
How can I capture iSight frames with Python in Snow Leopard?
1,576,593
<p>I have the following PyObjC script:</p> <pre><code>from Foundation import NSObject import QTKit error = None capture_session = QTKit.QTCaptureSession.alloc().init() print 'capture_session', capture_session device = QTKit.QTCaptureDevice.defaultInputDeviceWithMediaType_(QTKit.QTMediaTypeVideo) print 'device', device...
5
2009-10-16T07:16:44Z
1,578,283
<p>Your problem here is that you don't have an event loop. If you want to do this as a standalone script, you'll have to figure out how to create one. The PyObjC XCode templates automatically set that up for you with:</p> <pre><code>from PyObjCTools import AppHelper AppHelper.runEventLoop() </code></pre> <p>Trying to...
3
2009-10-16T14:08:43Z
[ "python", "osx-snow-leopard", "pyobjc", "qtkit", "isight" ]
How can I capture iSight frames with Python in Snow Leopard?
1,576,593
<p>I have the following PyObjC script:</p> <pre><code>from Foundation import NSObject import QTKit error = None capture_session = QTKit.QTCaptureSession.alloc().init() print 'capture_session', capture_session device = QTKit.QTCaptureDevice.defaultInputDeviceWithMediaType_(QTKit.QTMediaTypeVideo) print 'device', device...
5
2009-10-16T07:16:44Z
2,192,651
<p>You should give a try to <a href="http://github.com/motmot/pycamiface" rel="nofollow">motmot's camiface</a> library from Andrew Straw. It also works with firewire cameras, but it works also with the isight, which is what you are looking for.</p> <p>From the tutorial:</p> <pre><code>import motmot.cam_iface.cam_ifac...
2
2010-02-03T14:35:57Z
[ "python", "osx-snow-leopard", "pyobjc", "qtkit", "isight" ]
pyqt installation problem in mac osx snow leopard
1,576,629
<p>I'm following a tutorial of making desktop apps. with python and qt4, I downloaded and installed qt creator ide, created the .ui file and then I had to convert it using pyuic4, I've been trying a lot of things and still can't do it.</p> <p>I thought that pyuic4 would be installed with Qt creator IDE, but it seems t...
4
2009-10-16T07:29:28Z
1,583,091
<p>I've solved it, you have to use the python of macports instead of the default that comes with OS X, to do that install python_select through macports:</p> <pre><code>sudo port install python_select sudo python_select python26 </code></pre>
8
2009-10-17T20:09:25Z
[ "python", "osx", "qt", "macports" ]
pyqt installation problem in mac osx snow leopard
1,576,629
<p>I'm following a tutorial of making desktop apps. with python and qt4, I downloaded and installed qt creator ide, created the .ui file and then I had to convert it using pyuic4, I've been trying a lot of things and still can't do it.</p> <p>I thought that pyuic4 would be installed with Qt creator IDE, but it seems t...
4
2009-10-16T07:29:28Z
2,085,719
<p>I made <a href="http://chinbilly.blogspot.com/2010/01/building-pyqt4-on-snow-leopard.html" rel="nofollow">some notes on building and install PyQt4 on Mac Snow Leopard</a>.</p> <p>The order is important, and there are some quirks with 64-bit libraries. The default Mac Qt libs are Carbon (32 bit), whereas Mac system ...
3
2010-01-18T11:45:56Z
[ "python", "osx", "qt", "macports" ]
pyqt installation problem in mac osx snow leopard
1,576,629
<p>I'm following a tutorial of making desktop apps. with python and qt4, I downloaded and installed qt creator ide, created the .ui file and then I had to convert it using pyuic4, I've been trying a lot of things and still can't do it.</p> <p>I thought that pyuic4 would be installed with Qt creator IDE, but it seems t...
4
2009-10-16T07:29:28Z
9,559,996
<p>I spent a while finding the package name in Homebrew. It seems to be:</p> <pre><code>brew install pyqt </code></pre>
0
2012-03-04T23:45:10Z
[ "python", "osx", "qt", "macports" ]
Releasing Python GIL while in C++ code
1,576,737
<p>I've got a library written in C++ which I wrap using SWIG and use in python. Generally there is one class with few methods. The problem is that calling these methods may be time consuming - they may hang my application (GIL is not released when calling these methods). So my question is: </p> <p>What is the simplest...
6
2009-10-16T08:07:48Z
1,576,959
<p>You can use the same API call as for C. No difference. Include "python.h" and call the appoproate function.</p> <p>Also, see if SWIG doesn't have a typemap or something to indicate that the GIL shuold not be held for a specific function.</p>
1
2009-10-16T09:01:03Z
[ "c++", "python", "swig", "gil" ]
Releasing Python GIL while in C++ code
1,576,737
<p>I've got a library written in C++ which I wrap using SWIG and use in python. Generally there is one class with few methods. The problem is that calling these methods may be time consuming - they may hang my application (GIL is not released when calling these methods). So my question is: </p> <p>What is the simplest...
6
2009-10-16T08:07:48Z
1,577,009
<p>Not having any idea what SWIG is I'll attempt an answer anyway :)</p> <p>Use something like this to release/acquire the GIL:</p> <pre><code>class GILReleaser { GILReleaser() : save(PyEval_SaveThread()) {} ~GILReleaser() { PyEval_RestoreThread(save); } PyThreadState* save; }; </code></pre>...
4
2009-10-16T09:12:03Z
[ "c++", "python", "swig", "gil" ]
Releasing Python GIL while in C++ code
1,576,737
<p>I've got a library written in C++ which I wrap using SWIG and use in python. Generally there is one class with few methods. The problem is that calling these methods may be time consuming - they may hang my application (GIL is not released when calling these methods). So my question is: </p> <p>What is the simplest...
6
2009-10-16T08:07:48Z
1,578,357
<p>The real problem is that SWIG is not documented well (I saw hints to use changelog for searching ;) ). </p> <p>Ok, I found out that I can do inline functions in SWIG and use macros to release/acquire GIL, it looks like this:</p> <pre><code>%inline %{ void wrappedFunction(OriginalObject *o, &lt;parameters&gt;) ...
5
2009-10-16T14:21:01Z
[ "c++", "python", "swig", "gil" ]
SVN hook environment issues with Python script
1,576,784
<p>I am experiencing issues with my SVN post-commit hook and the fact that it is executed with an empty environment. Everything was working fine till about two weeks ago when my systems administrator upgraded a few things on the server.</p> <p>My post-commit hook executes a Python script that uses a SVN module to ema...
1
2009-10-16T08:21:49Z
1,576,956
<p>Your system administrator might have forgotten to execute this command.</p> <pre><code>echo /usr/local/lib/svn-python \ &gt; /usr/local/lib/python2.x/site-packages/subversion.pth </code></pre> <p>This is written in subversion/bindings/swig/INSTALL in the source distribution.</p>
1
2009-10-16T09:00:25Z
[ "python", "svn" ]
SVN hook environment issues with Python script
1,576,784
<p>I am experiencing issues with my SVN post-commit hook and the fact that it is executed with an empty environment. Everything was working fine till about two weeks ago when my systems administrator upgraded a few things on the server.</p> <p>My post-commit hook executes a Python script that uses a SVN module to ema...
1
2009-10-16T08:21:49Z
1,593,977
<p>Got it! I missed the <strong>export</strong> in my post-commit hook script! It should have been:</p> <p>export PYTHONPATH=/usr/local/lib/svn-python</p> <p>Problem solved :)</p>
1
2009-10-20T11:33:08Z
[ "python", "svn" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,800
<p>From the beginning of this line, <a href="http://rubular.com" rel="nofollow">"Any number of word characters (letter, number, underscore)"</a> until the end of the line.</p> <p>I am unsure as to why it's in square brackets, as circle brackets (e.g. "(" and ")") are correct if you want the matched text returned.</p>
0
2009-10-16T08:26:14Z
[ "python", "regex", "syntax" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,801
<p>\w refers to 0 or more alphanumeric characters and the underscore. the * in your case is also inside the character class, so [\w*] would match all of [a-zA-Z0-9_*] (the * is interpreted literally)</p> <p>See <a href="http://www.regular-expressions.info/reference.html" rel="nofollow">http://www.regular-expressions.i...
0
2009-10-16T08:26:20Z
[ "python", "regex", "syntax" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,806
<p>\w is equivalent to [a-zA-Z0-9_] I don't understand the * after it or the [] around it, because \w already is a class and * in class definitions makes no sense. </p>
0
2009-10-16T08:27:00Z
[ "python", "regex", "syntax" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,812
<p><strong>Quick answer:</strong> Match a string consisting of a single character, where that character is alphanumeric (letters, numbers) an underscore (<code>_</code>) or an asterisk (<code>*</code>).</p> <p><strong>Details:</strong></p> <ul> <li>The "<code>\w</code>" means "any word character" which usually means ...
28
2009-10-16T08:27:57Z
[ "python", "regex", "syntax" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,824
<p>As exhuma said, \w is any word-class character (alphanumeric as Jonathan clarifies).</p> <p>However because it is in square brackets it will match:</p> <ol> <li>a single alphanumeric character OR</li> <li>an asterisk (*)</li> </ol> <p>So the whole regular expression matches:</p> <ul> <li>the beginning of a line ...
1
2009-10-16T08:31:06Z
[ "python", "regex", "syntax" ]
In regex, what does \w* mean?
1,576,789
<p>In Python. r^[\w*]$</p> <p>whats that mean?</p>
6
2009-10-16T08:23:41Z
1,576,845
<p>As said above \w means any word. so you could use this in the context of below</p> <pre><code>view.aspx?url=[\w] </code></pre> <p>which means you can have any word as the value of the "url=" parameter</p>
0
2009-10-16T08:36:28Z
[ "python", "regex", "syntax" ]
How to use ? and ?: and : in REGEX for Python?
1,576,957
<p>I understand that </p> <pre><code>* = "zero or more" ? = "zero or more" ...what's the difference? </code></pre> <p>Also, ?: &lt;&lt; my book uses this, it says its a "subtlety" but I don't know what exactly these do!</p>
2
2009-10-16T09:00:34Z
1,576,962
<p>? = zero or one</p> <p>you use (?:) for grouping w/o saving the group in a temporary variable as you would with ()</p>
2
2009-10-16T09:02:01Z
[ "python", "regex", "syntax" ]
How to use ? and ?: and : in REGEX for Python?
1,576,957
<p>I understand that </p> <pre><code>* = "zero or more" ? = "zero or more" ...what's the difference? </code></pre> <p>Also, ?: &lt;&lt; my book uses this, it says its a "subtlety" but I don't know what exactly these do!</p>
2
2009-10-16T09:00:34Z
1,576,963
<p><code>?</code> does not mean "zero or more", it means "zero or one".</p>
1
2009-10-16T09:02:04Z
[ "python", "regex", "syntax" ]
How to use ? and ?: and : in REGEX for Python?
1,576,957
<p>I understand that </p> <pre><code>* = "zero or more" ? = "zero or more" ...what's the difference? </code></pre> <p>Also, ?: &lt;&lt; my book uses this, it says its a "subtlety" but I don't know what exactly these do!</p>
2
2009-10-16T09:00:34Z
1,576,991
<blockquote> <p>?: &lt;&lt; my book uses this, it says its a "subtlety" but I don't know what exactly these do!</p> </blockquote> <p>If that’s indeed what your book says, then I advise getting a better book.</p> <p>Inside parentheses (more precisely: right after an opening parenthesis), <code>?</code> has another...
4
2009-10-16T09:06:53Z
[ "python", "regex", "syntax" ]
How to use ? and ?: and : in REGEX for Python?
1,576,957
<p>I understand that </p> <pre><code>* = "zero or more" ? = "zero or more" ...what's the difference? </code></pre> <p>Also, ?: &lt;&lt; my book uses this, it says its a "subtlety" but I don't know what exactly these do!</p>
2
2009-10-16T09:00:34Z
1,577,001
<p>As Manu already said, <code>?</code> means "zero or one time". It is the same as <code>{0,1}</code>.</p> <p>And by <code>?:</code>, you probably meant <code>(?:X)</code>, where X is some other string. This is called a "non-capturing group". Normally when you wrap parenthesis around something, you group what is matc...
3
2009-10-16T09:10:14Z
[ "python", "regex", "syntax" ]
What does this function do?
1,577,031
<pre><code>def fun1(a): for i in range(len(a)): a[i] = a[i] * a[i] return a </code></pre>
-4
2009-10-16T09:16:10Z
1,577,038
<p>It takes an array as parameter and returns the same array with each member squared.</p> <p>EDIT:</p> <p>Since you modified your question from 'What does this function do' to 'What is some code to execute this function', here is an example:</p> <pre><code>def fun1(a): for i in range(len(a)): a[i] = a[i...
12
2009-10-16T09:18:37Z
[ "python" ]