title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Django Timed Events
2,377,661
<p>I want to schedule events to happen for my users. Is there an efficient way to do this in Python/Django easily? I'd prefer not to poll a priority queue.</p> <p>Thanks!</p> <p>Edit: I want to clarify that this job is run per user, for potentially hundreds or thousands of users.</p>
1
2010-03-04T08:01:34Z
2,377,719
<p>This may help:</p> <p><a href="http://stackoverflow.com/questions/573618/django-set-up-a-scheduled-job">http://stackoverflow.com/questions/573618/django-set-up-a-scheduled-job</a></p>
2
2010-03-04T08:13:34Z
[ "python", "django", "scheduling", "scheduled-tasks" ]
Django Timed Events
2,377,661
<p>I want to schedule events to happen for my users. Is there an efficient way to do this in Python/Django easily? I'd prefer not to poll a priority queue.</p> <p>Thanks!</p> <p>Edit: I want to clarify that this job is run per user, for potentially hundreds or thousands of users.</p>
1
2010-03-04T08:01:34Z
2,377,723
<p>How about <a href="http://code.google.com/p/django-cron/" rel="nofollow">django-cron</a>? </p>
0
2010-03-04T08:14:31Z
[ "python", "django", "scheduling", "scheduled-tasks" ]
Django Timed Events
2,377,661
<p>I want to schedule events to happen for my users. Is there an efficient way to do this in Python/Django easily? I'd prefer not to poll a priority queue.</p> <p>Thanks!</p> <p>Edit: I want to clarify that this job is run per user, for potentially hundreds or thousands of users.</p>
1
2010-03-04T08:01:34Z
2,378,230
<p>You should probably look at: <a href="http://celeryproject.org/" rel="nofollow">http://celeryproject.org/</a></p> <p>From the website:</p> <blockquote> <p>"Celery is already used in production to process millions of tasks a day."</p> </blockquote>
4
2010-03-04T09:56:10Z
[ "python", "django", "scheduling", "scheduled-tasks" ]
Rendering mathematical notation in Python / OpenGL?
2,377,944
<p>How can I render mathematical notations / expressions in Python with OpenGL?</p> <p>I'm actually using <a href="http://www.pyglet.org/" rel="nofollow">pyglet</a> however it uses OpenGL.</p> <p>Such things as <a href="http://en.wikipedia.org/wiki/Quadratic_formula#Quadratic_formula" rel="nofollow">this</a>:</p> <p...
3
2010-03-04T08:59:07Z
2,377,956
<p>I would say generate suitable <a href="http://en.wikipedia.org/wiki/LaTeX">latex</a> expression, rendering it into an image, then load the image as a texture.</p>
8
2010-03-04T09:02:04Z
[ "python", "math", "opengl", "rendering", "pyglet" ]
Rendering mathematical notation in Python / OpenGL?
2,377,944
<p>How can I render mathematical notations / expressions in Python with OpenGL?</p> <p>I'm actually using <a href="http://www.pyglet.org/" rel="nofollow">pyglet</a> however it uses OpenGL.</p> <p>Such things as <a href="http://en.wikipedia.org/wiki/Quadratic_formula#Quadratic_formula" rel="nofollow">this</a>:</p> <p...
3
2010-03-04T08:59:07Z
2,377,996
<p>You can use GL_TEXTURE_RECTANGLE_ARB opengl extension to quickly load dynamicaly generated image of arbitrary size into OpenGL texture. You can look for python examples of using dynamic vector graphics with opengl at <a href="http://cairographics.org/OpenGL/" rel="nofollow">http://cairographics.org/OpenGL/</a>, tho...
2
2010-03-04T09:11:19Z
[ "python", "math", "opengl", "rendering", "pyglet" ]
Rendering mathematical notation in Python / OpenGL?
2,377,944
<p>How can I render mathematical notations / expressions in Python with OpenGL?</p> <p>I'm actually using <a href="http://www.pyglet.org/" rel="nofollow">pyglet</a> however it uses OpenGL.</p> <p>Such things as <a href="http://en.wikipedia.org/wiki/Quadratic_formula#Quadratic_formula" rel="nofollow">this</a>:</p> <p...
3
2010-03-04T08:59:07Z
2,383,568
<p>I don't know about the OpenGL bit. But <a href="http://matplotlib.sourceforge.net/" rel="nofollow">matplotlib</a> has a <a href="http://matplotlib.sourceforge.net/api/mathtext_api.html#module-matplotlib.mathtext" rel="nofollow"><code>matplotlib.mathtext</code></a> module for rendering a sub-set of TeX mathematical e...
1
2010-03-04T23:45:59Z
[ "python", "math", "opengl", "rendering", "pyglet" ]
Doxygen C++ comment string parser in python?
2,377,985
<p>Does anybody know of a python module to parse a doxygen style C++ comment string? I mean a string like this (simple example):</p> <pre><code> /** * A constructor. * A more elaborate description of the constructor. * @param param1 test1 * @param param2 test2 */ </code></pre> <p>and I would like to e...
7
2010-03-04T09:09:45Z
2,398,862
<p>You should take a look at how doxygen is implemented to see how it handles parsing. I very much doubt it uses regex.</p>
1
2010-03-08T01:48:24Z
[ "c++", "python", "parsing", "doxygen" ]
Doxygen C++ comment string parser in python?
2,377,985
<p>Does anybody know of a python module to parse a doxygen style C++ comment string? I mean a string like this (simple example):</p> <pre><code> /** * A constructor. * A more elaborate description of the constructor. * @param param1 test1 * @param param2 test2 */ </code></pre> <p>and I would like to e...
7
2010-03-04T09:09:45Z
2,453,626
<p>You might be able to set something up using the <a href="http://simpleparse.sourceforge.net/" rel="nofollow">SimpleParse</a> module, but this does require creating an EBNF grammar which might be more investment than you are interested in.</p> <p>The Sphinx/Doxygen bridge (<a href="http://github.com/michaeljones/bre...
4
2010-03-16T10:42:28Z
[ "c++", "python", "parsing", "doxygen" ]
C++ iostreams and python
2,378,005
<p>Is it possible to interoperate with a C++ iostream and python? I'm using boost-python and want to wrap a function that has istream and ostream as arguments.</p>
8
2010-03-04T09:12:53Z
2,380,870
<p>Is <a href="http://cci.lbl.gov/cctbx_sources/boost_adaptbx/python_streambuf.h" rel="nofollow">http://cci.lbl.gov/cctbx_sources/boost_adaptbx/python_streambuf.h</a> what you are looking for? It comes from the Phenix project. </p> <p>(license information at <a href="http://cci.lbl.gov/cctbx_sources/boost_adaptbx/LICE...
2
2010-03-04T16:24:30Z
[ "python", "iostream", "boost-python" ]
How to write back to a certain cell in google doc spreadsheet using python
2,378,104
<p>So the problem is, i get some information from first column of the row (for example A2 ) from the spreadsheet, then i will do some checking with that information, after that i want to write back to the next column in the row the result, how do i do that? Is there a certain function to allow me to indicate the column...
1
2010-03-04T09:32:37Z
2,380,524
<p>Sure, the docs for Google Spreadsheet API in Python are <a href="http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html" rel="nofollow">here</a>. To create or update a cell, see <a href="http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html#updateCell" rel="nofollow"...
1
2010-03-04T15:38:31Z
[ "python", "cell", "spreadsheet" ]
How to embed a graphical interactive IronPython shell in an application?
2,378,110
<p>I've tried the obvious path in my pet open source project <a href="http://code.google.com/p/revitpythonshell/">RevitPythonShell</a> (a plugin for the building modeling software Autodesk Revit Architecture 2010): <code>code.interact()</code> with the IronPython engine set up to use .NET streams for <code>STDIN</code>...
9
2010-03-04T09:33:48Z
2,382,322
<p>Ok, then I have two possible answers. One in the comment above....and another far simpler (no intellisense, no syntax highlighting):</p> <p><a href="http://www.codeproject.com/KB/edit/irontextbox2.aspx" rel="nofollow">http://www.codeproject.com/KB/edit/irontextbox2.aspx</a></p> <p>It's by JoeSox, and it is for Ir...
3
2010-03-04T20:00:44Z
[ "python", "shell", "ironpython", "embedding", "read-eval-print-loop" ]
How to embed a graphical interactive IronPython shell in an application?
2,378,110
<p>I've tried the obvious path in my pet open source project <a href="http://code.google.com/p/revitpythonshell/">RevitPythonShell</a> (a plugin for the building modeling software Autodesk Revit Architecture 2010): <code>code.interact()</code> with the IronPython engine set up to use .NET streams for <code>STDIN</code>...
9
2010-03-04T09:33:48Z
9,811,946
<p>I was looking for a similar thing and I discovered that the IronLab project contains a nice IronPython console. The source code can be found here <a href="http://code.google.com/p/ironlab/source/browse/trunk/IronPythonConsole/">http://code.google.com/p/ironlab/source/browse/trunk/IronPythonConsole/</a>.</p>
6
2012-03-21T19:59:35Z
[ "python", "shell", "ironpython", "embedding", "read-eval-print-loop" ]
Tab not working properly in Python
2,378,119
<p>I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV IDE (for Eclipse). The problem is that when I wrote the scripts in NotePad++ I used "TAB" for indentation, and now when I open them with PyDEV, every time I try to write a new line instead of "TABS" PyDEV inserts spaces. (even if...
3
2010-03-04T09:35:00Z
2,378,139
<p>Yes, follow <a href="http://www.python.org/dev/peps/pep-0008/">http://www.python.org/dev/peps/pep-0008/</a> which states:</p> <blockquote> <p>Indentation</p> <pre><code>Use 4 spaces per indentation level. </code></pre> </blockquote> <p>Replace all your tabs with spaces, and set Notepad++ to use spaces instead o...
7
2010-03-04T09:39:08Z
[ "python", "eclipse", "eclipse-plugin", "pydev" ]
Tab not working properly in Python
2,378,119
<p>I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV IDE (for Eclipse). The problem is that when I wrote the scripts in NotePad++ I used "TAB" for indentation, and now when I open them with PyDEV, every time I try to write a new line instead of "TABS" PyDEV inserts spaces. (even if...
3
2010-03-04T09:35:00Z
2,379,282
<p>Tabs are problematic—different people can choose different widths in their editor settings, and then you have bad formatting (for e.g. C) or execution problems (Python). So spaces are better for getting consistently sensible results. But one issue with that is that some editors still default to using tabs.</p> <p...
4
2010-03-04T12:41:03Z
[ "python", "eclipse", "eclipse-plugin", "pydev" ]
Tab not working properly in Python
2,378,119
<p>I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV IDE (for Eclipse). The problem is that when I wrote the scripts in NotePad++ I used "TAB" for indentation, and now when I open them with PyDEV, every time I try to write a new line instead of "TABS" PyDEV inserts spaces. (even if...
3
2010-03-04T09:35:00Z
17,719,748
<p>Putting aside the tabs vs spaces argument. </p> <p>To fix this you need to chose 'toggle force tabs' in preferences for eclipse to use tabs instead of the default spaces.</p>
1
2013-07-18T09:35:18Z
[ "python", "eclipse", "eclipse-plugin", "pydev" ]
Why does nose finds tests in files with only 644 permission?
2,378,146
<p>Today I ran a bunch of doctests using Python 2.6 on a Ubuntu 9.10 with nose :</p> <pre><code>nosetests --with-doctest Ran 0 tests in 0.001s OK </code></pre> <p>WTF? I had tests in that files, why didn't that work?</p> <p>I changed permission to 644:</p> <pre><code>sudo chmod 644 * -R nosetests --with-doctest Ra...
7
2010-03-04T09:40:02Z
2,378,714
<p>Try the <code>--exe</code> flag:</p> <pre><code>$ nosetests --help ... --exe Look for tests in python modules that are executable. Normal behavior is to exclude executable modules, since they may not be import-safe [NOSE_INCLUDE_EXE] </code></pre>
9
2010-03-04T11:08:42Z
[ "python", "permissions", "nose", "doctest" ]
Need help on python sqlite?
2,378,364
<p>1.I have a list of data and a sqlite DB filled with past data along with some stats on each data. I have to do the following operations with them.</p> <ul> <li>Check if each item in the list is present in DB. if no then collect some stats on the new item and add them to DB.</li> <li>Check if each item in DB is in t...
0
2010-03-04T10:14:41Z
2,378,530
<ol> <li><p>It does not need to check anything, just use INSERT OR IGNORE in first case (just make sure you have corresponding unique fields so INSERT would not create duplicates) and DELETE FROM tbl WHERE data NOT IN ('first item', 'second item', 'third item') in second case.</p></li> <li><p>As it is stated in the off...
0
2010-03-04T10:40:12Z
[ "python", "sqlite", "multithreading" ]
Accessing python variables in a list
2,378,393
<p>In the following code below, how to retrieve the value of id,Id has multiple values in it.How to access the values of id and update it to result1</p> <pre><code>def parse_results (): try: xml = minidom.parseString(new_results) for xmlchild in xmldoc.childNodes[0].childNodes : result...
0
2010-03-04T10:19:04Z
2,379,276
<p>Why are you using minidom? It is really boring to use.</p> <p>I suggest you move to <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">element tree</a>:</p> <pre><code>import xml.etree.ElementTree as et d = et.fromstring(''' &lt;doc&gt; &lt;info&gt;&lt;firstname&gt;firstname&lt;/fi...
0
2010-03-04T12:40:08Z
[ "python", "class", "django-views" ]
python datetime.time operation
2,378,521
<pre><code>t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10 t2 = datetime.time(13, 13, 0, tzinfo=GMT1()) #13:13 t3 = datetime.time(23, 55, 0, tzinfo=GMT1()) #23:55 t4 = datetime.time(01, 10, 0, tzinfo=GMT1()) #01:10 </code></pre> <p>I need the minute interval between between two times. For instance a non working...
1
2010-03-04T10:39:17Z
2,378,597
<pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; t1 = datetime.time(12, 10, 0) &gt;&gt;&gt; t2 = datetime.time(13, 13, 0) &gt;&gt;&gt; today = datetime.datetime.today() &gt;&gt;&gt; t1n = datetime.datetime.combine(today, t1) &gt;&gt;&gt; t2n = datetime.datetime.combine(today + datetime.timedelta(days=int(t2 &lt; t1...
0
2010-03-04T10:50:30Z
[ "python", "datetime", "intervals" ]
python datetime.time operation
2,378,521
<pre><code>t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10 t2 = datetime.time(13, 13, 0, tzinfo=GMT1()) #13:13 t3 = datetime.time(23, 55, 0, tzinfo=GMT1()) #23:55 t4 = datetime.time(01, 10, 0, tzinfo=GMT1()) #01:10 </code></pre> <p>I need the minute interval between between two times. For instance a non working...
1
2010-03-04T10:39:17Z
2,378,645
<p>How's this?</p> <pre><code>def minute_interval(start,end): start_sec= (start.hour*60+start.minute)*60+start.second end_sec= (end.hour*60+end.minute)*60+end.second return (end_sec-start_sec)/60.0 </code></pre>
0
2010-03-04T10:57:41Z
[ "python", "datetime", "intervals" ]
python datetime.time operation
2,378,521
<pre><code>t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10 t2 = datetime.time(13, 13, 0, tzinfo=GMT1()) #13:13 t3 = datetime.time(23, 55, 0, tzinfo=GMT1()) #23:55 t4 = datetime.time(01, 10, 0, tzinfo=GMT1()) #01:10 </code></pre> <p>I need the minute interval between between two times. For instance a non working...
1
2010-03-04T10:39:17Z
2,378,646
<p>Assuming time are in same timezone and no DST</p> <pre><code>import datetime def minute_interval(start, end): reverse = False if start &gt; end: start, end = end, start reverse = True delta = (end.hour - start.hour)*60 + end.minute - start.minute + (end.second - start.second)/60...
2
2010-03-04T10:57:48Z
[ "python", "datetime", "intervals" ]
Accessing child nodein an xml in python
2,378,834
<p>How to retrieve the value of type in the below XML</p> <pre><code> &lt;info&gt;&lt;category&gt;Flip&lt;/category&gt;&lt;info&gt;2&lt;/info&gt;&lt;type&gt;Tree&lt;/type&gt;&lt;/info&gt; </code></pre>
1
2010-03-04T11:27:13Z
2,379,063
<p>Using ElementTree:</p> <pre><code>import xml.etree.ElementTree as E e = E.parse("test.xml") print(e.find("type").text) </code></pre> <p>Using minidom:</p> <pre><code>import xml.dom.minidom d = xml.dom.minidom.parse("test.xml") print(d.getElementsByTagName("type")[0].firstChild.data) </code></pre> <p>Using <a hre...
2
2010-03-04T12:05:18Z
[ "python", "xml", "xml-parsing" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,378,977
<pre><code>&gt;&gt;&gt; next(i for i, j in enumerate(' xyz') if j.strip()) 3 </code></pre> <p>or</p> <pre><code>&gt;&gt;&gt; next(i for i, j in enumerate(' xyz') if j not in string.whitespace) 3 </code></pre> <p>in versions of Python &lt; 2.5 you'll have to do:</p> <pre><code>(...).next() </code></pre>
2
2010-03-04T11:49:45Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,378,988
<pre><code>&gt;&gt;&gt; s = " xyz" &gt;&gt;&gt; len(s) - len(s.lstrip()) 3 </code></pre>
25
2010-03-04T11:51:32Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,379,009
<pre><code>&gt;&gt;&gt; string = " xyz" &gt;&gt;&gt; next(idx for idx, chr in enumerate(string) if not chr.isspace()) 3 </code></pre>
-1
2010-03-04T11:54:28Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,379,204
<pre><code>&gt;&gt;&gt; string = " xyz" &gt;&gt;&gt; map(str.isspace,string).index(False) 3 </code></pre>
-1
2010-03-04T12:28:19Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,379,269
<p>Looks like the "regexes can do anything" brigade have taken the day off, so I'll fill in:</p> <pre><code>&gt;&gt;&gt; tests = [u'foo', u' foo', u'\xA0foo'] &gt;&gt;&gt; import re &gt;&gt;&gt; for test in tests: ... print len(re.match(r"\s*", test, re.UNICODE).group(0)) ... 0 1 1 &gt;&gt;&gt; </code></pre> <p>F...
1
2010-03-04T12:38:58Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
2,379,278
<pre><code>import re def prefix_length(s): m = re.match('(\s+)', s) if m: return len(m.group(0)) return 0 </code></pre>
0
2010-03-04T12:40:24Z
[ "python", "string", "string-matching" ]
Returning the lowest index for the first non whitespace character in a string in Python
2,378,962
<p>What's the shortest way to do this in Python?</p> <pre><code>string = " xyz" </code></pre> <p>must return index = 3</p>
7
2010-03-04T11:47:00Z
13,616,230
<p>Many of the previous solutions are iterating at several points in their proposed solutions. And some make copies of the data (the string). re.match(), strip(), enumerate(), isspace()are duplicating behind the scene work. The </p> <pre><code>next(idx for idx, chr in enumerate(string) if not chr.isspace()) next(idx f...
1
2012-11-28T23:24:30Z
[ "python", "string", "string-matching" ]
Installing a python module on windows
2,379,238
<p>I am trying to install a module called Swish-E 0.5 and for some reason im getting an error when running the command </p> <pre><code>python setup.py install </code></pre> <p>I keep getting this error no matter what module i try to install. I have tried installing other modules to see if the problem lay in that spec...
0
2010-03-04T12:35:15Z
2,379,289
<p>I you haven't already, install <a href="http://swish-e.org/download/index.html" rel="nofollow">Swish-e</a>. If you have, then grab the development files from the source tarball and put them somewhere the compiler can find them.</p>
0
2010-03-04T12:42:51Z
[ "python", "windows" ]
Installing a python module on windows
2,379,238
<p>I am trying to install a module called Swish-E 0.5 and for some reason im getting an error when running the command </p> <pre><code>python setup.py install </code></pre> <p>I keep getting this error no matter what module i try to install. I have tried installing other modules to see if the problem lay in that spec...
0
2010-03-04T12:35:15Z
2,379,293
<p>Search your hard disk for the file <code>swish-e.h</code> and make sure the directory is mentioned in the command line after a <code>-I</code> (= add include path).</p>
0
2010-03-04T12:43:18Z
[ "python", "windows" ]
Installing a python module on windows
2,379,238
<p>I am trying to install a module called Swish-E 0.5 and for some reason im getting an error when running the command </p> <pre><code>python setup.py install </code></pre> <p>I keep getting this error no matter what module i try to install. I have tried installing other modules to see if the problem lay in that spec...
0
2010-03-04T12:35:15Z
2,379,295
<p>You probably need to install/compile Swish-e itself before building Python module for it. Also missing header points to this cause - the Python module uses Swish-e library and headers.</p>
0
2010-03-04T12:43:32Z
[ "python", "windows" ]
pycurl and lot of callback functions
2,379,240
<p>I have big URL list, which I have to download in parallel and check one of headers that is returned with each response.</p> <p>I can use <a href="http://pycurl.sourceforge.net/doc/curlmultiobject.html" rel="nofollow">CurlMulti</a> for parallelization. I can use <code>/dev/null</code> as fb, because I am not interes...
2
2010-03-04T12:35:20Z
2,379,594
<p>I know you're asking about pycurl, but I find it too hard and unpythonic to use. The API is weird.</p> <p>Here's a <a href="http://twistedmatrix.com/" rel="nofollow">twisted</a> example:</p> <pre><code>from twisted.web.client import Agent from twisted.internet import reactor, defer def get_headers(response, url):...
0
2010-03-04T13:34:15Z
[ "python", "libcurl", "pycurl" ]
pycurl and lot of callback functions
2,379,240
<p>I have big URL list, which I have to download in parallel and check one of headers that is returned with each response.</p> <p>I can use <a href="http://pycurl.sourceforge.net/doc/curlmultiobject.html" rel="nofollow">CurlMulti</a> for parallelization. I can use <code>/dev/null</code> as fb, because I am not interes...
2
2010-03-04T12:35:20Z
2,381,066
<p>I would use Python's built in httplib and threading modules. I don't see need for a 3rd party module.</p>
1
2010-03-04T16:51:04Z
[ "python", "libcurl", "pycurl" ]
pycurl and lot of callback functions
2,379,240
<p>I have big URL list, which I have to download in parallel and check one of headers that is returned with each response.</p> <p>I can use <a href="http://pycurl.sourceforge.net/doc/curlmultiobject.html" rel="nofollow">CurlMulti</a> for parallelization. I can use <code>/dev/null</code> as fb, because I am not interes...
2
2010-03-04T12:35:20Z
2,384,879
<p>The solution is to use a little bit of functional programming to 'stick' some additional information to our callback function.</p> <p><a href="http://docs.python.org/library/functools.html#functools.partial" rel="nofollow">functools.partial</a></p>
0
2010-03-05T06:03:34Z
[ "python", "libcurl", "pycurl" ]
Getting pubsubhubbub hub working
2,379,263
<p>I have followed the instructions found at <a href="http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide" rel="nofollow">http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide</a> to setup a hub. When I start the hub I get following warnings</p> <pre><code>$ sudo python2.5 google_...
4
2010-03-04T12:38:23Z
2,379,504
<p>The tutorial at <a href="http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide" rel="nofollow">http://code.google.com/p/pubsubhubbub/wiki/DeveloperGettingStartedGuide</a> is outdated, you need to use <strong>at least google app engine 1.2.8</strong> to make it work (where New memcache offset_multi ...
3
2010-03-04T13:19:29Z
[ "python", "google-app-engine", "pubsubhubbub" ]
Python modules matching a pattern
2,379,285
<p>I'd like to run <code>doctest</code>s for a set of modules (glob: <code>invenio.webtag*</code>) from a single module, but I'll need a way to import all these (and only these) modules and run <code>doctest.testmod()</code> on all of them. Any ideas?</p> <p><strong>Edit</strong>: The solution:</p> <pre><code>import ...
2
2010-03-04T12:41:42Z
2,379,353
<p>A module can be dynamically loaded using <code>__import__</code> e.g.</p> <pre><code>my_module = __import__("mymodule") </code></pre> <p>and then passed to <code>testmod</code> e.g.</p> <pre><code>doctest.testmod(my_module) </code></pre> <p>Assuming you can build a list of the matching modules using either <a hr...
1
2010-03-04T12:52:46Z
[ "python" ]
Python AST processing
2,379,355
<p>I have a Python AST [as returned by ast.parse()].</p> <p>I know this is an AST of a class method.</p> <p>How do I find all calls to other methods of the same class?</p> <p>Basically, I want to collect something like:</p> <pre><code>['foo', 'bar'] </code></pre> <p>for a code snippet like:</p> <pre><code>def baz...
5
2010-03-04T12:52:52Z
2,380,672
<p>The general approach is to subclass <a href="http://docs.python.org/library/ast.html?highlight=ast#ast.NodeVisitor"><code>ast.NodeVisitor</code></a>:</p> <pre><code>&gt;&gt;&gt; class VisitCalls(ast.NodeVisitor): ... def visit_Call(self, what): ... if what.func.value.id == 'self': ... print what.func.at...
14
2010-03-04T15:58:08Z
[ "python", "abstract-syntax-tree" ]
Python's AppKit and ObjectiveC Delegates
2,379,473
<p>AppKit allows Python programs on a Mac to use ObjectiveC classes. I am not very familiar with ObjectiveC, but I want to access the <a href="http://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Classes/NSSound_Class/Reference/Reference.html" rel="nofollow">NSSound</a> class using AppKit...
3
2010-03-04T13:14:30Z
2,381,147
<p>The first step towards successful development of a PyObjC based Cocoa/AppKit application is to learn <a href="http://developer.apple.com/Mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html" rel="nofollow">Objective-C</a> and then learn <a href="http://developer.apple.com/mac/libra...
4
2010-03-04T17:02:00Z
[ "python", "objective-c", "osx", "appkit" ]
Django Admin filter on Foreign Key property
2,379,702
<p>I want to add a filter in an admin changelist by a property of a foreign key, e.g.</p> <pre><code>class Address(model.Models): street = models.CharField(max_length=25) city = models.CharField(max_length=25) country = models.CharField(max_length=25) class Customer(models.Model): name...
13
2010-03-04T13:49:50Z
2,380,120
<p>I have found and tested following solution:</p> <p><a href="http://www.djangosnippets.org/snippets/1911/" rel="nofollow">http://www.djangosnippets.org/snippets/1911/</a></p> <p>It works with ForeignKeys, but it doesn't work with ManyToMany relations. </p>
1
2010-03-04T14:46:08Z
[ "python", "django", "filter", "admin" ]
Django Admin filter on Foreign Key property
2,379,702
<p>I want to add a filter in an admin changelist by a property of a foreign key, e.g.</p> <pre><code>class Address(model.Models): street = models.CharField(max_length=25) city = models.CharField(max_length=25) country = models.CharField(max_length=25) class Customer(models.Model): name...
13
2010-03-04T13:49:50Z
4,168,420
<p>I ran into the same problem and really needed a solution. I have a workaround that lets you create a filter on a FK related model property. You can even traverse more than one FK relationship. It creates a new FilterSpec subclass that subclasses the default RelatedFilterSpec used to give you a filter on a ForeignKey...
0
2010-11-12T19:41:52Z
[ "python", "django", "filter", "admin" ]
Django Admin filter on Foreign Key property
2,379,702
<p>I want to add a filter in an admin changelist by a property of a foreign key, e.g.</p> <pre><code>class Address(model.Models): street = models.CharField(max_length=25) city = models.CharField(max_length=25) country = models.CharField(max_length=25) class Customer(models.Model): name...
13
2010-03-04T13:49:50Z
7,841,996
<p>See <a href="https://code.djangoproject.com/ticket/3400">https://code.djangoproject.com/ticket/3400</a> . It works ok in django 1.3 :)</p> <pre><code>class Room(models.Model): house = models.ForeignKey(House) def __unicode__(self): return self.house.town.name class Booking(models.Model): room ...
11
2011-10-20T20:43:36Z
[ "python", "django", "filter", "admin" ]
Introspection of win32com module / pythoncom module
2,379,809
<p>what is the best way to see what all functions that can be performed using pythoncom module? Specifically, i was working with the win32com module to operate upon excel files. I was not able to find introspection for it as we do for the rest of the modules. Can anyone please suggest how can i retrieve this informatio...
6
2010-03-04T14:06:14Z
2,380,198
<p>The <code>win32com</code> module doesn't provide the functions to manipulate an Excel spreadsheet directly. Rather, it provides you a function to acquire an Excel spreadsheet <em>object</em>. From this object, you can then manipulate a spreadsheet in an object-oriented fashion:</p> <pre><code>import win32com.client...
1
2010-03-04T14:56:02Z
[ "python" ]
Introspection of win32com module / pythoncom module
2,379,809
<p>what is the best way to see what all functions that can be performed using pythoncom module? Specifically, i was working with the win32com module to operate upon excel files. I was not able to find introspection for it as we do for the rest of the modules. Can anyone please suggest how can i retrieve this informatio...
6
2010-03-04T14:06:14Z
2,427,607
<p>run the make.py file in \lib\site-packages\win32com\client.</p> <p>When you run it, a dialog comes up showing installed COM objects... choose the one for the Excel Ojbect library and you'll get something like this:</p> <pre><code>c:\Python26\Lib\site-packages\win32com\client&gt;makepy.py Generating to C:\Python26\...
4
2010-03-11T18:28:43Z
[ "python" ]
Make distutils look for numpy header files in the correct place
2,379,898
<p>In my installation, numpy's <code>arrayobject.h</code> is located at <code>…/site-packages/numpy/core/include/numpy/arrayobject.h</code>. I wrote a trivial Cython script that uses numpy:</p> <pre><code>cimport numpy as np def say_hello_to(name): print("Hello %s!" % name) </code></pre> <p>I also have the fo...
32
2010-03-04T14:17:13Z
2,379,912
<p>Use <code>numpy.get_include()</code>:</p> <pre><code>from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext import numpy as np # &lt;---- New line ext_modules = [Extension("hello", ["hello.pyx"])] setup( name = 'Hello world app...
47
2010-03-04T14:19:16Z
[ "python", "numpy", "distutils", "cython" ]
PyQt QTreeWidget problem with custom delegate
2,379,915
<p>All! I'm trying to write simple property editor. I have automatically generated pyqt class (WorkZone in the code below), and I need to view/edit some of it's properties with PropertyEditor, with the delegate PropertyEditorDelegate, that uses custom editors ColorEditor, LineEditor, etc.</p> <p>Main idea is that Work...
-1
2010-03-04T14:19:40Z
2,385,208
<p>The answer is simple, as always.. %) Default flags for QTreeWidgetItem do not include QtCore.Qt.ItemIsEditable.</p>
0
2010-03-05T07:35:42Z
[ "python", "pyqt", "qtreewidget", "qitemdelegate" ]
PyQt QTreeWidget problem with custom delegate
2,379,915
<p>All! I'm trying to write simple property editor. I have automatically generated pyqt class (WorkZone in the code below), and I need to view/edit some of it's properties with PropertyEditor, with the delegate PropertyEditorDelegate, that uses custom editors ColorEditor, LineEditor, etc.</p> <p>Main idea is that Work...
-1
2010-03-04T14:19:40Z
2,385,646
<p>On PS. </p> <p>From documentation of PyQt</p> <p>QAbstractItemView.setItemDelegate (self, QAbstractItemDelegate)</p> <p>Sets the item delegate for this view and its model to delegate. This is useful if you want complete control over the editing and display of items.</p> <p>Any existing delegate will be removed, ...
1
2010-03-05T09:26:36Z
[ "python", "pyqt", "qtreewidget", "qitemdelegate" ]
PyQt QTreeWidget problem with custom delegate
2,379,915
<p>All! I'm trying to write simple property editor. I have automatically generated pyqt class (WorkZone in the code below), and I need to view/edit some of it's properties with PropertyEditor, with the delegate PropertyEditorDelegate, that uses custom editors ColorEditor, LineEditor, etc.</p> <p>Main idea is that Work...
-1
2010-03-04T14:19:40Z
10,724,842
<p>I ended up handling the double click to set to editable, force the item in to edit mode with editItem() and then set it back. The delegate itself handles all the display and editing.</p> <pre><code># In __init__: self.tree.itemActivated.connect(self.onDoubleClick) def onDoubleClick(self, item, index): """...
2
2012-05-23T17:19:16Z
[ "python", "pyqt", "qtreewidget", "qitemdelegate" ]
Can hotshot be used in multiple threads?
2,379,954
<p>I have a long-running multithreaded program, and I'd like to occasionally like to call a function with <a href="http://docs.python.org/library/hotshot.html#hotshot.Profile.runcall" rel="nofollow">Profile.runcall</a> and dump the data to a file.</p> <p>The <a href="http://docs.python.org/library/hotshot.html" rel="n...
1
2010-03-04T14:23:20Z
2,381,099
<p>For what it's worth, we have a setting in <a href="http://www.cubicweb.org" rel="nofollow">CubicWeb</a> (which uses multiple threads) to enable hotshot profiling, and so far I've never experienced issues when enabling profiling. </p>
1
2010-03-04T16:55:16Z
[ "python", "multithreading", "profiling", "profiler", "profile" ]
Converting date/time in YYYYMMDD/HHMMSS format to Python datetime
2,380,013
<p>I have a date in YYYYMMDD format and a time in HHMMSS format as strings in the 4th and 5th elements in a list. I.E.:</p> <pre><code>data[4] = '20100304' data[5] = '082835' </code></pre> <p>I am creating an instance of datetime (in a field named generates) like this:</p> <pre><code>generatedtime = datetime.dateti...
12
2010-03-04T14:33:25Z
2,380,028
<p>You might take a look at <a href="http://docs.python.org/library/time.html#time.strptime" rel="nofollow">time.strptime</a>.</p> <pre><code>import time time.strptime('20100304 082835', '%Y%m%d %H%M%S') </code></pre> <p>The above assumes a 24-hour clock (<code>%H</code>). Use <code>%I</code> instead if using a 12-h...
4
2010-03-04T14:35:10Z
[ "python", "datetime" ]
Converting date/time in YYYYMMDD/HHMMSS format to Python datetime
2,380,013
<p>I have a date in YYYYMMDD format and a time in HHMMSS format as strings in the 4th and 5th elements in a list. I.E.:</p> <pre><code>data[4] = '20100304' data[5] = '082835' </code></pre> <p>I am creating an instance of datetime (in a field named generates) like this:</p> <pre><code>generatedtime = datetime.dateti...
12
2010-03-04T14:33:25Z
2,380,033
<pre><code>import time, datetime x = time.strptime("30 Nov 00", "%d %b %y") datetime.datetime(x) </code></pre> <p>You can also provide your own format of date string, here is <a href="http://docs.python.org/library/time.html#time.strptime" rel="nofollow">doc</a>.</p>
0
2010-03-04T14:35:27Z
[ "python", "datetime" ]
Converting date/time in YYYYMMDD/HHMMSS format to Python datetime
2,380,013
<p>I have a date in YYYYMMDD format and a time in HHMMSS format as strings in the 4th and 5th elements in a list. I.E.:</p> <pre><code>data[4] = '20100304' data[5] = '082835' </code></pre> <p>I am creating an instance of datetime (in a field named generates) like this:</p> <pre><code>generatedtime = datetime.dateti...
12
2010-03-04T14:33:25Z
2,380,078
<p>No need to import <code>time</code>; <a href="http://docs.python.org/library/datetime.html#datetime.datetime.strptime"><code>datetime.datetime.strptime</code></a> can do it by itself.</p> <pre><code>import datetime dt=datetime.datetime.strptime(data[4]+data[5],'%Y%m%d%H%M%S') print(dt) # 2010-03-04 08:28:35 </code>...
29
2010-03-04T14:41:10Z
[ "python", "datetime" ]
Converting date/time in YYYYMMDD/HHMMSS format to Python datetime
2,380,013
<p>I have a date in YYYYMMDD format and a time in HHMMSS format as strings in the 4th and 5th elements in a list. I.E.:</p> <pre><code>data[4] = '20100304' data[5] = '082835' </code></pre> <p>I am creating an instance of datetime (in a field named generates) like this:</p> <pre><code>generatedtime = datetime.dateti...
12
2010-03-04T14:33:25Z
2,380,118
<p>You could clean up your existing code a bit with a generator (equivalent to a map):</p> <pre><code>generatedtime = datetime.datetime( *(int(x) for x in (data[4][:4], data[4][4:6], data[4][6:], data[5][:2], data[5][2:4],data[5][4:6]) ) ) </code></pre> <p>or even, if you're crazy like a fox, you could make the...
0
2010-03-04T14:46:06Z
[ "python", "datetime" ]
Determine current Mac Safari web page using Python
2,380,031
<p>Is there a way to determine programmatically, using Python, which web page is currently active in Safari?</p>
3
2010-03-04T14:35:26Z
2,380,279
<p>I don't know <em>how</em> to do this, but I would start <a href="http://docs.python.org/library/macosa.html#macpython-osa-modules" rel="nofollow">here</a>.</p>
0
2010-03-04T15:06:57Z
[ "python", "osx", "safari" ]
Determine current Mac Safari web page using Python
2,380,031
<p>Is there a way to determine programmatically, using Python, which web page is currently active in Safari?</p>
3
2010-03-04T14:35:26Z
2,380,295
<p>An Applescript example is <a href="http://daringfireball.net/2003/01/scripting_safari_urls">here</a>, and the relevant part is:</p> <pre><code>tell application "Safari" set url_list to URL of every document end tell </code></pre> <p>Python/AppleScript translation is covered <a href="http://wiki.python.org/moin...
6
2010-03-04T15:09:29Z
[ "python", "osx", "safari" ]
How to identify what function call raise an exception in Python?
2,380,073
<p>i need to identify who raise an exception to handle better str error, is there a way ?</p> <p>look at my example:</p> <pre><code>try: os.mkdir('/valid_created_dir') os.listdir('/invalid_path') except OSError, msg: # here i want i way to identify who raise the exception if is_mkdir_who_raise_an_excepti...
2
2010-03-04T14:40:42Z
2,380,096
<p>Wrap in "try/catch" each function individually.</p> <pre><code>try: os.mkdir('/valid_created_dir') except Exception,e: ## doing something, ## quite probably skipping the next try statement try: os.listdir('/invalid_path') except OSError, msg: ## do something </code></pre> <p>This will help readabi...
8
2010-03-04T14:43:21Z
[ "python", "exception" ]
How to identify what function call raise an exception in Python?
2,380,073
<p>i need to identify who raise an exception to handle better str error, is there a way ?</p> <p>look at my example:</p> <pre><code>try: os.mkdir('/valid_created_dir') os.listdir('/invalid_path') except OSError, msg: # here i want i way to identify who raise the exception if is_mkdir_who_raise_an_excepti...
2
2010-03-04T14:40:42Z
2,380,109
<p>How about the simple solution:</p> <pre><code>try: os.mkdir('/valid_created_dir') except OSError, msg: # it_is_mkdir_whow_raise_ane_xception: do some things try: os.listdir('/invalid_path') except OSError, msg: # it_is_listdir_who_raise_ane_xception: do other things .. </code></pre>
1
2010-03-04T14:44:32Z
[ "python", "exception" ]
How to identify what function call raise an exception in Python?
2,380,073
<p>i need to identify who raise an exception to handle better str error, is there a way ?</p> <p>look at my example:</p> <pre><code>try: os.mkdir('/valid_created_dir') os.listdir('/invalid_path') except OSError, msg: # here i want i way to identify who raise the exception if is_mkdir_who_raise_an_excepti...
2
2010-03-04T14:40:42Z
2,380,177
<p>If you have completely separate tasks to execute depending on which function failed, as your code seems to show, then separate try/exec blocks, as the existing answers suggest, may be better (though you may probably need to skip the second part if the first one has failed).</p> <p>If you have many things that you n...
7
2010-03-04T14:53:29Z
[ "python", "exception" ]
How to identify what function call raise an exception in Python?
2,380,073
<p>i need to identify who raise an exception to handle better str error, is there a way ?</p> <p>look at my example:</p> <pre><code>try: os.mkdir('/valid_created_dir') os.listdir('/invalid_path') except OSError, msg: # here i want i way to identify who raise the exception if is_mkdir_who_raise_an_excepti...
2
2010-03-04T14:40:42Z
2,391,152
<p>Here's the clean approach: attach additional information to the exception where it happens, and then use it in a unified place:</p> <pre><code>import os, sys def func(): try: os.mkdir('/dir') except OSError, e: if e.errno != os.errno.EEXIST: e.action = "creating directory" ...
0
2010-03-06T02:38:36Z
[ "python", "exception" ]
Simple implementation of N-Gram, tf-idf and Cosine similarity in Python
2,380,394
<p>I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. </p> <p>The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity.</...
38
2010-03-04T15:22:30Z
2,380,855
<p>For our Information Retrieval Course, we use some code that is written by our professor in Java. Sorry, no python port. "It is being released for educational and research purposes only under the GNU General Public License." </p> <p>You can check out the documentation <a href="http://userweb.cs.utexas.edu/~mooney/ir...
3
2010-03-04T16:21:39Z
[ "python", "document", "n-gram", "tf-idf", "vsm" ]
Simple implementation of N-Gram, tf-idf and Cosine similarity in Python
2,380,394
<p>I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. </p> <p>The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity.</...
38
2010-03-04T15:22:30Z
2,754,261
<p>Check out NLTK package: <a href="http://www.nltk.org">http://www.nltk.org</a> it has everything what you need</p> <p>For the cosine_similarity:</p> <pre><code> def cosine_distance(u, v): """ Returns the cosine of the angle between vectors v and u. This is equal to u.v / |u||v|. """ return numpy...
42
2010-05-02T17:20:58Z
[ "python", "document", "n-gram", "tf-idf", "vsm" ]
Simple implementation of N-Gram, tf-idf and Cosine similarity in Python
2,380,394
<p>I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. </p> <p>The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity.</...
38
2010-03-04T15:22:30Z
3,362,193
<p>In case you're still interested in this problem, I've done something very similar using <a href="http://lucene.apache.org/java/3_0_2/api/all/index.html" rel="nofollow">Lucene Java</a> and Jython. Here's some snippets from my code.</p> <p>Lucene preprocesses documents and queries using so-called analyzers. This one ...
3
2010-07-29T11:59:08Z
[ "python", "document", "n-gram", "tf-idf", "vsm" ]
Simple implementation of N-Gram, tf-idf and Cosine similarity in Python
2,380,394
<p>I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. </p> <p>The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity.</...
38
2010-03-04T15:22:30Z
7,856,554
<p>If you are interested, I've done tutorial series (<a href="http://blog.christianperone.com/?p=1589">Part I</a> and <a href="http://blog.christianperone.com/?p=1747">Part II</a>) talking about tf-idf and using the <a href="http://scikit-learn.sourceforge.net/stable/">Scikits.learn (sklearn)</a> Python module.</p>
16
2011-10-22T00:11:07Z
[ "python", "document", "n-gram", "tf-idf", "vsm" ]
Simple implementation of N-Gram, tf-idf and Cosine similarity in Python
2,380,394
<p>I need to compare documents stored in a DB and come up with a similarity score between 0 and 1. </p> <p>The method I need to use has to be very simple. Implementing a vanilla version of n-grams (where it possible to define how many grams to use), along with a simple implementation of tf-idf and Cosine similarity.</...
38
2010-03-04T15:22:30Z
22,577,329
<p>Here's an answer with just <code>python</code> + <code>numpy</code>, in short:</p> <p><strong>Cosine</strong>:</p> <pre><code>def cosine_sim(u,v): return np.dot(u,v) / (sqrt(np.dot(u,u)) * sqrt(np.dot(v,v))) </code></pre> <p><strong>Ngrams</strong>:</p> <pre><code>def ngrams(sentence, n): return zip(*[sent...
3
2014-03-22T12:02:40Z
[ "python", "document", "n-gram", "tf-idf", "vsm" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
2,380,932
<p>You could try to write your own <code>testrunner</code> and see, if you can include other files to be checked for doc tests.</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/testing/#defining-a-test-runner" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/testing/#defining-a-test-runner</a></p>...
1
2010-03-04T16:33:15Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
2,381,771
<p>Use nosetests with plugin for django (django-sane-testing or django-nose) and use the <a href="https://nose.readthedocs.org/en/latest/plugins/doctests.html#cmdoption--with-doctest" rel="nofollow">--with-doctest flag</a>.</p>
5
2010-03-04T18:35:20Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
2,386,237
<p>Django's native testing system is based on <code>unittest</code> package. So it is not as powerful as it can be.</p> <p>I recommend you using <a href="http://somethingaboutorange.com/mrl/projects/nose/0.11.2/" rel="nofollow">nose</a> that is backward-compatible <code>unittest</code> on steroids. Use it along with <...
2
2010-03-05T11:11:45Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
3,030,065
<p>You can do this by adding/editing the suite() function in tests.py which defines what tests will be run by the django test runner.</p> <pre><code>import unittest import doctest from project import views def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(views)) return suite </...
20
2010-06-12T20:59:57Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
4,816,284
<p>This is my <code>tests/__init__.py</code> implementation, based on <a href="http://stackoverflow.com/questions/2380527/django-doctests-in-views-py/3030065#3030065">Jesse Shieh answer</a>:</p> <pre><code>import doctest import unittest list_of_doctests = [ 'myapp.views.myview', 'myapp.forms.myform', ] list_o...
7
2011-01-27T12:28:07Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
5,013,963
<p>I posted a github gist that lets you run test in any file or module in your project. <a href="http://dodrum.blogspot.com/2011/01/running-doctests-in-django-project.html" rel="nofollow">Running doctests from specific modules and files</a></p>
2
2011-02-16T08:09:05Z
[ "python", "django", "unit-testing", "doctest" ]
Django doctests in views.py
2,380,527
<p>The Django 1.4 <a href="https://docs.djangoproject.com/en/1.4/topics/testing/#writing-doctests">documentation on tests</a> states:</p> <blockquote> <p>For a given Django application, the test runner looks for doctests in two places:</p> <ul> <li><p>The <code>models.py</code> file. You can define module-lev...
20
2010-03-04T15:39:23Z
20,564,401
<p>Things have <a href="https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner">changed in Django 1.6</a>:</p> <blockquote> <p>Doctests will no longer be automatically discovered. To integrate doctests in your test suite, follow the <a href="http://docs.python.org/2/library/doctest.html#unittest-api">...
11
2013-12-13T10:39:17Z
[ "python", "django", "unit-testing", "doctest" ]
urllib ignore authentication requests
2,380,623
<p>I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to get content of desired URL. But some of these URLs requires authentication. And urlopen prompts me to type in my username and then password. What I need is to ignore every URL that'll require authentication, just easily ski...
0
2010-03-04T15:51:25Z
2,380,789
<p>You are right about the <a href="http://docs.python.org/library/urllib2.html#urllib2.HTTPError" rel="nofollow"><code>urllib2.HTTPError</code></a> exception:</p> <blockquote> <p><code>exception urllib2.HTTPError</code></p> <p>Though being an exception (a subclass of URLError), an HTTPError can also function a...
1
2010-03-04T16:14:05Z
[ "python", "urllib", "urlopen" ]
Redirect Python standard input/output to C# forms application
2,380,649
<p>I apologize if this is a duplicate question, I searched a bit and couldn't find anything similar - I have a Python library that connects to my C# application via a socket in order to allow simple Python scripting (IronPython isn't an option right now for a couple of reasons). I would like to create a Windows Forms c...
4
2010-03-04T15:55:01Z
2,380,685
<p>write in separate thread:</p> <pre><code>while(cond) { string s = _pythonProc.StandardOutput.ReadLine(); textOutput.Invoke( () =&gt; { textOutput.Text += s; } ); } </code></pre>
0
2010-03-04T15:59:41Z
[ "c#", "python", "redirect", "stdout", "stdin" ]
Redirect Python standard input/output to C# forms application
2,380,649
<p>I apologize if this is a duplicate question, I searched a bit and couldn't find anything similar - I have a Python library that connects to my C# application via a socket in order to allow simple Python scripting (IronPython isn't an option right now for a couple of reasons). I would like to create a Windows Forms c...
4
2010-03-04T15:55:01Z
2,381,182
<p>In case anyone else stumbles across this, I figured out the problem - by default, the Python interpreter only enters interactive mode if it detects that a TTY device is connected to standard input (which is normally only true if the program is run from the console). In order to redirect the standard IO streams, you ...
13
2010-03-04T17:06:26Z
[ "c#", "python", "redirect", "stdout", "stdin" ]
Turning on DEBUG on a Django production site
2,380,726
<p>I'm using the Django ORM in a non-Django application and would like to turn on the <a href="http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#debug" rel="nofollow">DEBUG</a> setting so that I can periodically log my queries. So I have something vaguely like this:</p> <pre><code>from django.db import ...
0
2010-03-04T16:05:27Z
2,381,019
<p>In <code>DEBUG</code> mode any error in your application will lead to the detailed Django stacktrace. This is very undesirable in a production environment as it will probably leak sensitive information that attackers can use against your site. Even if your application seems pretty stable, I wouldn't risk it.</p> <p...
2
2010-03-04T16:44:00Z
[ "python", "django", "debugging" ]
set() runtime in python
2,381,026
<p>Just wondering what the run time of lookup for set() is? O(1) or O(n)?</p> <p>if I have </p> <p>x = set() whats the runtime of</p> <p>if "a" in x: print a in set!</p>
5
2010-03-04T16:45:30Z
2,381,054
<p><code>set</code> is implemented using a hash, so the lookup is, on average, close to O(1). The worst case is O(n), where n objects have colliding hashes.</p>
7
2010-03-04T16:48:52Z
[ "python" ]
How does one produce a specific unicode character with Python's C-API?
2,381,132
<p>I'm writing a Python extension that runs through a Py_UNICODE array, finds specific (ASCII, if it matters) characters, i.e. '\' or '\n', and does some additional stuff for each one that it finds.</p> <p>Is there a way to write those characters as literals? If not, what is the correct way to obtain Py_UNICODEs for ...
0
2010-03-04T17:00:13Z
2,381,158
<p>Use <a href="http://docs.python.org/c-api/unicode.html#PyUnicode_FromWideChar" rel="nofollow"><code>PyUnicode_FromWideChar()</code></a> or one of the <a href="http://docs.python.org/c-api/unicode.html#built-in-codecs" rel="nofollow">built-in codec decode functions</a>.</p>
1
2010-03-04T17:03:54Z
[ "python", "unicode", "python-c-api" ]
Python 2.6 - I can not write dwords greater than 0x7fffffff into registry using _winreg.SetValueEx()
2,381,205
<p>using regedit.exe I have manually created a key in registry called <br> HKEY_CURRENT_USER/00_Just_a_Test_Key <br> and created two dword values <br> dword_test_1 and dword_test_2<br> I am trying to write some values into those two keys using following program</p> <pre><code>import _winreg aReg = _winreg.ConnectRegi...
2
2010-03-04T17:09:09Z
2,381,240
<p>Most likely the function expects an <code>int</code> within the limits of a signed C integer, so you'll need to subtract <code>0x100000000</code> before passing to the function.</p> <p>Yes, ideally this would be solved in the bindings. Unfortunately someone let this one slide.</p>
3
2010-03-04T17:13:22Z
[ "python", "registry", "winreg" ]
Python 2.6 - I can not write dwords greater than 0x7fffffff into registry using _winreg.SetValueEx()
2,381,205
<p>using regedit.exe I have manually created a key in registry called <br> HKEY_CURRENT_USER/00_Just_a_Test_Key <br> and created two dword values <br> dword_test_1 and dword_test_2<br> I am trying to write some values into those two keys using following program</p> <pre><code>import _winreg aReg = _winreg.ConnectRegi...
2
2010-03-04T17:09:09Z
2,386,675
<p>I have solved the problem the following way</p> <pre><code>import _winreg def complement(n,radix=32): if n &lt; (1&lt;&lt;(radix-1)) : return n # n is less than 0x80000000 and we do not do anything else : return n - (1&lt;&lt;radix) # n is greater than 0x80000000 and we have to convert it # (1&...
1
2010-03-05T12:33:43Z
[ "python", "registry", "winreg" ]
What is the subprocess.Popen max length of the args parameter?
2,381,241
<p>I am using <a href="http://docs.python.org/library/subprocess.html#using-the-subprocess-module">Popen</a> function from the subprocess module to execute a command line tool:</p> <pre><code>subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shel...
9
2010-03-04T17:13:23Z
2,381,726
<p>If you're passing shell=False, then Cmd.exe does not come into play. </p> <p>On windows, subprocess will use the CreateProcess function from Win32 API to create the new process. The <a href="http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx" rel="nofollow">documentation</a> for this function states t...
6
2010-03-04T18:29:16Z
[ "python", "shell", "subprocess", "popen" ]
Replace a string of characters with some special characters?
2,381,423
<p>when i input some texts/strings, i want them to appear either as hidden or with some special characters(as we do while entering password). . . how can i implement it in a python program? pls help me.</p>
1
2010-03-04T17:35:41Z
2,381,430
<p>Use <a href="http://docs.python.org/library/getpass.html" rel="nofollow">getpass</a></p> <pre><code>import getpass getpass.getpass() </code></pre>
4
2010-03-04T17:37:15Z
[ "python" ]
Replace a string of characters with some special characters?
2,381,423
<p>when i input some texts/strings, i want them to appear either as hidden or with some special characters(as we do while entering password). . . how can i implement it in a python program? pls help me.</p>
1
2010-03-04T17:35:41Z
2,381,431
<p>You want the <a href="http://docs.python.org/library/getpass.html" rel="nofollow"><code>getpass</code></a> module.</p>
0
2010-03-04T17:37:26Z
[ "python" ]
How to write a unittest for importing a module in Python
2,381,535
<p>What is the pythonic way of writing a unittest to see if a module is properly installed? By properly installed I mean, it does not raise an ImportError: No module named foo.</p>
5
2010-03-04T17:55:26Z
2,381,698
<p>I don't see why you'd need to test this, but something like:</p> <pre><code>def my_import_test(self): import my_module </code></pre> <p>If an import error is raised the test has failed, if not it passes.</p>
1
2010-03-04T18:24:46Z
[ "python", "django", "unit-testing" ]
How to write a unittest for importing a module in Python
2,381,535
<p>What is the pythonic way of writing a unittest to see if a module is properly installed? By properly installed I mean, it does not raise an ImportError: No module named foo.</p>
5
2010-03-04T17:55:26Z
2,381,888
<blockquote> <p>As I have to deploy my Django application on a different server and it requires some extra modules I want to make sure that all required modules are installed.</p> </blockquote> <p>This is not a unit test scenario at all.</p> <p>This is a production readiness process and it isn't -- technica...
5
2010-03-04T18:50:53Z
[ "python", "django", "unit-testing" ]
XMPP chat: accessing contacts' status messages with xmppPy's Roster
2,381,597
<p>I'm trying to access my google talk contacts' custom status messages with xmpppy. I'm made it this far:</p> <pre><code>import xmpp import sys userID = 'myname@gmail.com' password = 'mypassword' ressource = 'Script' jid = xmpp.protocol.JID(userID) jabber = xmpp.Client(jid.getDomain(), debug=[]) connection = ...
2
2010-03-04T18:08:09Z
2,404,990
<p>It's a timing issue. Add a handler with:</p> <pre><code>jabber.RegisterHandler('presence', myPresenceHandler) def myPresenceHandler(self, con, event): fromjid = event.getFrom().getStripped() status = myroster.getStatus(fromjid) </code></pre> <p>BEFORE connecting. Then make sure to call <code>jabber.Process(...
2
2010-03-08T21:44:37Z
[ "python", "chat", "xmpp", "google-talk" ]
XMPP chat: accessing contacts' status messages with xmppPy's Roster
2,381,597
<p>I'm trying to access my google talk contacts' custom status messages with xmpppy. I'm made it this far:</p> <pre><code>import xmpp import sys userID = 'myname@gmail.com' password = 'mypassword' ressource = 'Script' jid = xmpp.protocol.JID(userID) jabber = xmpp.Client(jid.getDomain(), debug=[]) connection = ...
2
2010-03-04T18:08:09Z
3,508,698
<p>Here's one thing I've found, which was not clear to me when I first started working with xmpp. Friending is two-way. </p> <p>Using presence stanzas<br> (a) You can "subscribe" to your friend, and your friend can return "subscribed".<br> (b) Your friend can "subscribe" to you, and you can return "subscribed".</p> <...
3
2010-08-18T03:17:44Z
[ "python", "chat", "xmpp", "google-talk" ]
Can someone explain pipe buffer deadlock?
2,381,751
<p>Python documentation to Popen states:</p> <blockquote> <p>Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.</p> </blockquote> <p>Now, I'm trying to figure out how this deadlock can...
7
2010-03-04T18:33:16Z
2,381,791
<p>A deadlock can occur when both buffers (stdin and stdout) are full: your program is waiting to write more input to the external program, and the external program is waiting for you to read from its output buffer first.</p> <p>This can be solved by using non-blocking I/O and properly prioritizing the buffers. You ca...
1
2010-03-04T18:37:45Z
[ "python", "operating-system", "pipe" ]
Can someone explain pipe buffer deadlock?
2,381,751
<p>Python documentation to Popen states:</p> <blockquote> <p>Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.</p> </blockquote> <p>Now, I'm trying to figure out how this deadlock can...
7
2010-03-04T18:33:16Z
2,381,822
<p>Careful, this has a subtle mistake in it.</p> <blockquote> <p>My mental model: subproccess produces something to stdout/err, which is buffered and after buffer is filled, it's flushed to stdout/err of subproccess, which is send through pipe to parent process.</p> </blockquote> <p>The buffer is shared b...
6
2010-03-04T18:40:55Z
[ "python", "operating-system", "pipe" ]
How to get the Python date object for last Wednesday
2,381,786
<p>Using Python I would like to find the date object for last Wednesday. I can figure out where today is on the calendar using isocalendar, and determine whether or not we need to go back a week to get to the previous Wednesday. However, I can't figure out how to create a new date object with that information. Essen...
12
2010-03-04T18:36:55Z
2,381,882
<p>read <a href="http://docs.python.org/library/datetime.html" rel="nofollow">http://docs.python.org/library/datetime.html</a></p> <p>Write your own function using date2 = date1 - timedelta(days=1) and date.isoweekday() iterating over previous days while isoweek is not equal to 3(Wednesday)</p>
-1
2010-03-04T18:49:59Z
[ "python", "datetime", "date" ]
How to get the Python date object for last Wednesday
2,381,786
<p>Using Python I would like to find the date object for last Wednesday. I can figure out where today is on the calendar using isocalendar, and determine whether or not we need to go back a week to get to the previous Wednesday. However, I can't figure out how to create a new date object with that information. Essen...
12
2010-03-04T18:36:55Z
2,381,977
<p>I'm not sure if this meets your requirements, but it should get you <strike>the Wednesday closest to a given date</strike> the Wednesday in the same week as the given date, assuming weeks start on Monday:</p> <pre><code>import datetime def find_closest_wednesday(date): WEDNESDAY = 3 year, week, day = date...
-1
2010-03-04T19:05:43Z
[ "python", "datetime", "date" ]
How to get the Python date object for last Wednesday
2,381,786
<p>Using Python I would like to find the date object for last Wednesday. I can figure out where today is on the calendar using isocalendar, and determine whether or not we need to go back a week to get to the previous Wednesday. However, I can't figure out how to create a new date object with that information. Essen...
12
2010-03-04T18:36:55Z
2,382,238
<p>I think you want this. If the specified day is a Wednesday it will give you that day.</p> <pre><code>from datetime import date from datetime import timedelta today = date.today() offset = (today.weekday() - 2) % 7 last_wednesday = today - timedelta(days=offset) </code></pre> <p>Example, the last wednesday for eve...
33
2010-03-04T19:46:41Z
[ "python", "datetime", "date" ]
How to get the Python date object for last Wednesday
2,381,786
<p>Using Python I would like to find the date object for last Wednesday. I can figure out where today is on the calendar using isocalendar, and determine whether or not we need to go back a week to get to the previous Wednesday. However, I can't figure out how to create a new date object with that information. Essen...
12
2010-03-04T18:36:55Z
2,384,407
<p>Assuming that "last Wednesday" can't be the same as "today", this shows how to do it for any day of the week:</p> <pre><code>&gt;&gt;&gt; from datetime import date &gt;&gt;&gt; from datetime import timedelta &gt;&gt;&gt; &gt;&gt;&gt; MON, TUE, WED, THU, FRI, SAT, SUN = range(7) &gt;&gt;&gt; &gt;&gt;&gt; def lastWda...
5
2010-03-05T03:34:39Z
[ "python", "datetime", "date" ]
Python Lambda with Or
2,382,023
<p>Reading the documentation it seems this might not be possible, but it seems that a lot of people have been able to beat more complicated functionality into pythons lambda function.</p> <p>I'm leveraging the scapy libraries to do some packet creation. Specially this questions is about the ConditionalField which tak...
3
2010-03-04T19:13:36Z
2,382,033
<pre><code>lambda pkt:((pkt.chksumpresent == 1) or (pkt.special == 1)) </code></pre>
8
2010-03-04T19:15:06Z
[ "python", "lambda" ]
Python Lambda with Or
2,382,023
<p>Reading the documentation it seems this might not be possible, but it seems that a lot of people have been able to beat more complicated functionality into pythons lambda function.</p> <p>I'm leveraging the scapy libraries to do some packet creation. Specially this questions is about the ConditionalField which tak...
3
2010-03-04T19:13:36Z
2,382,068
<p>Is lambda the most readable/maintainable? The following is just as performant:</p> <pre><code>def checksum_condition(pkt): return pkt.chksumpresent == 1 or pkt.special == 1 ConditionalField(XShortField("chksum",None), checksum_condition) </code></pre>
6
2010-03-04T19:21:20Z
[ "python", "lambda" ]
Opening links in external browser in Amarok 1.4
2,382,263
<p>I've tried asking this question on the <a href="http://forum.kde.org/viewtopic.php?f=117&amp;t=86095" rel="nofollow">KDE development forum</a>, but haven't received a satisfying answer so far. </p> <p>I've developed a Python <a href="http://www.kde-apps.org/content/show.php/OnStage?content=88557" rel="nofollow">scr...
1
2010-03-04T19:50:22Z
2,383,547
<p>I know nothing about Amarok, but in general you can spawn the platform's default web browser on a URL:</p> <ul> <li><p>on modern open-source desktops (KDE, GNOME, Xfce) by spawning the <code>xdg-open</code> command;</p></li> <li><p>on OS X with the <code>open</code> command;</p></li> <li><p>on Windows with the buil...
0
2010-03-04T23:41:30Z
[ "python" ]
Python problems with FancyURLopener, 401, and "Connection: close"
2,382,338
<p>I'm new to Python, so forgive me if I am missing something obvious.</p> <p>I am using urllib.FancyURLopener to retrieve a web document. It works fine when authentication is disabled on the web server, but fails when authentication is enabled.</p> <p>My guess is that I need to subclass urllib.FancyURLopener to ove...
2
2010-03-04T20:03:47Z
6,713,149
<p>I just tried your code on my webserver (nginx) and it works as expected:</p> <ul> <li>Get from urllib client</li> <li><p>HTTP/1.1 401 Unauthorized from server with Headers</p> <pre><code>Connection: close WWW-Authenticate: Basic realm="Restricted" </code></pre></li> <li><p>client tries again with Authorization hea...
0
2011-07-15T21:08:01Z
[ "python", "urllib", "http-status-code-401" ]
wsdl2py ComplexTypes
2,382,650
<p>How do I add complex types to a SOAP request?</p> <p>I'm using WSDL2py generated requests, and trying to use the other TypeDefinitions that it made in the <em>*</em>_types.py file (like AccountInfo, for authentication, that goes into every request). Then passing it the wsdl2py generated server, and I'm getting this...
2
2010-03-04T20:55:00Z
2,382,889
<p>So... found out that the problem is I needed to run wsdl2py with the --complextypes flag.This creates a whole slew of awesome methods inside of the reqeust object. methods like new_XXXXX where X is the name of the complex type that's required by that request.</p>
2
2010-03-04T21:36:27Z
[ "python", "soap", "wsdl" ]
Creating a palindrome list with reverse()
2,382,905
<p>I want to take a list <code>[0,1,2]</code> and turn it into <code>[0,1,2,2,1,0]</code>. Right now, I've got</p> <pre><code>r = list(mus) r.reverse() mus = mus + r </code></pre> <p>but it seems like there should be a better way. Can anyone come up with a good, pythonic one-liner?</p>
1
2010-03-04T21:39:09Z
2,382,919
<p>It looks like you might be in need of</p> <pre><code>mus.extend(reversed(mus)) </code></pre> <p>Or if you simply need to iterate over this and not necessarily form the list, use</p> <pre><code>import itertools for item in itertools.chain(mus, reversed(mus)): do_something... </code></pre>
3
2010-03-04T21:41:10Z
[ "python" ]
Creating a palindrome list with reverse()
2,382,905
<p>I want to take a list <code>[0,1,2]</code> and turn it into <code>[0,1,2,2,1,0]</code>. Right now, I've got</p> <pre><code>r = list(mus) r.reverse() mus = mus + r </code></pre> <p>but it seems like there should be a better way. Can anyone come up with a good, pythonic one-liner?</p>
1
2010-03-04T21:39:09Z
2,383,032
<p>Just a few of the many ways to do this are:</p> <ol> <li>m = l + reversed(l)</li> <li>m = l + l[::-1]</li> <li>l.extend(reversed(l))</li> <li>l.extend(l[::-1])</li> </ol> <p>The first two assign the output to a new list, and the second two update the list in place. If I was being clever, I would probably use 2 or...
2
2010-03-04T21:58:48Z
[ "python" ]
What is the associativity of Python's ** operator?
2,383,034
<p>I was just playing around with the python command line and the ** operator, which as far as I know performs a power function. So 2 ** 3 should be (and is) 8 because 2 * 2 * 2 = 8.</p> <p>Can someone explain the behavior I found? I don't see any way to group the operations with parentheses to actually get a result...
5
2010-03-04T21:59:18Z
2,383,041
<pre><code>2** (2**(2**2)) </code></pre> <p>from <a href="http://docs.python.org/reference/expressions.html" rel="nofollow">http://docs.python.org/reference/expressions.html</a></p> <p>Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain ...
5
2010-03-04T22:00:34Z
[ "python" ]