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
How to call function that takes an argument in a Django template?
2,468,804
<p>I'm passing to Django's template a function, which returns some records. I want to call this function and iterate over its result. </p> <pre><code>{% for item in my_func(10) %} </code></pre> <p>That doesn't work. I've tried to set the function's return value to a variable and iterate over the variable, but ther...
30
2010-03-18T09:53:37Z
2,519,636
<blockquote> <p>I'm passing to Django's template a function, which returns me some records</p> </blockquote> <p>Why don't you pass to Django template the variable storing function's return value, instead of the function? </p> <p><br /></p> <blockquote> <p>I've tried to set fuction's return value to a variable an...
7
2010-03-25T21:46:03Z
[ "python", "django", "function", "variables", "django-templates" ]
How to call function that takes an argument in a Django template?
2,468,804
<p>I'm passing to Django's template a function, which returns some records. I want to call this function and iterate over its result. </p> <pre><code>{% for item in my_func(10) %} </code></pre> <p>That doesn't work. I've tried to set the function's return value to a variable and iterate over the variable, but ther...
30
2010-03-18T09:53:37Z
17,902,516
<p>By design, Django templates cannot call into arbitrary Python code. This is a security and safety feature for environments where designers write templates, and it also prevents business logic migrating into templates.</p> <p>If you want to do this, you can switch to using Jinja2 templates (<a href="http://jinja.poc...
2
2013-07-27T21:14:06Z
[ "python", "django", "function", "variables", "django-templates" ]
How to call function that takes an argument in a Django template?
2,468,804
<p>I'm passing to Django's template a function, which returns some records. I want to call this function and iterate over its result. </p> <pre><code>{% for item in my_func(10) %} </code></pre> <p>That doesn't work. I've tried to set the function's return value to a variable and iterate over the variable, but ther...
30
2010-03-18T09:53:37Z
21,530,804
<p>if you have an object you can define it as <code>@property</code> so you can get results without a call, e.g.</p> <pre><code>class Item: @property def results(self): return something </code></pre> <p>then in the template:</p> <pre><code>&lt;% for result in item.results %&gt; ... &lt;% endfor %&gt;...
12
2014-02-03T15:11:23Z
[ "python", "django", "function", "variables", "django-templates" ]
How to call function that takes an argument in a Django template?
2,468,804
<p>I'm passing to Django's template a function, which returns some records. I want to call this function and iterate over its result. </p> <pre><code>{% for item in my_func(10) %} </code></pre> <p>That doesn't work. I've tried to set the function's return value to a variable and iterate over the variable, but ther...
30
2010-03-18T09:53:37Z
28,002,284
<p>What you could do is, create the "function" as another template file and then include that file passing the parameters to it.</p> <p>Inside index.html</p> <pre><code>&lt;h3&gt; Latest Songs &lt;/h3&gt; {% include "song_player_list.html" with songs=latest_songs %} </code></pre> <p>Inside song_player_list.html</p> ...
0
2015-01-17T17:39:50Z
[ "python", "django", "function", "variables", "django-templates" ]
Problems with installing jcc and pylucene
2,468,872
<p>I'm trying to install pylucene on Windows XP. I installed JDK on C:\Programme\Java\jdk1.6.0_18 . I also installed Visual Studio C++ Express to have a C++ compiler.</p> <p>As first step I'm trying to integrate jcc into python2.6 through the command: C:\Python26\python.exe setup.py build</p> <p>This gives me the fol...
0
2010-03-18T10:04:26Z
2,472,138
<p>Is there really a space in "jav ac.exe", as shown in the error message? Can setup.py just call javac.exe (is the java binaries directory in the PATH?)</p> <p>Disclaimer: I've built jcc and pylucene on mac os x and linux, but not on windows.</p>
0
2010-03-18T17:43:03Z
[ "java", "python", "pylucene", "jcc" ]
Equivalent of python eval in Haskell
2,469,139
<p>There is function in python called <code>eval</code> that takes string input and evaluates it.</p> <pre><code>&gt;&gt;&gt; x = 1 &gt;&gt;&gt; print eval('x+1') 2 &gt;&gt;&gt; print eval('12 + 32') 44 &gt;&gt;&gt; </code></pre> <p>What is Haskell equivalent of <code>eval</code> function?</p>
8
2010-03-18T10:49:34Z
2,469,165
<p>There is no eval equivalent, Haskell is a statically compiled language, same as C or C++ which does not have eval neither.</p>
1
2010-03-18T10:52:41Z
[ "python", "haskell", "metaprogramming", "eval" ]
Equivalent of python eval in Haskell
2,469,139
<p>There is function in python called <code>eval</code> that takes string input and evaluates it.</p> <pre><code>&gt;&gt;&gt; x = 1 &gt;&gt;&gt; print eval('x+1') 2 &gt;&gt;&gt; print eval('12 + 32') 44 &gt;&gt;&gt; </code></pre> <p>What is Haskell equivalent of <code>eval</code> function?</p>
8
2010-03-18T10:49:34Z
2,469,183
<p>It doesn't have an inbuilt eval function. However are some packages on hackage <a href="http://hackage.haskell.org/package/plugins">that can do the same sort of thing</a>. (<a href="http://www.cse.unsw.edu.au/~dons/hs-plugins/html/System-Eval-Haskell.html">docs</a>). Thanks to <a href="http://stackoverflow.com/users...
11
2010-03-18T10:54:41Z
[ "python", "haskell", "metaprogramming", "eval" ]
Equivalent of python eval in Haskell
2,469,139
<p>There is function in python called <code>eval</code> that takes string input and evaluates it.</p> <pre><code>&gt;&gt;&gt; x = 1 &gt;&gt;&gt; print eval('x+1') 2 &gt;&gt;&gt; print eval('12 + 32') 44 &gt;&gt;&gt; </code></pre> <p>What is Haskell equivalent of <code>eval</code> function?</p>
8
2010-03-18T10:49:34Z
2,470,408
<p>It is true that in Haskell, as in Java or C++ or similar languages, you <em>can</em> call out to the compiler, then dynamically load the code and execute it. However, this is generally heavy weight and almost never why people use <code>eval()</code> in other languages.</p> <p>People tend to use <code>eval()</code> ...
25
2010-03-18T14:09:49Z
[ "python", "haskell", "metaprogramming", "eval" ]
Equivalent of python eval in Haskell
2,469,139
<p>There is function in python called <code>eval</code> that takes string input and evaluates it.</p> <pre><code>&gt;&gt;&gt; x = 1 &gt;&gt;&gt; print eval('x+1') 2 &gt;&gt;&gt; print eval('12 + 32') 44 &gt;&gt;&gt; </code></pre> <p>What is Haskell equivalent of <code>eval</code> function?</p>
8
2010-03-18T10:49:34Z
2,471,983
<p>There is no 'eval' built into the language, though Template Haskell allows compile time evaluation.</p> <p>For runtime 'eval' -- i.e. runtime metaprogramming -- there are a number of packages on Hackage that essentially import GHC or GHCi, including the old hs-plugins package, and the hint package. </p>
10
2010-03-18T17:23:54Z
[ "python", "haskell", "metaprogramming", "eval" ]
Equivalent of python eval in Haskell
2,469,139
<p>There is function in python called <code>eval</code> that takes string input and evaluates it.</p> <pre><code>&gt;&gt;&gt; x = 1 &gt;&gt;&gt; print eval('x+1') 2 &gt;&gt;&gt; print eval('12 + 32') 44 &gt;&gt;&gt; </code></pre> <p>What is Haskell equivalent of <code>eval</code> function?</p>
8
2010-03-18T10:49:34Z
2,478,772
<p><a href="http://www.cse.unsw.edu.au/~dons/hs-plugins/" rel="nofollow">hs-plugins</a> has <a href="http://www.cse.unsw.edu.au/~dons/hs-plugins/html/System-Eval-Haskell.html" rel="nofollow">System.Eval.Haskell</a>.</p>
2
2010-03-19T16:08:47Z
[ "python", "haskell", "metaprogramming", "eval" ]
merge excel cells using pyExcelerator
2,469,167
<p>I want to merge two cells in excel using pyExcelerator , </p> <blockquote> <p>ws.write_merge(r1=0,r2=1,c1=0, c2=0, label='test1', style=style1)<br> #merge cell1(row=0, column=0) with cell2(row=1, column=0) </p> </blockquote> <p>Why the errors happen? AssertionErrors,0 &lt; 0 errors</p>
2
2010-03-18T10:52:54Z
2,469,378
<p>Because the package author put an assertion in Cell.py that would blow up if he ever tried to write a MULBLANKS record with too few columns. Your one-column-wide merged cells block stepped on the mine.</p> <p>Suggestion: Instead of pyExcelerator, use xlwt. xlwt is a fork of pyExcelerator, with many bugs fixed (incl...
3
2010-03-18T11:25:33Z
[ "python", "xlwt", "pyexcelerator" ]
Set the current directory when running a SimpleHTTPServer
2,469,256
<p>Is there any way to set the directory where you want to start a SimpleHTTPServer or BaseHTTPServer?</p>
21
2010-03-18T11:04:22Z
2,469,278
<p>If you're using <code>SimpleHTTPServer</code> directly from command line, you can simply use shell features:</p> <pre><code>pushd /path/you/want/to/serve; python -m SimpleHTTPServer; popd </code></pre>
29
2010-03-18T11:08:21Z
[ "python" ]
s/mime v3 with M2Crypto
2,469,271
<p>I would like to send a mail with a s/mime v3 attachment through SMTP.</p> <p>The excellent HOWTO below describes the procedure in detail for s/mime v2. <a href="http://sandbox.rulemaker.net/ngps/m2/howto.smime.html" rel="nofollow">http://sandbox.rulemaker.net/ngps/m2/howto.smime.html</a></p> <p>I would greatly app...
2
2010-03-18T11:07:05Z
2,505,355
<p>I don't know about v3, but some updated info...</p> <p>The new location for that howto is at <a href="http://svn.osafoundation.org/m2crypto/trunk/doc/howto.smime.html" rel="nofollow">http://svn.osafoundation.org/m2crypto/trunk/doc/howto.smime.html</a>. Note that it is still for v2. There are also some smime tests a...
2
2010-03-24T04:35:01Z
[ "python", "m2crypto", "smime" ]
Talking to printer from Python CGI
2,469,368
<p>I have a Python CGI. I want to print the data in the page. There will be a print button and when the user clicks teh button, I need to do some processing and send the data to the printer. I similarly want to implement 'Export to excel'. Please let me know how to do these</p>
-1
2010-03-18T11:24:12Z
2,469,586
<p>Do you want to print to the user's printer, or the server's? If it's the user's, this is a job for client-side Javascript, not CGI.</p>
1
2010-03-18T12:00:09Z
[ "python", "excel", "printing", "cgi" ]
Calculating a range of an exact number of values in Python
2,469,461
<p>I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). <code>range</code> and <code>arange</code> work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:</p> <pre><code>start_value = -7.5 end_value = 0.1 my_...
3
2010-03-18T11:38:19Z
2,469,536
<p>See <a href="http://code.activestate.com/recipes/66472-frange-a-range-function-with-float-increments/" rel="nofollow">Recipe 66472: frange(), a range function with float increments (Python)</a> with various float implementations, their pros and cons.</p> <p>Alternatively, if precision is important to you, work with...
4
2010-03-18T11:52:36Z
[ "python", "list", "range" ]
Calculating a range of an exact number of values in Python
2,469,461
<p>I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). <code>range</code> and <code>arange</code> work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:</p> <pre><code>start_value = -7.5 end_value = 0.1 my_...
3
2010-03-18T11:38:19Z
2,469,554
<pre><code>def my_function(start, end, length): len = length - 1 incr = (end-start) / len r = [ start ] for i in range(len): r.append ( r[i] + incr ) return r </code></pre>
2
2010-03-18T11:54:55Z
[ "python", "list", "range" ]
Calculating a range of an exact number of values in Python
2,469,461
<p>I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). <code>range</code> and <code>arange</code> work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:</p> <pre><code>start_value = -7.5 end_value = 0.1 my_...
3
2010-03-18T11:38:19Z
2,469,562
<p>How about this:</p> <pre><code>def my_range_function(start, end, length): if length &lt;= 1: return [ start ] step = (end - start) / (length - 1) return [(start + i * step) for i in xrange(length)] </code></pre> <p>For your sample range, it returns:</p> <pre><code>[-7.5, -5.9800000000000004, -4.46, -...
1
2010-03-18T11:56:48Z
[ "python", "list", "range" ]
Calculating a range of an exact number of values in Python
2,469,461
<p>I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). <code>range</code> and <code>arange</code> work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:</p> <pre><code>start_value = -7.5 end_value = 0.1 my_...
3
2010-03-18T11:38:19Z
2,469,698
<p>Use linspace() from <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a>.</p> <pre><code>&gt;&gt;&gt; from numpy import linspace &gt;&gt;&gt; linspace(-7.5, 0.1, 6) array([-7.5 , -5.98, -4.46, -2.94, -1.42, 0.1]) &gt;&gt;&gt; linspace(-7.5, 0.1, 6).tolist() [-7.5, -5.9800000000000004, -4.46, -2.9399999999999...
5
2010-03-18T12:17:15Z
[ "python", "list", "range" ]
Calculating a range of an exact number of values in Python
2,469,461
<p>I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). <code>range</code> and <code>arange</code> work with steps, instead. To put things into pseudo Python, this is what I'd like to achieve:</p> <pre><code>start_value = -7.5 end_value = 0.1 my_...
3
2010-03-18T11:38:19Z
2,469,760
<p>In order to handle the rounding errors, the following code utilizes Python's <a href="http://docs.python.org/library/decimal.html" rel="nofollow">decimal module</a>. You can set the rounding; for this sample I've set it to two decimal points via <code>round_setting = '.01'</code>. In order to handle any rounding err...
1
2010-03-18T12:28:33Z
[ "python", "list", "range" ]
Default value for file path in function gives SyntaxError. Work around?
2,469,538
<p>for this,</p> <pre><code>import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data </code></pre> <p>I get this,</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>Is there a way to make this work or do I have to define a variable ...
2
2010-03-18T11:52:38Z
2,469,556
<p>You have to switch the order of the arguments. Mandatory arguments (without default values) must come before arguments with set default values. </p>
0
2010-03-18T11:55:55Z
[ "python", "function", "default-value" ]
Default value for file path in function gives SyntaxError. Work around?
2,469,538
<p>for this,</p> <pre><code>import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data </code></pre> <p>I get this,</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>Is there a way to make this work or do I have to define a variable ...
2
2010-03-18T11:52:38Z
2,469,557
<p>Move <code>type</code> before <code>data_file_path</code></p> <pre><code>def f(type,data_file_path=os.path.join(os.getcwd(),'temp')): </code></pre> <p>Assigning values in the function parameter called default arguments, those should come afther non-default arguments</p>
1
2010-03-18T11:56:04Z
[ "python", "function", "default-value" ]
Default value for file path in function gives SyntaxError. Work around?
2,469,538
<p>for this,</p> <pre><code>import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data </code></pre> <p>I get this,</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>Is there a way to make this work or do I have to define a variable ...
2
2010-03-18T11:52:38Z
2,469,558
<p>Rearrange the parameters:</p> <pre><code>def f(type, data_file_path=os.path.join(os.getcwd(),'temp')): pass </code></pre> <p>The reason for this is, that arguments with default values can be omitted.<br> But of you call <code>f('foo')</code>, it is not know if you want to set the <code>type</code> and omit <co...
0
2010-03-18T11:56:19Z
[ "python", "function", "default-value" ]
Default value for file path in function gives SyntaxError. Work around?
2,469,538
<p>for this,</p> <pre><code>import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data </code></pre> <p>I get this,</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>Is there a way to make this work or do I have to define a variable ...
2
2010-03-18T11:52:38Z
2,469,559
<p>Arguments with a default value should be placed after all arguments without a default value.</p> <p>Change it to:</p> <pre><code>import os.path def f(type, data_file_path=os.path.join(os.getcwd(),'temp')): ... return data </code></pre>
0
2010-03-18T11:56:25Z
[ "python", "function", "default-value" ]
Default value for file path in function gives SyntaxError. Work around?
2,469,538
<p>for this,</p> <pre><code>import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data </code></pre> <p>I get this,</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>Is there a way to make this work or do I have to define a variable ...
2
2010-03-18T11:52:38Z
2,469,566
<p>Never mind.</p> <pre><code>SyntaxError: non-default argument follows default argument </code></pre> <p>refers to the order of the arguments so,</p> <pre><code>def f(type,data_file_path=os.path.join(os.getcwd(),'temp')): </code></pre> <p>works!</p> <p>me newbie</p>
0
2010-03-18T11:57:14Z
[ "python", "function", "default-value" ]
TFTP server
2,469,632
<p>Are there any modules for python, that can be used as tftp server? I tried Tftpy, but when I try to upload something, it says:</p> <pre><code>ERROR:tftpy:Write requests not implemented at this time. </code></pre> <p>In fact, it's the only function that I need.</p>
0
2010-03-18T12:08:28Z
2,476,064
<p>You may try <strong>tftpgui</strong> from <a href="http://code.google.com/p/tftpgui/" rel="nofollow">http://code.google.com/p/tftpgui/</a> but it's GPL'ed.</p> <p><strong>UPD</strong>: uploading is available starting with <a href="https://github.com/msoulier/tftpy" rel="nofollow"><strong>TFTPy</strong> 0.5.0+</a></...
4
2010-03-19T09:12:43Z
[ "python" ]
Django store regular expression in DB which then gets evaluated on page
2,469,640
<p>I want to store a number of url patterns in my django model which a user can provide parameters to which will create a url.</p> <p>For example I might store these 3 urls in my db where %s is the variable parameter provided by the user:</p> <ul> <li>www.thisissomewebsite.com?param=%s</li> <li>www.anotherurl/%s/</li...
0
2010-03-18T12:09:31Z
2,469,757
<p>You can do this:</p> <pre><code>pattern="www.url?param=%s&amp;param2=%s&amp;param3=%s" params = "[1, 2, 3]" url = pattern % tuple(s.strip('[] ') for s in params.split(',')) </code></pre> <p>or use <code>ast.literal_eval(params)</code> as Ignacio suggests.</p>
0
2010-03-18T12:28:11Z
[ "python", "django", "replace" ]
Django store regular expression in DB which then gets evaluated on page
2,469,640
<p>I want to store a number of url patterns in my django model which a user can provide parameters to which will create a url.</p> <p>For example I might store these 3 urls in my db where %s is the variable parameter provided by the user:</p> <ul> <li>www.thisissomewebsite.com?param=%s</li> <li>www.anotherurl/%s/</li...
0
2010-03-18T12:09:31Z
2,469,762
<pre><code>&gt;&gt;&gt; param = [2, 6, 3] &gt;&gt;&gt; pattern = 'www.url?param=%s&amp;param2=%s&amp;param3=%s' &gt;&gt;&gt; url = pattern % tuple(param) &gt;&gt;&gt; url 'www.url?param=2&amp;param2=6&amp;param3=3' </code></pre> <p>if <strong>param</strong> is a string like <em>'[2,6,3]'</em> you can use ast.literal_e...
1
2010-03-18T12:29:04Z
[ "python", "django", "replace" ]
Django store regular expression in DB which then gets evaluated on page
2,469,640
<p>I want to store a number of url patterns in my django model which a user can provide parameters to which will create a url.</p> <p>For example I might store these 3 urls in my db where %s is the variable parameter provided by the user:</p> <ul> <li>www.thisissomewebsite.com?param=%s</li> <li>www.anotherurl/%s/</li...
0
2010-03-18T12:09:31Z
2,469,775
<p><a href="http://docs.python.org/library/ast.html#ast.literal_eval" rel="nofollow"><code>ast.literal_eval()</code></a> can be used to parse a string into a Python value or structure. If it's a <code>list</code> then just pass it to <code>tuple()</code> before using string interpolation.</p>
3
2010-03-18T12:31:53Z
[ "python", "django", "replace" ]
How do I get javascript results using selenium?
2,469,701
<p>I have the following code:</p> <pre><code>from selenium import selenium selenium = selenium("localhost", 4444, "*chrome", "http://some_site.com/") selenium.start() sel = selenium sel.open("/") sel.type("ctl00_ContentPlaceHolder1_SuburbTownTextBox", "Adelaide,SA,5000") sel.click("ctl00_ContentPlaceHolder1_SearchIm...
3
2010-03-18T12:17:29Z
2,469,832
<p>try this to get the content of a html element with id=your-id :</p> <pre><code>sel.get_eval("this.browserbot.getCurrentWindow().document.getElementById('your-id').innerHTML" </code></pre>
4
2010-03-18T12:40:33Z
[ "javascript", "python", "selenium" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
2,470,989
<p>At least on Windows, this seems to doable via:</p> <ol> <li><p>[Navigate Eclipse menus] <code>"Window"</code>-><code>"Preferences"</code>-><code>"PyDev"</code>-><code>"Interpreter - Python"</code>-> <code>"New"</code> (which is next to <code>"Auto Config"</code> you tried to use, if I get it right)</p></li> <li><p>...
10
2010-03-18T15:24:00Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
4,060,609
<p>Mac OS 10.6.4:</p> <p>Selecting the interpreter as <code>/Library/Frameworks/Python.framework/Versions/2.7/Python</code> did not work.</p> <p>I had to select <code>/Library/Frameworks/Python.framework/Versions/2.7/bin/python</code></p>
12
2010-10-30T20:43:21Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
8,531,898
<p>I've had the same luck!</p> <p>On top of a Mac X Lion I did the following installations: * Enthought 2.7 (these preconfigures Python 2.7 and a lot of other libraries). * Aptana Studio 3.03 (not beta) with PyDev preconfigured. * Finally, and after some troubles I saw that there was some versions of Python installed ...
2
2011-12-16T09:04:44Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
9,306,753
<p>I am running Python 3, so I had to make these changes to get python.exe as my interpreter.</p> <p>File: C:\EasyEclipse-for-LAMP-1.2.2.2\extensions\pydev-1.3.3\eclipse\plugins\org.python.pydev_1.3.3\PySrc\interpreterInfo.py</p> <p>Edit all occurrences of "print ..." to "print(...)" (the ... is whatever is being pri...
1
2012-02-16T06:47:43Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
16,527,123
<p>For latest versions of Canopy under Mac the correct path seems to be:</p> <pre><code>/Users/&lt;yourusername&gt;/Library/Enthought/Canopy_32bit/System/bin/python </code></pre> <p>I tried with ~/.... first but Eclipse didn't seem to like that.</p>
3
2013-05-13T16:45:28Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
19,804,253
<p>If you can get the (Enthought) Canopy distribution working, but are unsure where it's installed to/what PyDev needs, the following worked for me to use that install to identify the right solution, and install it: </p> <p>start ipython (as it was installed with the Canopy distribution).</p> <p>do:</p> <pre><code>...
0
2013-11-06T04:40:16Z
[ "python", "pydev", "enthought" ]
Configuring Pydev Interpreter in Eclipse to use Enthought Python Distribution
2,469,849
<p>I downloaded Pydev plugin for Eclipse (3.5.2) today on Mac OSX 10.5.8. To be able to use Pydev, I need to configure the interpreter in Eclipse. I am not clear what exactly I need to do here, or what this step does. I want to make sure that when I run programs from Eclipse using Pydev, it uses the Enthought Python Di...
16
2010-03-18T12:45:02Z
20,478,259
<p>I found this tutorial very helpful for this problem - <a href="http://www.cs.duke.edu/courses/compsci101/current/resources/install.php" rel="nofollow">http://www.cs.duke.edu/courses/compsci101/current/resources/install.php</a></p> <p>Specifically, step 6:</p> <ol> <li>connect Eclipse to your version of Python (so ...
0
2013-12-09T18:48:10Z
[ "python", "pydev", "enthought" ]
Python objects as userdata in ctypes callback functions
2,469,975
<p>The C function <code>myfunc</code> operates on a larger chunk of data. The results are returned in chunks to a callback function:</p> <pre><code>int myfunc(const char *data, int (*callback)(char *result, void *userdata), void *userdata); </code></pre> <p>Using <strong>ctypes</strong>, it's no big deal to call <cod...
8
2010-03-18T13:06:43Z
2,470,034
<p>I guess you could use the <a href="http://docs.python.org/c-api/" rel="nofollow">Python C API</a> to do that... maybe you could use a PyObject pointer.</p> <p><strong>edit</strong>: As the op pointed out in the comments, there's already a <code>py_object</code> type readily available in ctypes, so the solution is t...
3
2010-03-18T13:16:55Z
[ "python", "callback", "ctypes", "user-data" ]
How to pass SOAP headers into python SUDS that are not defined in WSDL file
2,469,988
<p>I have a camera on my network which I am trying to connect to with suds but suds doesn't send all the information needed. I need to put extra soap headers not defined in the WSDL file so the camera can understand the message. All the headers are contained in a SOAP envelope and then the suds command should be in the...
11
2010-03-18T13:08:28Z
2,546,113
<p>I have worked out how to enter in new headers and namespaces in suds. As stated above you create an Element and pass it in as a soapheader as so:</p> <pre><code>from suds.sax.element import Element client = client(url) ssnns = ('ssn', 'http://namespaces/sessionid') ssn = Element('SessionID', ns=ssnns).setText('1...
19
2010-03-30T14:46:02Z
[ "python", "xml", "wsdl", "suds", "soapheader" ]
How to check if two object are overlapping in a Canvas widget?
2,470,022
<p>Say I have objects within the Canvas with a tags <code>'stopped'</code> and <code>'flying'</code>. </p> <p>How do I check if any of this objects overlap each other?</p>
1
2010-03-18T13:15:27Z
2,470,120
<p>You can use the method <code>find_overlapping</code></p> <blockquote> <p><code>find_overlapping(x1, y1, x2, y2)</code> => <code>tuple</code></p> <pre><code>Returns a tuple of all items that overlap the given rectangle, or that are </code></pre> <p>completely enclosed by it.</p> </blockquote> <p>And then...
2
2010-03-18T13:31:52Z
[ "python", "canvas", "tkinter", "overlap" ]
Bad auto completion with python on pydev?
2,470,121
<p>I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time. I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java.</p> <p>My question is the following...
5
2010-03-18T13:31:52Z
2,470,245
<p>First make sure your <a href="http://pydev.org/manual_101_interpreter.html" rel="nofollow">interpreter</a> is set up correctly.</p> <pre><code>Window | Preferences | Pydev | Interpreter - Python </code></pre> <p>I use cpython on linux so my interpreter is</p> <pre><code> cpython /usr/bin/python25 </code></p...
1
2010-03-18T13:51:41Z
[ "python", "pydev" ]
Bad auto completion with python on pydev?
2,470,121
<p>I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time. I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java.</p> <p>My question is the following...
5
2010-03-18T13:31:52Z
2,478,621
<p>Pycharm (<a href="http://www.jetbrains.com/pycharm/index.html" rel="nofollow">http://www.jetbrains.com/pycharm/index.html</a>) is much better than Pydev for auto completion, among other things.</p>
0
2010-03-19T15:44:41Z
[ "python", "pydev" ]
Bad auto completion with python on pydev?
2,470,121
<p>I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time. I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java.</p> <p>My question is the following...
5
2010-03-18T13:31:52Z
5,761,144
<p>Well, as you didn't say what 'garbage' is showing, it's a bit hard to guess, but I believe you mean the <code>__hash__, __str__,</code> etc from the object class (is that it?)</p> <p>If that's the case, this has been dealt in the current nightly build (the '_' methods will still appear, but with lower priority, so,...
0
2011-04-22T23:55:13Z
[ "python", "pydev" ]
Can a python webapp be bundled into a single file for deployment?
2,470,182
<p>Is it possible for a python webapp to be bundled (gzipped?) into a single file, along with any required resources (js/css files) &amp; modules (including modules like lxml which are mostly C-based), for easy deployment onto a linux webserver?</p>
4
2010-03-18T13:40:37Z
2,470,212
<p>For standalones ,you could try : </p> <p>OS X : <a href="http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html" rel="nofollow">py2app</a></p> <p>For Windows <a href="http://pypi.python.org/pypi/py2exe/" rel="nofollow">py2exe</a>.</p> <p>Not sure if this would apply to your 'webapp' though.</p>
0
2010-03-18T13:48:02Z
[ "python", "deployment" ]
Can a python webapp be bundled into a single file for deployment?
2,470,182
<p>Is it possible for a python webapp to be bundled (gzipped?) into a single file, along with any required resources (js/css files) &amp; modules (including modules like lxml which are mostly C-based), for easy deployment onto a linux webserver?</p>
4
2010-03-18T13:40:37Z
2,470,241
<p>Yes. You can create a windows executable using <code>py2exe</code>. A better way to manage deployment is to package your app with a <code>setup.py</code> file, listing all needed dependencies, and listing non-python support files in the <code>MANIFEST.in</code> file. Then you can package it into a bundle using <c...
1
2010-03-18T13:51:13Z
[ "python", "deployment" ]
Can a python webapp be bundled into a single file for deployment?
2,470,182
<p>Is it possible for a python webapp to be bundled (gzipped?) into a single file, along with any required resources (js/css files) &amp; modules (including modules like lxml which are mostly C-based), for easy deployment onto a linux webserver?</p>
4
2010-03-18T13:40:37Z
2,470,583
<p><a href="http://www.pyinstaller.org/" rel="nofollow">PyInstaller</a> is perhaps the best cross-platform packager (in the SVN trunk version: 1.3, the latest packaged release, is very old and crufty -- no idea why my friends who took over maintenance over a year ago and did so many enhancements keep resisting my entre...
0
2010-03-18T14:32:15Z
[ "python", "deployment" ]
Error -3 while decompressing data: incorrect header check
2,470,389
<p>I have .zip file which contain csv data. I am reading .zip file using </p> <pre><code>&lt;input type = "file" name = "select_file"/&gt; </code></pre> <p>I want to decompress that .zip file and read csv data.</p> <pre><code>file_data = self.request.get('select_file') file_str = zlib.decompress(file_data) #file_...
1
2010-03-18T14:07:13Z
2,470,549
<p>Try making a <a href="http://docs.python.org/library/zipfile.html?highlight=zipfile#zipfile-objects" rel="nofollow">zipfile.ZipFile</a> object instead -- as the first argument, you need an open file-like object, so first make one out of your <code>file_data</code> bytes with <a href="http://docs.python.org/library/s...
1
2010-03-18T14:28:06Z
[ "python" ]
Python: nonblocking read from stdout of threaded subprocess
2,470,742
<p>I have a script (worker.py) that prints unbuffered output in the form...</p> <pre><code>1 2 3 . . . n </code></pre> <p>where n is some constant number of iterations a loop in this script will make. In another script (service_controller.py) I start a number of threads, each of which starts a subprocess using subpr...
0
2010-03-18T14:54:37Z
2,470,821
<p>Instead of having your service_controller being blocked by i/o access, only the thread loop should read its own controlled process output.</p> <p>then, you can have method in the threaded object controlling the process to get the last polled output.</p> <p>of course, don't forget in that case to use some locking ...
2
2010-03-18T15:04:01Z
[ "python", "multithreading", "subprocess", "nonblocking" ]
Python: nonblocking read from stdout of threaded subprocess
2,470,742
<p>I have a script (worker.py) that prints unbuffered output in the form...</p> <pre><code>1 2 3 . . . n </code></pre> <p>where n is some constant number of iterations a loop in this script will make. In another script (service_controller.py) I start a number of threads, each of which starts a subprocess using subpr...
0
2010-03-18T14:54:37Z
7,495,395
<p>Your method WorkerThread.run() launches the subprocess and then terminates immediately. Run() needs to perform the polling and update WorkerThread.completed until the subprocess completes.</p>
1
2011-09-21T06:24:36Z
[ "python", "multithreading", "subprocess", "nonblocking" ]
What does this sentence mean in 'The Zen of Python'?
2,470,761
<p>Please tell me what the following sentence means in '<a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Python</a>'.</p> <blockquote> <p>"Although that way may not be obvious at first unless you’re Dutch."</p> </blockquote> <p>Thanks in advance.</p>
8
2010-03-18T14:56:40Z
2,470,773
<p>It is a reference to the fact that Python's creator, <a href="http://www.python.org/~guido/">Guido van Rossum</a>, is Dutch.</p>
10
2010-03-18T14:58:10Z
[ "python" ]
What does this sentence mean in 'The Zen of Python'?
2,470,761
<p>Please tell me what the following sentence means in '<a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Python</a>'.</p> <blockquote> <p>"Although that way may not be obvious at first unless you’re Dutch."</p> </blockquote> <p>Thanks in advance.</p>
8
2010-03-18T14:56:40Z
2,471,037
<p>When Python was not so popular, and mostly used by scripters and IT people to avoid bash monsters, features and modules and stuff went into the language without pondering over them as much as today.</p> <p>A simple example: the <code>backtick</code> operator was syntactic sugar for repr().</p> <p>The "one obvious ...
11
2010-03-18T15:28:37Z
[ "python" ]
python union of 2 nested lists with index
2,470,764
<p>I want to get the union of 2 nested lists plus an index to the common values.</p> <p>I have two lists like <code>A = [[1,2,3],[4,5,6],[7,8,9]]</code> and <code>B = [[1,2,3,4],[3,3,5,7]]</code> but the length of each list is about 100 000. To A belongs an index vector with <code>len(A)</code>: <code>I = [2,3,4]</cod...
1
2010-03-18T14:57:04Z
2,470,811
<p>Create an auxiliary dict (work is <code>O(len(A)</code>) -- assuming the first three items of a sublist in A uniquely identify it (otherwise you need a dict of lists):</p> <pre><code>aud = dict((tuple(a[:3]), i) for i, a in enumerate(A)) </code></pre> <p>Use said dict to loop once on B (work is <code>O(len(B))</co...
1
2010-03-18T15:02:29Z
[ "python", "dataset", "list", "nested", "union" ]
convert string of millisecond into datetime in python
2,470,784
<p>I am a newbie in Python. I want to subtract interval time from my log file, but the problem is I cannot convert millisecond string of log file into datetime format. For example, I have 15:55:05.12345 and I want to remove 5.12345 seconds from this string, and show result of 15.55.00.00000 in Python. How can I do that...
0
2010-03-18T14:59:23Z
2,470,831
<pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; s = '15:55:05.12345' &gt;&gt;&gt; datetime.datetime.strptime(s.rpartition('.')[0], '%H:%M:%S').strftime('%H.%M.00.00000') '15.55.00.00000' </code></pre> <p><strong>edit after clarification</strong>:<br> there is no way to do this with Python standard library, only w...
1
2010-03-18T15:05:02Z
[ "python", "datetime", "python-2.5" ]
convert string of millisecond into datetime in python
2,470,784
<p>I am a newbie in Python. I want to subtract interval time from my log file, but the problem is I cannot convert millisecond string of log file into datetime format. For example, I have 15:55:05.12345 and I want to remove 5.12345 seconds from this string, and show result of 15.55.00.00000 in Python. How can I do that...
0
2010-03-18T14:59:23Z
2,472,163
<p>I see that you need to subtract from the value, so I would use timedelta objects because you can do math with those.</p> <pre><code>&gt;&gt;&gt; value = '15:55:05.123450' &gt;&gt;&gt; m = re.match('(\d+):(\d+):(\d+\.\d+)', value) &gt;&gt;&gt; hour = int(m.group(1)) &gt;&gt;&gt; min = int(m.group(2)) &gt;&gt;&gt; se...
0
2010-03-18T17:46:13Z
[ "python", "datetime", "python-2.5" ]
cpython: when PyDict_GetItem is called and when dict_subscript?
2,470,928
<p>I am reading cpython code for python 3k and I have noticed, that <code>__missing__</code> is called only when <code>dict_subscript</code> is called, but not when <code>PyDict_GetItem</code> is used. What is the difference between those two methods and when each is called? If I pass an PyObject that is a subclass of ...
1
2010-03-18T15:17:03Z
2,473,724
<p>Observations, guesses, etc:</p> <p>Same happens in Python 2.x.</p> <p><code>dict_subscript</code> implements the equivalent of the high_level <code>dict.__getitem__</code> method and thus will be called whenever <code>adict[somekey]</code> appears other than on the LHS of an assignment in Python code.</p> <p><cod...
1
2010-03-18T22:16:18Z
[ "python", "dictionary", "cpython" ]
Fast way to test if a port is in use using Python
2,470,971
<p>I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Sinc...
3
2010-03-18T15:21:29Z
2,471,039
<p>How about just trying to bind to the port you want, and handle the error case if the port is occupied? (If the issue is that you might start the same service twice then don't look at open ports.)</p>
5
2010-03-18T15:28:39Z
[ "python", "sockets" ]
Fast way to test if a port is in use using Python
2,470,971
<p>I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Sinc...
3
2010-03-18T15:21:29Z
2,471,078
<p>Are you on Linux? If so, perhaps your application could run <code>netstat -lant</code> (or <code>netstat -lanu</code> if you're using UDP) and see what ports are in use. This should be faster...</p>
1
2010-03-18T15:32:16Z
[ "python", "sockets" ]
Fast way to test if a port is in use using Python
2,470,971
<p>I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Sinc...
3
2010-03-18T15:21:29Z
2,471,762
<p>Simon B's answer is the way to go - don't check anything, just try to bind and handle the error case if it's already in use.</p> <p>Otherwise you're in a race condition where some other app can grab the port <strong>in between</strong> your check that it's free and your subsequent attempt to bind to it. That means ...
0
2010-03-18T16:51:19Z
[ "python", "sockets" ]
Fast way to test if a port is in use using Python
2,470,971
<p>I have a python server that listens on a couple sockets. At startup, I try to connect to these sockets before listening, so I can be sure that nothing else is already using that port. This adds about three seconds to my server's startup (which is about .54 seconds without the test) and I'd like to trim it down. Sinc...
3
2010-03-18T15:21:29Z
35,387,673
<p>Here is an example of how to check if the port is taken.</p> <pre><code>import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind(("127.0.0.1", 5555)) except socket.error as e: if e.errno == 98: print("Port is already in use") else: # something else raised the soc...
0
2016-02-14T02:20:42Z
[ "python", "sockets" ]
Is there a functional way to do this?
2,471,413
<pre><code>def flattenList(toFlatten): final=[] for el in toFlatten: if isinstance(el, list): final.extend(flattenList(el)) else: final.append(el) return final </code></pre> <p>When I don't know how deeply the lists will nest, this is the only way I can think to do this.</p>
5
2010-03-18T16:09:47Z
2,471,793
<ol> <li><p>You should avoid typechecking in Python. In this case, this means avoiding arbitrarily-nested structures where you distinguish by type. You can build your own node type which you can traverse by methods <em>other</em> than typechecking, like looking at a specific attribute.</p></li> <li><p>For flattening on...
7
2010-03-18T16:55:49Z
[ "python", "sequences" ]
Is there a functional way to do this?
2,471,413
<pre><code>def flattenList(toFlatten): final=[] for el in toFlatten: if isinstance(el, list): final.extend(flattenList(el)) else: final.append(el) return final </code></pre> <p>When I don't know how deeply the lists will nest, this is the only way I can think to do this.</p>
5
2010-03-18T16:09:47Z
2,471,855
<p>Here's another option (though there may be something cleaner than type-checking, like testing if something is iterable and hence not an "atom"):</p> <pre><code>def flatten(lst): if not isinstance(lst,list): return [lst] else: return reduce(lambda x,y:x+y,[flatten(x) for x in lst],[]) </code>...
2
2010-03-18T17:07:20Z
[ "python", "sequences" ]
Is there a functional way to do this?
2,471,413
<pre><code>def flattenList(toFlatten): final=[] for el in toFlatten: if isinstance(el, list): final.extend(flattenList(el)) else: final.append(el) return final </code></pre> <p>When I don't know how deeply the lists will nest, this is the only way I can think to do this.</p>
5
2010-03-18T16:09:47Z
2,471,887
<p>Under the doc for <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools</a>, there's a <code>flatten()</code> function</p>
2
2010-03-18T17:11:14Z
[ "python", "sequences" ]
Is there a functional way to do this?
2,471,413
<pre><code>def flattenList(toFlatten): final=[] for el in toFlatten: if isinstance(el, list): final.extend(flattenList(el)) else: final.append(el) return final </code></pre> <p>When I don't know how deeply the lists will nest, this is the only way I can think to do this.</p>
5
2010-03-18T16:09:47Z
2,472,209
<p>This answer explains why you do not want to use <code>reduce</code> for this in Python. </p> <p>Consider the snippet </p> <pre><code>reduce(operator.add, [[1], [2], [3], [4], [5]]) </code></pre> <p>What does this have to do?</p> <pre><code>[1] + [2] =&gt; [1, 2] [1, 2] + [3] =&gt; This makes a new list, having t...
3
2010-03-18T17:54:36Z
[ "python", "sequences" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
2,487,862
<p>The "proper" way to do that would be to write a <a href="http://docutils.sourceforge.net/docs/dev/hacking.html#parsing-the-document">docutils parser</a> for markdown. (Plus a Sphinx option to choose the parser.) The beauty of this would be instant support for all docutils output formats (but you might not care abo...
79
2010-03-21T16:53:55Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
16,430,414
<p>There is a workaround.<br> The sphinx-quickstart.py script generates a Makefile.<br> You can easily invoke Pandoc from the Makefile every time you'd like to generate the documentation in order to convert Markdown to reStructuredText.</p>
1
2013-05-07T23:45:30Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
17,228,308
<p>Markdown and ReST do different things.</p> <p>RST provides an object model for working with documents.</p> <p>Markdown provides a way to engrave bits of text.</p> <p>It seems reasonable to want to reference your bits of Markdown content from your sphinx project, using RST to stub out the overall information archi...
20
2013-06-21T05:31:54Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
22,919,306
<p>This doesn't use Sphinx, but <a href="http://www.mkdocs.org">MkDocs</a> will build your documentation using Markdown. I also hate rst, and have really enjoyed MkDocs so far.</p>
21
2014-04-07T17:36:12Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
30,197,203
<p>I went with Beni's suggestion of using pandoc for this task. Once installed the following script will convert all markdown files in the source directory to rst files, so that you can just write all your documentation in markdown. Hope this is useful for others.</p> <pre><code>#!/usr/bin/env python import os impor...
7
2015-05-12T17:00:29Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
33,797,841
<p>You can use Markdown and reStructuredText in the same Sphinx project. How to do this is succinctly documented on <a href="http://docs.readthedocs.org/en/latest/getting_started.html#in-markdown" rel="nofollow">Read The Docs</a>. Install recommonmark (<code>pip install recommonmark</code>) and then edit <code>conf.py<...
31
2015-11-19T07:40:50Z
[ "python", "markdown", "python-sphinx" ]
Using sphinx with Markdown instead of RST
2,471,804
<p>I hate RST but love sphinx. Is there a way that sphinx reads markdown instead of reStructuredText?</p>
147
2010-03-18T16:57:05Z
36,103,903
<p>It looks like a basic implementation has made it's way into Sphinx but word has not gotten round yet. <a href="https://github.com/sphinx-doc/sphinx/issues/825#issuecomment-180197293">See github issue comment</a></p> <p>install dependencies:</p> <pre><code>pip install commonmark recommonmark </code></pre> <p>adjus...
12
2016-03-19T16:02:59Z
[ "python", "markdown", "python-sphinx" ]
Producing a color map image using Python
2,471,899
<p>I have a working program in C++ that generates data for a Mandelbrot Set. I am able to get the color map image of the Mandelbrot set using gnuplot. In order to save the image, I just take a screenshot which doesn't give a very accurate image.</p> <p>how I can use a Python script in order to produce and save the ima...
0
2010-03-18T17:12:45Z
2,471,963
<p>The <a href="http://www.pythonware.com/products/pil/" rel="nofollow">Python Imaging Library</a> is the standard means to produce 2D images and image files in Python.</p>
0
2010-03-18T17:20:30Z
[ "python", "c", "image" ]
Producing a color map image using Python
2,471,899
<p>I have a working program in C++ that generates data for a Mandelbrot Set. I am able to get the color map image of the Mandelbrot set using gnuplot. In order to save the image, I just take a screenshot which doesn't give a very accurate image.</p> <p>how I can use a Python script in order to produce and save the ima...
0
2010-03-18T17:12:45Z
2,472,198
<p>Source code <a href="http://www.daniweb.com/code/snippet216851.html#" rel="nofollow"><strong>Draw a Mandelbrot Set (Python)</strong></a></p> <p>PIL and NumPy ofcourse ;)</p>
0
2010-03-18T17:53:19Z
[ "python", "c", "image" ]
In Python what's the best way to emulate Perl's __END__?
2,471,942
<p>Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's <code>__END__</code>?</p> <pre><code>print "Perl...\n"; __END__ End of code. I can put anything I want here. </code></pre> <p>One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve th...
19
2010-03-18T17:18:46Z
2,471,975
<p>What you're asking for does not exist. Proof: <a href="http://www.mail-archive.com/python-list@python.org/msg156396.html" rel="nofollow">http://www.mail-archive.com/python-list@python.org/msg156396.html</a></p> <p>A simple solution is to escape any " as \" and do a normal multi line string -- see official docs: <a ...
3
2010-03-18T17:21:59Z
[ "python", "perl" ]
In Python what's the best way to emulate Perl's __END__?
2,471,942
<p>Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's <code>__END__</code>?</p> <pre><code>print "Perl...\n"; __END__ End of code. I can put anything I want here. </code></pre> <p>One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve th...
19
2010-03-18T17:18:46Z
2,471,985
<p>The triple-quote form you suggested will still create a python string, whereas Perl's parser simply ignores anything after <code>__END__</code>. You can't write:</p> <pre><code>""" I can put anything in here... Anything! """ import os os.system("rm -rf /") </code></pre> <p>Comments are more suitable in my opinion....
5
2010-03-18T17:24:13Z
[ "python", "perl" ]
In Python what's the best way to emulate Perl's __END__?
2,471,942
<p>Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's <code>__END__</code>?</p> <pre><code>print "Perl...\n"; __END__ End of code. I can put anything I want here. </code></pre> <p>One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve th...
19
2010-03-18T17:18:46Z
2,472,152
<p>Python does not have a direct equivalent to this.</p> <p>Why do you want it? It doesn't sound like a really great thing to have when there are more consistent ways like putting the text at the end as comments (that's how we include arbitrary text in Python source files. Triple quoted strings are for making multi-li...
0
2010-03-18T17:45:11Z
[ "python", "perl" ]
In Python what's the best way to emulate Perl's __END__?
2,471,942
<p>Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's <code>__END__</code>?</p> <pre><code>print "Perl...\n"; __END__ End of code. I can put anything I want here. </code></pre> <p>One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve th...
19
2010-03-18T17:18:46Z
5,079,712
<p>The <pre><code>&#95;&#95;END&#95;&#95;</code></pre> block in perl dates from a time when programmers had to work with data from the outside world and liked to keep examples of it in the program itself.</p> <p><p>Hard to imagine I know.</p> <p><p>It was useful for example if you had a moving target like a hardware ...
11
2011-02-22T14:55:43Z
[ "python", "perl" ]
In Python what's the best way to emulate Perl's __END__?
2,471,942
<p>Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's <code>__END__</code>?</p> <pre><code>print "Perl...\n"; __END__ End of code. I can put anything I want here. </code></pre> <p>One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve th...
19
2010-03-18T17:18:46Z
12,411,402
<p>Hm, what about <code>sys.exit(0)</code> ? (assuming you do <code>import sys</code> above it, of course)</p> <p>As to why it would useful, sometimes I sit down to do a substantial rewrite of something and want to mark my "good up to this point" place.</p> <p>By using <code>sys.exit(0)</code> in a temporary manner, ...
1
2012-09-13T17:09:21Z
[ "python", "perl" ]
How can I use python itertools.groupby() to group a list of strings by their first character?
2,472,001
<p>I have a list of strings similar to this list:</p> <pre><code>tags = ('apples', 'apricots', 'oranges', 'pears', 'peaches') </code></pre> <p>How should I go about grouping this list by the first character in each string using itertools.groupby()? How should I supply the 'key' argument required by itertools.groupby(...
4
2010-03-18T17:25:27Z
2,472,009
<pre><code>groupby(tags, key=operator.itemgetter(0)) </code></pre>
10
2010-03-18T17:26:41Z
[ "python", "string", "itertools" ]
How can I use python itertools.groupby() to group a list of strings by their first character?
2,472,001
<p>I have a list of strings similar to this list:</p> <pre><code>tags = ('apples', 'apricots', 'oranges', 'pears', 'peaches') </code></pre> <p>How should I go about grouping this list by the first character in each string using itertools.groupby()? How should I supply the 'key' argument required by itertools.groupby(...
4
2010-03-18T17:25:27Z
2,472,012
<pre><code>&gt;&gt;&gt; for i, j in itertools.groupby(tags, key=lambda x: x[0]): print(i, list(j)) a ['apples', 'apricots'] o ['oranges'] p ['pears', 'peaches'] </code></pre>
4
2010-03-18T17:26:54Z
[ "python", "string", "itertools" ]
How can I use python itertools.groupby() to group a list of strings by their first character?
2,472,001
<p>I have a list of strings similar to this list:</p> <pre><code>tags = ('apples', 'apricots', 'oranges', 'pears', 'peaches') </code></pre> <p>How should I go about grouping this list by the first character in each string using itertools.groupby()? How should I supply the 'key' argument required by itertools.groupby(...
4
2010-03-18T17:25:27Z
2,472,048
<p>just another way, </p> <pre><code>&gt;&gt;&gt; from collections import defaultdict &gt;&gt;&gt; t=defaultdict(list) &gt;&gt;&gt; for items in tags: ... t[items[0]].append(items) ... &gt;&gt;&gt; t defaultdict(&lt;type 'list'&gt;, {'a': ['apples', 'apricots'], 'p': ['pears', 'peaches'], 'o': ['oranges']}) </code...
0
2010-03-18T17:31:07Z
[ "python", "string", "itertools" ]
How can I use python itertools.groupby() to group a list of strings by their first character?
2,472,001
<p>I have a list of strings similar to this list:</p> <pre><code>tags = ('apples', 'apricots', 'oranges', 'pears', 'peaches') </code></pre> <p>How should I go about grouping this list by the first character in each string using itertools.groupby()? How should I supply the 'key' argument required by itertools.groupby(...
4
2010-03-18T17:25:27Z
2,472,176
<p>You might want to create <code>dict</code> afterwards:</p> <pre><code>from itertools import groupby d = {k: list(v) for k, v in groupby(tags, key=lambda x: x[0])} </code></pre>
7
2010-03-18T17:48:43Z
[ "python", "string", "itertools" ]
How to check if a file is a textfile?
2,472,221
<p>I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.<br> Can i check somehow what kind of file is it so i only open and search through txt, php, etc files. I can't rely on the file extension.</p>
4
2010-03-18T17:56:19Z
2,472,231
<p>Check the mime type and file extension. </p> <p>Or if this is a one time thing you can use file searching commands in linux.</p>
0
2010-03-18T17:57:58Z
[ "python" ]
How to check if a file is a textfile?
2,472,221
<p>I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.<br> Can i check somehow what kind of file is it so i only open and search through txt, php, etc files. I can't rely on the file extension.</p>
4
2010-03-18T17:56:19Z
2,472,233
<p>If you're on linux you can parse the output of the <code>file</code> command-line tool.</p>
1
2010-03-18T17:58:17Z
[ "python" ]
How to check if a file is a textfile?
2,472,221
<p>I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.<br> Can i check somehow what kind of file is it so i only open and search through txt, php, etc files. I can't rely on the file extension.</p>
4
2010-03-18T17:56:19Z
2,472,234
<p>You can use the <a href="http://pypi.python.org/pypi/python-magic/" rel="nofollow">Python interface</a> to <a href="http://linux.die.net/man/3/libmagic" rel="nofollow">libmagic</a> to identify file formats.</p>
2
2010-03-18T17:58:47Z
[ "python" ]
How to check if a file is a textfile?
2,472,221
<p>I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.<br> Can i check somehow what kind of file is it so i only open and search through txt, php, etc files. I can't rely on the file extension.</p>
4
2010-03-18T17:56:19Z
2,472,243
<p>Use Python's <code>mimetypes</code> library:</p> <pre><code>import mimetypes if mimetypes.guess_type('full path to document here')[0] == 'text/plain': # file is plaintext </code></pre>
5
2010-03-18T18:01:02Z
[ "python" ]
Changing Element Value in Existing XML File Using DOM
2,472,279
<p>I am trying to find examples of how to change an existing xml files Element Value.</p> <p>Using the following xml example:</p> <pre><code>&lt;book&gt; &lt;title&gt;My Book&lt;/title&gt; &lt;author&gt;John Smith&lt;/author&gt; &lt;/book&gt; </code></pre> <p>If I wanted to replace the author element value 'John...
3
2010-03-18T18:07:44Z
2,472,603
<p>Presuming</p> <pre><code>s = ''' &lt;book&gt; &lt;title&gt;My Book&lt;/title&gt; &lt;author&gt;John Smith&lt;/author&gt; &lt;/book&gt;''' </code></pre> <p>DOM would look like:</p> <pre><code>from xml.dom import minidom dom = minidom.parseString(s) # or parse(filename_or_file) for author in dom.getElementsByT...
5
2010-03-18T19:01:29Z
[ "python", "xml" ]
In Sphinx, can I register a bunch of keywords that should always be translated into links?
2,472,364
<p>My doc strings have references to other python classes that I've defined. Every time Sphinx encounters one of these classes, I want it to insert a link to the documentation for that other class. Is this possible in Sphinx?</p> <p>Specifically, I have a doc string like:</p> <pre><code>'''This class contains a bun...
5
2010-03-18T18:20:29Z
2,472,464
<p>Sphinx has a huge number of interpreted text roles for this.</p> <p><a href="http://sphinx.pocoo.org/markup/inline.html#cross-referencing-python-objects" rel="nofollow">http://sphinx.pocoo.org/markup/inline.html#cross-referencing-python-objects</a></p> <blockquote> <p>I want to enter Foo and have Sphinx interpre...
2
2010-03-18T18:42:07Z
[ "python", "python-sphinx" ]
In Sphinx, can I register a bunch of keywords that should always be translated into links?
2,472,364
<p>My doc strings have references to other python classes that I've defined. Every time Sphinx encounters one of these classes, I want it to insert a link to the documentation for that other class. Is this possible in Sphinx?</p> <p>Specifically, I have a doc string like:</p> <pre><code>'''This class contains a bun...
5
2010-03-18T18:20:29Z
2,472,605
<p>You can use macros.</p> <p>In my project, I have a header file that contains all "important" classes and global functions and their abbreviation. Two example lines:</p> <pre><code>.. |PostItem| replace:: :class:`PostItem &lt;hklib.PostItem&gt;` .. |PostNotFoundError| replace:: :class:`PostNotFoundError &lt;hklib.P...
7
2010-03-18T19:01:41Z
[ "python", "python-sphinx" ]
Simple debugger, want work?
2,472,409
<p>i'm reading the Gray Hat Python,, i reach for this ::</p> <pre><code>class debugger(): def __init__(self): self.h_process = None self.pid = None self.debugger_active = False def load(self,path_to_exe): creation_flags = DEBUG_PROCESS startupinfo = STARTUPINFO() ...
0
2010-03-18T18:32:16Z
2,472,547
<p>I suppose at a certain point, you changed name from attach to open_process (as it seems from the output of the traceback).<br> In this case, the error is here:</p> <pre><code>def open_process(self,pid): h_process = self.open_process(pid) </code></pre> <p>As you can see, it is recursively calling itself.<br> ...
1
2010-03-18T18:54:48Z
[ "python", "debugging" ]
subprocess isn't outputting anything
2,472,488
<p>I'm trying to use Python to run pdftotext, but for some reason, my code isn't working. If I run the below, I expect that the content variable would contain the contents of the PDF, but the result I am getting is just an empty string.</p> <p>Does anybody know what I'm missing? </p> <pre><code>def getPDFContent(path...
1
2010-03-18T18:46:42Z
2,472,531
<p>By default <code>pdftotext</code> doesn't output anything on stdout, it instead creates a <code>.txt</code> file with the same base name as the pdf. To get the text on stdout, add <code>-</code> as a second parameter in the call to <code>pdftotext</code>:</p> <pre><code>process = subprocess.Popen(["pdftotext", path...
2
2010-03-18T18:52:31Z
[ "python", "subprocess", "pdftotext" ]
Python way to clone a git repository
2,472,552
<p>Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend. </p>
19
2010-03-18T18:55:14Z
2,472,616
<p>There is <a href="http://gitorious.org/git-python/">http://gitorious.org/git-python/</a> . Haven’t heard of it before and internally, it relies on having the git executables somewhere; additionally, they might have plenty of bugs. But it could be worth a try.</p> <p>How to clone:</p> <pre><code>import git git.Gi...
9
2010-03-18T19:04:57Z
[ "python", "git", "module" ]
Python way to clone a git repository
2,472,552
<p>Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend. </p>
19
2010-03-18T18:55:14Z
2,531,833
<p><a href="http://samba.org/~jelmer/dulwich/" rel="nofollow">Dulwich</a> is a pure-Python implementation of Git that does not fork at all. Be aware that it's still under development, so it may be buggy.</p>
0
2010-03-28T03:50:05Z
[ "python", "git", "module" ]
Python way to clone a git repository
2,472,552
<p>Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend. </p>
19
2010-03-18T18:55:14Z
7,086,686
<p>With Dulwich tip you should be able to do:</p> <pre><code>from dulwich.repo import Repo Repo("/path/to/source").clone("/path/to/target") </code></pre> <p>This is still very basic - it copies across the objects and the refs, but it doesn't yet create the contents of the working tree if you create a non-bare reposit...
1
2011-08-17T00:22:25Z
[ "python", "git", "module" ]
Python way to clone a git repository
2,472,552
<p>Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend. </p>
19
2010-03-18T18:55:14Z
15,388,550
<p>Using <a href="https://github.com/gitpython-developers/GitPython">GitPython</a> will give you a good python interface to Git.</p> <p>For example, after installing it (<code>pip install gitpython</code>), for cloning a new repository you can use <a href="http://gitpython.readthedocs.org/en/stable/reference.html?high...
33
2013-03-13T14:47:51Z
[ "python", "git", "module" ]
Python way to clone a git repository
2,472,552
<p>Is there a Python way without using a subprocess to clone a git repository? I'm up for using any sort of modules you recommend. </p>
19
2010-03-18T18:55:14Z
34,424,094
<p>Github's <a href="https://libgit2.github.com/" rel="nofollow">libgit2</a> binding, <a href="http://www.pygit2.org/repository.html" rel="nofollow">pygit2</a> provides a one-liner cloning a remote directory: </p> <pre><code>clone_repository(url, path, bare=False, repository=None, remote=None, checkout_branch=Non...
0
2015-12-22T20:40:30Z
[ "python", "git", "module" ]
"Bootstrap" python script in the Windows shell without .py / .pyw associations
2,472,558
<p>Sometimes (in customer's PCs) I need a python script to execute in the Windows shell like a .CMD or .BAT, but without having the .py or .pyw extensions associated with PYTHON / PYTHONW.</p> <p>I came out with a pair of 'quick'n dirty' solutions:</p> <p>1)</p> <pre><code>""" e:\devtool\python\python.exe %0 :: or %...
7
2010-03-18T18:56:00Z
2,472,637
<p>I use the following <a href="http://docs.python.org/distutils/" rel="nofollow">distutils</a>/<a href="http://www.py2exe.org/" rel="nofollow">py2exe</a> script to produce a single runnable executable file:</p> <pre><code>from distutils.core import setup import py2exe, sys, os sys.argv.append('py2exe') setup( o...
0
2010-03-18T19:08:13Z
[ "python", "shell" ]
"Bootstrap" python script in the Windows shell without .py / .pyw associations
2,472,558
<p>Sometimes (in customer's PCs) I need a python script to execute in the Windows shell like a .CMD or .BAT, but without having the .py or .pyw extensions associated with PYTHON / PYTHONW.</p> <p>I came out with a pair of 'quick'n dirty' solutions:</p> <p>1)</p> <pre><code>""" e:\devtool\python\python.exe %0 :: or %...
7
2010-03-18T18:56:00Z
2,472,660
<p>You can try to create a script what is both <code>python</code> and <code>windows shell script</code>. In this case you can name you file <code>my_flexible_script.bat</code> and execute it either directly or via <code>python ...</code>.</p> <p>See a content of <code>pylint.bat</code> file from <a href="http://www.l...
9
2010-03-18T19:12:50Z
[ "python", "shell" ]
Checkout/List remote branches in git-python
2,473,035
<p>I don't see an option to checkout or list remote/local branches in this module</p> <p><a href="http://gitorious.org/git-python/">http://gitorious.org/git-python/</a></p>
6
2010-03-18T20:09:24Z
2,473,118
<p>After you’ve done</p> <pre><code>from git import Git g = Git() </code></pre> <p>(and possibly some other command to init <code>g</code> to the repository you care about) all attribute requests on <code>g</code> are more or less transformed into a call of <code>git attr *args</code>.</p> <p>Therefore:</p> <pre>...
7
2010-03-18T20:23:41Z
[ "python", "git" ]
Cannot turn off autocommit in a script using the Django ORM
2,473,090
<p>I have a command line script that uses the Django ORM and MySQL backend. I want to turn off autocommit and commit manually. For the life of me, I cannot get this to work. Here is a pared down version of the script. A row is inserted into testtable every time I run this and I get this warning from MySQL: "Some no...
3
2010-03-18T20:18:13Z
2,473,205
<p>Are your tables MyISAM or InnoDB? Remember that MyISAM isn't transactional, so can't be rolled back. See for example <a href="http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-transactions.html" rel="nofollow">this page</a> in the MySQL documentation:</p> <blockquote> <p>In transactional terms, MyISAM tables effec...
2
2010-03-18T20:39:08Z
[ "python", "mysql", "django", "command-line" ]
Python: write to file multiple times without open/close for each write
2,473,202
<p>How can i open file in python and write to it multiple times?</p> <p>I am using speech recognition, and i want one file to change its contents based on what i say. Other application needs to be able to read this file. Is there way to do this, or i need to open/close for each write?</p>
3
2010-03-18T20:38:49Z
2,473,209
<pre><code>f = open('myfile.txt','w') f.write('Hi') f.write('Hi again!') f.write('Is this thing on?') # do this as long as you need to f.seek(0,0) # return to the beginning of the file if you need to f.close() # close the file handle </code></pre>
1
2010-03-18T20:40:20Z
[ "python", "file" ]
Python: write to file multiple times without open/close for each write
2,473,202
<p>How can i open file in python and write to it multiple times?</p> <p>I am using speech recognition, and i want one file to change its contents based on what i say. Other application needs to be able to read this file. Is there way to do this, or i need to open/close for each write?</p>
3
2010-03-18T20:38:49Z
2,473,227
<p>You can just keep the file object around and write to it whenever you want. You might need to flush it after each write to make things visible to the outside world.</p> <p>If you do the writes from a different process, just open the file in append mode ("a").</p>
4
2010-03-18T20:42:53Z
[ "python", "file" ]