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 do I ensure I always get a list of matches from Python's Regular Expressions?
2,370,369
<p>I'm trying to pull some information (no recursion necessary) from a jsp page (malformed xml) similar to this:</p> <pre><code>&lt;td&gt; &lt;html:button ...&gt;&lt;/html:button&gt; &lt;html:submit ...&gt;&lt;/html:submit&gt;&lt;/td&gt; </code></pre> <p>And a regex:</p> <pre><code>&lt;html:(button|submit|cancel)[\s...
0
2010-03-03T10:26:03Z
2,370,396
<p>Your <code>(button|submit|cancel)</code> getting capture, so add <code>?:</code> in brackets like <code>(?:</code></p> <pre><code>&gt;&gt;&gt; re.findall('&lt;html:(?:button|submit|cancel)[\s\S]*?&lt;/html:(?:button|submit|cancel)&gt;',TheHTMLWhichShouldntParseWithRegex) ['&lt;html:button ...&gt;&lt;/html:button&gt...
1
2010-03-03T10:30:42Z
[ "python", "regex", "tuples", "findall" ]
SOAP 1.2 python client
2,370,573
<p>I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1:</p> <ul> <li>suds</li> <li>SOAPpy</li> <li>ZSI</li> </ul>
13
2010-03-03T11:01:19Z
2,389,490
<p>The <a href="https://github.com/mvantellingen/python-zeep" rel="nofollow">zeep</a> library supports both SOAP 1.1 and 1.2 as long as the service's WSDL properly indicates it.</p> <p><s> WSF/Python is supporting SOAP 1.2.</p> <blockquote> <h2>INTRODUCTION</h2> <p>WSF/Python is the Python language extension t...
8
2010-03-05T19:42:46Z
[ "python", "soap" ]
SOAP 1.2 python client
2,370,573
<p>I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1:</p> <ul> <li>suds</li> <li>SOAPpy</li> <li>ZSI</li> </ul>
13
2010-03-03T11:01:19Z
2,430,740
<p>If you are really wanting to use SOAP 1.2 even though it is not used as a standard as yet, I reckon I can post an answer that requires some work (all for the greater good <code>:)</code>).</p> <p>I recommend that you use <strong><a href="http://sourceforge.net/projects/gsoap2/files/" rel="nofollow">gSOAP</a></stron...
4
2010-03-12T05:44:07Z
[ "python", "soap" ]
SOAP 1.2 python client
2,370,573
<p>I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1:</p> <ul> <li>suds</li> <li>SOAPpy</li> <li>ZSI</li> </ul>
13
2010-03-03T11:01:19Z
2,432,893
<p>I have had the very similar problem some years ago and I have solved it by using Jython.</p> <p>If there is no existed implementation of SOAP 1.2 for Python, you may be interested in <a href="http://www.jython.org/" rel="nofollow">Jython</a>, which seamlessly integrates you with the Java platform. It means, you can...
1
2010-03-12T13:12:22Z
[ "python", "soap" ]
SOAP 1.2 python client
2,370,573
<p>I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1:</p> <ul> <li>suds</li> <li>SOAPpy</li> <li>ZSI</li> </ul>
13
2010-03-03T11:01:19Z
5,262,037
<p>Even though this question has an accepted answer, there's a few notes I'd like regarding suds.</p> <p>I'm currently writing some code for interfacing with .tel community hosting for work and I needed a Python SOAP library, and suds was pretty much ideal except for its lack of support for SOAP 1.2.</p> <p>I managed...
11
2011-03-10T15:41:42Z
[ "python", "soap" ]
Python stream http client with keep-alive
2,370,692
<p>I need a python http client that can reuse connections and that supports consuming the stream as it comes in. It will be used to parse xml streams, sax style.</p> <p>I came up with a solution, but I'm not sure it is the best one (there are quite a few ways of writing an http client in python)</p> <pre><code>class ...
1
2010-03-03T11:20:15Z
2,372,772
<p><a href="http://urlgrabber.baseurl.org/" rel="nofollow"><code>urlgrabber</code></a> supports keepalive and can return a file-like object.</p>
1
2010-03-03T15:59:29Z
[ "python", "http", "streaming", "client", "keep-alive" ]
Python stream http client with keep-alive
2,370,692
<p>I need a python http client that can reuse connections and that supports consuming the stream as it comes in. It will be used to parse xml streams, sax style.</p> <p>I came up with a solution, but I'm not sure it is the best one (there are quite a few ways of writing an http client in python)</p> <pre><code>class ...
1
2010-03-03T11:20:15Z
2,642,500
<p>There is also <a href="http://pycurl.sourceforge.net/" rel="nofollow">pycurl</a>. By default keepalive is turned on and you can write to a file for output.</p> <p>Follow the examples, they are quite helpful</p>
1
2010-04-15T03:13:27Z
[ "python", "http", "streaming", "client", "keep-alive" ]
best way to do this string conversion in Python
2,370,974
<p>I need to convert a string to another which has removed anything before the second word</p> <p>Example from this,</p> <pre><code>string = "xyz anything else" string2 = "xyz anything else" string3 = "xyz anything else" </code></pre> <p>to this,</p> <pre><code>string = "anything else" string2 = "anything else"...
0
2010-03-03T12:03:58Z
2,371,004
<pre><code>s.split(None, 1)[-1] </code></pre>
6
2010-03-03T12:08:10Z
[ "python" ]
Listing names of available Virtualbox VMs using Python
2,371,076
<p>How do I list the names of available VirtualBox virtual machines with <strong><a href="http://code.google.com/p/pyvb/" rel="nofollow">pyvb</a></strong> modules?</p>
1
2010-03-03T12:17:17Z
2,371,185
<p>A good resource to learn VBox Python API is read the implementation of <a href="http://code.google.com/p/vboxweb/" rel="nofollow">vboxweb</a></p> <p>For your specific question, you can take a look at line 289 of <a href="http://code.google.com/p/vboxweb/source/browse/branches/VBox-3.0/VBoxWebSrv.py" rel="nofollow">...
4
2010-03-03T12:32:06Z
[ "python", "virtualbox" ]
Listing names of available Virtualbox VMs using Python
2,371,076
<p>How do I list the names of available VirtualBox virtual machines with <strong><a href="http://code.google.com/p/pyvb/" rel="nofollow">pyvb</a></strong> modules?</p>
1
2010-03-03T12:17:17Z
21,603,597
<p>To complete the answer from Findekano, I will add the last line:</p> <pre><code>import vboxapi virtualBoxManager = vboxapi.VirtualBoxManager(None, None) vbox = virtualBoxManager.vbox vboxVMList = virtualBoxManager.getArray(vbox, 'machines') vboxNameList = [mach.name for mach in vboxVMList] </code></pre>
1
2014-02-06T12:54:45Z
[ "python", "virtualbox" ]
Unable to get set intersection to work
2,371,405
<p>Sorry for the double post, I will update this question if I can't get things to work :)</p> <p>I am trying to compare two files. I will list the two file content:</p> <pre><code> File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 ...
0
2010-03-03T13:05:30Z
2,371,515
<p>The problem is that you are using the intersection instead of the difference :)</p> <p>If you use <code>target_set.difference(target_set_1)</code> you will have the results you're looking for.</p> <p>I'm not sure if I'm completely getting what you want, but is this what you are looking for?</p> <pre><code>def com...
2
2010-03-03T13:19:28Z
[ "python", "compare", "set", "loops" ]
Unable to get set intersection to work
2,371,405
<p>Sorry for the double post, I will update this question if I can't get things to work :)</p> <p>I am trying to compare two files. I will list the two file content:</p> <pre><code> File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 ...
0
2010-03-03T13:05:30Z
2,371,546
<p>You need to use <em>difference</em> instead of <em>intersection</em>, since the latter will give you items that are in both sets. You can also use the set1 - set2 syntax. <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset" rel="nofollow">See the python docs for sets</a>.</p> <p>I think yo...
1
2010-03-03T13:22:56Z
[ "python", "compare", "set", "loops" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
2,371,484
<p>You need to use the <strong>eval() function</strong>, as in</p> <pre><code>#btw that's probably what you meant, 2 to the 4th power, not the XOR operation &gt;&gt;&gt;stringExp = "2**4" &gt;&gt;&gt;print(eval(stringExp)) 16 </code></pre> <p>Beware that <strong>eval(), and its cousin exec() are dangerous tools in...
6
2010-03-03T13:15:39Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
2,371,522
<p>If you don't want to use eval, then the only solution is to implement the appropriate grammar parser. Have a look at <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a>.</p>
1
2010-03-03T13:19:45Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
2,371,543
<p>I think I would use <code>eval()</code>, but would first check to make sure the string is a valid mathematical expression, as opposed to something malicious. You could use a regex for the validation.</p> <p><code>eval()</code> also takes additional arguments which you can use to restrict the namespace it operates ...
2
2010-03-03T13:22:36Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
2,371,789
<p><a href="http://pyparsing.wikispaces.com/">Pyparsing</a> can be used to parse mathematical expressions. In particular, <a href="http://pyparsing.wikispaces.com/file/view/fourFn.py">fourFn.py</a> shows how to parse basic arithmetic expressions. Below, I've rewrapped fourFn into a numeric parser class for easier reuse...
47
2010-03-03T13:52:30Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
2,372,145
<p>Use <code>eval</code> in a clean namespace:</p> <pre><code>&gt;&gt;&gt; ns = {'__builtins__': None} &gt;&gt;&gt; eval('2 ** 4', ns) 16 </code></pre> <p>The clean namespace should prevent injection. For instance:</p> <pre><code>&gt;&gt;&gt; eval('__builtins__.__import__("os").system("echo got through")', ns) Trace...
3
2010-03-03T14:42:24Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
9,556,473
<p>This is a massively late reply, but I think useful for future reference. Rather than write your own math parser (although the pyparsing example above is great) you could use SymPy. I don't have a lot of experience with it, but it contains a much more powerful math engine than anyone is likely to write for a specific...
3
2012-03-04T16:08:10Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
9,558,001
<h2><code>eval</code> is evil</h2> <pre><code>eval("__import__('os').remove('important file')") # arbitrary commands eval("9**9**9**9**9**9**9**9", {'__builtins__': None}) # CPU, memory </code></pre> <p>Note: even if you use set <code>__builtins__</code> to <code>None</code> it still might be possible to break out us...
96
2012-03-04T19:15:26Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
16,323,878
<p>Python already has a function for safely evaluating strings containing literal expressions:</p> <p><a href="http://docs.python.org/2/library/ast.html#ast.literal_eval" rel="nofollow">http://docs.python.org/2/library/ast.html#ast.literal_eval</a></p>
1
2013-05-01T18:14:09Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
18,096,137
<p>Try <a href="http://newville.github.io/asteval/" rel="nofollow">asteval</a> or possibly <a href="https://github.com/pydata/numexpr" rel="nofollow">numexpr</a> for possibly safer alternatives to <code>eval()</code> and <code>Sympy.sympify().evalf()</code>.</p>
7
2013-08-07T06:28:40Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
25,437,733
<p>Okay, so the problem with eval is that it can escape its sandbox too easily, even if you get rid of <code>__builtins__</code>. All the methods for escaping the sandbox come down to using <code>getattr</code> or <code>object.__getattribute__</code> (via the <code>.</code> operator) to obtain a reference to some dang...
4
2014-08-21T23:59:21Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
30,516,254
<p>You can use the ast module and write a NodeVisitor that verifies that the type of each node is part of a whitelist.</p> <pre><code>import ast, math locals = {key: value for (key,value) in vars(math).items() if key[0] != '_'} locals.update({"abs": abs, "complex": complex, "min": min, "max": max, "pow": pow, "round...
2
2015-05-28T20:13:52Z
[ "python", "math" ]
Evaluating a mathematical expression in a string
2,371,436
<pre><code>stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 </code></pre> <p>This returns the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: invalid literal for int() with base 10: '2^4' </code></pre> <p>I know that ...
49
2010-03-03T13:10:39Z
35,930,111
<p>The reason <code>eval</code> and <code>exec</code> are so dangerous is that the default <code>compile</code> function will generate bytecode for any valid python expression, and the default <code>eval</code> or <code>exec</code> will execute any valid python bytecode. All the answers to date have focused on restric...
2
2016-03-11T00:34:34Z
[ "python", "math" ]
How to append EOF to file using Perl or Python?
2,371,645
<p>I’m trying to bulk insert data to SQL server express database. When doing bcp from Windows XP command prompt, I get the following error:</p> <pre>C:\temp>bcp in -T -f -S Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file 0 row...
0
2010-03-03T13:35:57Z
2,371,680
<p>This is not a problem with missing EOF, but with EOF that is there and is not expected by bcp.</p> <p>I am not a bcp tool expert, but it looks like there is some problem with format of your data files.</p>
1
2010-03-03T13:39:17Z
[ "python", "sql-server", "perl", "bcp" ]
How to append EOF to file using Perl or Python?
2,371,645
<p>I’m trying to bulk insert data to SQL server express database. When doing bcp from Windows XP command prompt, I get the following error:</p> <pre>C:\temp>bcp in -T -f -S Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file 0 row...
0
2010-03-03T13:35:57Z
2,371,725
<p>EOF is End Of File. What probably occurred is that the file is not complete; the software expects data, but there is none to be had anymore.</p> <p>These kinds of things happen when:</p> <ul> <li>the export is interrupted (quit dump software while dumping)</li> <li>while copying the dumpfile aborting the copy</li>...
3
2010-03-03T13:44:38Z
[ "python", "sql-server", "perl", "bcp" ]
How to append EOF to file using Perl or Python?
2,371,645
<p>I’m trying to bulk insert data to SQL server express database. When doing bcp from Windows XP command prompt, I get the following error:</p> <pre>C:\temp>bcp in -T -f -S Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file 0 row...
0
2010-03-03T13:35:57Z
2,371,888
<p>Unexpected EOF means that the bcp reader found an EOF when it was expecting more data. This EOF can be:</p> <p>(1) the actual physical end-of-file (no more bytes to be read). This means that you have mis-formatted data. Check near the end of your file for an incomplete record.</p> <p>OR</p> <p>(2) on Windows, whe...
3
2010-03-03T14:08:18Z
[ "python", "sql-server", "perl", "bcp" ]
Importing bytea field into PostgreSQL database via psycopg2
2,371,779
<p>I have a list of values as such:</p> <pre><code>row = ['0x14', '0xb6', '0xa1', '0x0', '0xa1', '0x0'] </code></pre> <p>I would like to insert these into a <code>bytea</code> field in my PostgreSQL database, using psycopg2, but I am unfamiliar with byte strings in python.</p> <p>What is the best way to achieve this...
3
2010-03-03T13:50:42Z
2,372,219
<p>I am not sure if this is the correct way, but the following appears to work: </p> <pre><code> row = ['0x14', '0xb6', '0xa1', '0x0', '0xa1', '0x0'] as_hex = ''.join(byte[2:].zfill(2) for byte in row) # as_hex = '14b6a100a100' bytes = buffer(as_hex.decode('hex')) cur.execute("INSERT INTO mylog (bi...
2
2010-03-03T14:51:36Z
[ "python", "postgresql", "psycopg2" ]
More efficient solution to loop nesting required
2,371,956
<p>I am trying to compare two files. I will list the two file content:</p> <pre><code> File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 ...
0
2010-03-03T14:17:37Z
2,372,308
<p>Pointers:</p> <ul> <li>Use list comprehensions or generator expressions to simplify data processing. More readable</li> <li>Just generate the sets once.</li> <li>Use functions to not repeat yourself, especially doing the same task twice.</li> </ul> <p>I've made a few assumptions about your input data, you might wa...
1
2010-03-03T15:04:15Z
[ "python", "loops", "for-loop", "nested" ]
More efficient solution to loop nesting required
2,371,956
<p>I am trying to compare two files. I will list the two file content:</p> <pre><code> File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 ...
0
2010-03-03T14:17:37Z
2,372,784
<p>There's already a good answer, by @MattH, focused on the Python details of your problem, and while it can be improved in several details the improvements would only gain you some percentage points in efficiency -- worthwhile but not great.</p> <p>The only hope for a <em>huge</em> boost in efficiency (as opposed to ...
1
2010-03-03T16:00:28Z
[ "python", "loops", "for-loop", "nested" ]
Python - functional "find"?
2,371,979
<p>I need a function, which is capable of iterating over the collection, calling a supplied function with element of the collection as a parameter and returning the parameter or it's index when received "True" from supplied function.</p> <p>It is somethong like this:</p> <pre><code>def find(f, seq, index_only=True, i...
5
2010-03-03T14:20:25Z
2,372,007
<p>You can use <code>itertools.dropwhile</code> to skip over the items for which the supplied function returns <code>False</code>, then take the first item of the rest (if any). If you need the index rather than the item, incorporate <code>enumerate</code> from the Recipes section of <a href="http://docs.python.org/lib...
2
2010-03-03T14:24:41Z
[ "python", "functional-programming", "lambda" ]
Python - functional "find"?
2,371,979
<p>I need a function, which is capable of iterating over the collection, calling a supplied function with element of the collection as a parameter and returning the parameter or it's index when received "True" from supplied function.</p> <p>It is somethong like this:</p> <pre><code>def find(f, seq, index_only=True, i...
5
2010-03-03T14:20:25Z
2,372,013
<p>Try <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools</a> and for example <a href="http://docs.python.org/library/itertools.html#itertools.ifilter" rel="nofollow">ifilter</a>.</p>
3
2010-03-03T14:25:05Z
[ "python", "functional-programming", "lambda" ]
Python - functional "find"?
2,371,979
<p>I need a function, which is capable of iterating over the collection, calling a supplied function with element of the collection as a parameter and returning the parameter or it's index when received "True" from supplied function.</p> <p>It is somethong like this:</p> <pre><code>def find(f, seq, index_only=True, i...
5
2010-03-03T14:20:25Z
2,372,051
<p>I don't think there is any such function with such exact semantics, and anyway your function is short , good enough and you can easily improve it for later use, so use it.</p> <p>because simple is better than complex.</p>
3
2010-03-03T14:30:45Z
[ "python", "functional-programming", "lambda" ]
function not defined but really is defined
2,371,981
<p>I am writing a script and in my script I have this function:</p> <pre><code>def insert_image(cursor, object_id, sku): product_obj = core.Object.get(object_id) string_sku = str(sku) folder = string_sku[0] + string_sku[1] + string_sku[2] found_url = False # KLUDGE This is ugly and redundant, howev...
0
2010-03-03T14:20:31Z
2,371,987
<p>You have syntax errors in your function:</p> <pre><code>try urllib.urlopen("http://&lt;path to images&gt;/%s/%sPR-IT,PM.jpg" % (folder, sku)): urllib.URLopener().retrieve("http://&lt;path to images&gt;/%s/%sPR-IT,PM.jpg" % (folder, sku), "%sPR-IT,PM.jpg" % (sku)) found_url = True except: ...
3
2010-03-03T14:22:08Z
[ "python", "nameerror" ]
function not defined but really is defined
2,371,981
<p>I am writing a script and in my script I have this function:</p> <pre><code>def insert_image(cursor, object_id, sku): product_obj = core.Object.get(object_id) string_sku = str(sku) folder = string_sku[0] + string_sku[1] + string_sku[2] found_url = False # KLUDGE This is ugly and redundant, howev...
0
2010-03-03T14:20:31Z
2,372,003
<p>This sounds like you have a whitespace issue before the method. The incorrect whitespace has moved it outside of the normal code path and if it is in a class it may not appear to be in the class any more</p>
0
2010-03-03T14:24:03Z
[ "python", "nameerror" ]
Scrapy install: no acceptable C compiler found in $PATH
2,371,997
<p>I am trying to install <a href="http://scrapy.org/" rel="nofollow">Scrapy</a> on a a Mac OS X 10.6.2 machine... When i try to build one of the dependent modules ( libxml2 )</p> <p>I am getting the following error: </p> <pre><code>configure: error: no acceptable C compiler found in $PATH </code></pre> <p>I assume...
2
2010-03-03T14:23:04Z
2,372,052
<p>You need to install the Apple Xcode Development tools. There would be on <a href="http://connect.apple.com/" rel="nofollow">Apple Developer Connection site</a> or on your Mac OS X installation CDs/DVD. Ensure that the optional components for command line development are installed ("Unix Development" in the Xcode 3.x...
2
2010-03-03T14:30:52Z
[ "python", "osx", "gcc", "scrapy" ]
Scrapy install: no acceptable C compiler found in $PATH
2,371,997
<p>I am trying to install <a href="http://scrapy.org/" rel="nofollow">Scrapy</a> on a a Mac OS X 10.6.2 machine... When i try to build one of the dependent modules ( libxml2 )</p> <p>I am getting the following error: </p> <pre><code>configure: error: no acceptable C compiler found in $PATH </code></pre> <p>I assume...
2
2010-03-03T14:23:04Z
2,372,053
<p>You need to install XCode ('developer tools') from the Snow Leopard DVD - this includes gcc among much other stuff. You should also run software update after the install to freshen it</p>
1
2010-03-03T14:30:55Z
[ "python", "osx", "gcc", "scrapy" ]
Scrapy install: no acceptable C compiler found in $PATH
2,371,997
<p>I am trying to install <a href="http://scrapy.org/" rel="nofollow">Scrapy</a> on a a Mac OS X 10.6.2 machine... When i try to build one of the dependent modules ( libxml2 )</p> <p>I am getting the following error: </p> <pre><code>configure: error: no acceptable C compiler found in $PATH </code></pre> <p>I assume...
2
2010-03-03T14:23:04Z
4,173,182
<p>Might be of interest to know that upgrading from OS X 10.5 to 10.6 <a href="http://www.brianp.net/2009/09/05/snow-leopards-ate-my-c-compiler/" rel="nofollow">apparently</a> unlinks the existing developer tools thus requiring a reinstall from the SL DVD for gcc to work as usual. </p> <p>Most annoying when you though...
2
2010-11-13T15:13:02Z
[ "python", "osx", "gcc", "scrapy" ]
Imports in Python project with doctests
2,372,125
<p>I have a Python project with following directory structure:</p> <pre> /(some files) /model/(python files) /tools/(more python files) ... </pre> <p>So, I have Python files in couple subdirectories and there are some dependencies between directories as well: tools are used by model, etc. Now my problem is that I wa...
3
2010-03-03T14:40:00Z
2,372,200
<p>Use packages. Add an <code>__init__.py</code> file to your working directory and all subfolders then your imports will search the parent directories if it doesn't find the module in the current directory.</p> <p>See <a href="http://www.network-theory.co.uk/docs/pytut/Packages.html" rel="nofollow">http://www.networ...
1
2010-03-03T14:49:15Z
[ "python", "linux", "unix", "path" ]
Imports in Python project with doctests
2,372,125
<p>I have a Python project with following directory structure:</p> <pre> /(some files) /model/(python files) /tools/(more python files) ... </pre> <p>So, I have Python files in couple subdirectories and there are some dependencies between directories as well: tools are used by model, etc. Now my problem is that I wa...
3
2010-03-03T14:40:00Z
2,372,420
<p>Don't frob <code>sys.path</code> in this manner. Instead either use <code>$PYTHONPATH</code> to force the base directory in when invoking <code>python</code>, or use <code>python -m model.car</code> from that directory.</p>
0
2010-03-03T15:16:47Z
[ "python", "linux", "unix", "path" ]
Imports in Python project with doctests
2,372,125
<p>I have a Python project with following directory structure:</p> <pre> /(some files) /model/(python files) /tools/(more python files) ... </pre> <p>So, I have Python files in couple subdirectories and there are some dependencies between directories as well: tools are used by model, etc. Now my problem is that I wa...
3
2010-03-03T14:40:00Z
2,378,342
<p>What you are trying to do is a relative import. It works fine in Python, <strong>but on the module level, not on the file system level.</strong> I know, this is confusing.</p> <p>It means that if you run a script in a subdir, it doesn't see the upper dirs because for the running script, the root of the module is th...
0
2010-03-04T10:12:17Z
[ "python", "linux", "unix", "path" ]
Python XML to dictionary to iterate over items
2,372,217
<p>I have the following XML example</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;test&gt; &lt;items&gt; &lt;item&gt;item 1&lt;/item&gt; &lt;item&gt;item 2&lt;/item&gt; &lt;/items&gt; &lt;/test&gt; </code></pre> <p>I need to iterate over each tag in a for loop in python. If tried many things...
4
2010-03-03T14:51:32Z
2,372,258
<p>Try xml parser from <code>xml.sax</code> package in standard library.</p> <pre> from xml.sax import parse from xml.sax.handler import ContentHandler from sys import argv class Handler(ContentHandler): def startElementNS(self, name, qname, attrs): self.startElement(name, attrs) def endElementNs(sel...
1
2010-03-03T14:56:58Z
[ "python", "xml" ]
Python XML to dictionary to iterate over items
2,372,217
<p>I have the following XML example</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;test&gt; &lt;items&gt; &lt;item&gt;item 1&lt;/item&gt; &lt;item&gt;item 2&lt;/item&gt; &lt;/items&gt; &lt;/test&gt; </code></pre> <p>I need to iterate over each tag in a for loop in python. If tried many things...
4
2010-03-03T14:51:32Z
2,372,264
<pre><code>import xml.dom.minidom as md x='''&lt;?xml version="1.0"?&gt; &lt;test&gt; &lt;items&gt; &lt;item&gt;item 1&lt;/item&gt; &lt;item&gt;item 2&lt;/item&gt; &lt;/items&gt; &lt;/test&gt; ''' xml=md.parseString(x) items=xml.getElementsByTagName("item") # [&lt;DOM Element: item at 0xc16e4...
1
2010-03-03T14:58:05Z
[ "python", "xml" ]
Python XML to dictionary to iterate over items
2,372,217
<p>I have the following XML example</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;test&gt; &lt;items&gt; &lt;item&gt;item 1&lt;/item&gt; &lt;item&gt;item 2&lt;/item&gt; &lt;/items&gt; &lt;/test&gt; </code></pre> <p>I need to iterate over each tag in a for loop in python. If tried many things...
4
2010-03-03T14:51:32Z
2,372,270
<p>I personally use <a href="http://docs.python.org/library/xml.etree.elementtree.html"><code>xml.etree.cElementTree</code></a>, as I've found it works really well, it's fast, <a href="http://codespeak.net/lxml/tutorial.html">easy to use</a>, and <a href="http://www.ibm.com/developerworks/xml/library/x-hiperfparse/">wo...
6
2010-03-03T14:59:01Z
[ "python", "xml" ]
Python XML to dictionary to iterate over items
2,372,217
<p>I have the following XML example</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;test&gt; &lt;items&gt; &lt;item&gt;item 1&lt;/item&gt; &lt;item&gt;item 2&lt;/item&gt; &lt;/items&gt; &lt;/test&gt; </code></pre> <p>I need to iterate over each tag in a for loop in python. If tried many things...
4
2010-03-03T14:51:32Z
2,372,271
<p>You would probably like to use something like <a href="http://effbot.org/zone/element-index.htm" rel="nofollow">ElementTree</a> This is a well renowned library, I have not personally used it but I always hear good things. </p> <p>Also as of python 2.5 it's part of the standard library</p>
0
2010-03-03T14:59:08Z
[ "python", "xml" ]
Is there a Python version of CPAN?
2,372,445
<p>So I've been using Perl for several years now and I'm starting to dabble a little in Python. Is there a sort of CPAN but for Python? What's the normal way to manage modules in Python? Any direction would be greatly appreciated. FWIW I use Linux so Windows-only solutions aren't really useful to me.</p>
3
2010-03-03T15:19:38Z
2,372,463
<p><a href="http://pypi.python.org/pypi">The repository formerly known as Cheese Shop</a>.</p> <blockquote> <h2><a href="http://pypi.python.org/pypi">PyPI</a></h2> <p>The Python Package Index is a repository of software for the Python programming language. There are currently 9140 packages here. To contact the ...
11
2010-03-03T15:21:26Z
[ "python" ]
Is there a Python version of CPAN?
2,372,445
<p>So I've been using Perl for several years now and I'm starting to dabble a little in Python. Is there a sort of CPAN but for Python? What's the normal way to manage modules in Python? Any direction would be greatly appreciated. FWIW I use Linux so Windows-only solutions aren't really useful to me.</p>
3
2010-03-03T15:19:38Z
2,372,470
<p>Check out <a href="http://mrtopf.de/blog/python_zope/a-small-introduction-to-python-eggs/" rel="nofollow">Python eggs / easy_install</a></p>
1
2010-03-03T15:22:09Z
[ "python" ]
How do I remove whitespace from the end of a string in Python?
2,372,573
<p>I need to remove whitespaces after the word in the string. Can this be done in one line of code?</p> <p>Example:</p> <pre><code>string = " xyz " desired result : " xyz" </code></pre>
36
2010-03-03T15:36:14Z
2,372,578
<pre><code>&gt;&gt;&gt; " xyz ".rstrip() ' xyz' </code></pre> <p>more about <code>rstrip</code> in <a href="http://docs.python.org/library/stdtypes.html#str.rstrip">docs</a></p>
67
2010-03-03T15:37:00Z
[ "python" ]
Error installing scrapy on Mac Os X 10.6
2,372,758
<p>Trying to install Scrapy on Mac OSX 10.6 using this <a href="http://doc.scrapy.org/intro/install.html" rel="nofollow">guide</a>:</p> <p>When running these commands from Terminal:</p> <pre><code>cd libxml2-2.7.3/python sudo make install </code></pre> <p>I get the following error:</p> <pre><code>Making install in ...
3
2010-03-03T15:57:50Z
2,375,162
<p>The simplest approach is to use MacPorts to <a href="http://stackoverflow.com/questions/2353957/do-i-need-32bit-libxml2-for-python-on-snow-leopard/">install python and the libraries you need</a>. </p>
2
2010-03-03T21:35:16Z
[ "python", "osx", "libxml2", "scrapy" ]
Error installing scrapy on Mac Os X 10.6
2,372,758
<p>Trying to install Scrapy on Mac OSX 10.6 using this <a href="http://doc.scrapy.org/intro/install.html" rel="nofollow">guide</a>:</p> <p>When running these commands from Terminal:</p> <pre><code>cd libxml2-2.7.3/python sudo make install </code></pre> <p>I get the following error:</p> <pre><code>Making install in ...
3
2010-03-03T15:57:50Z
2,380,797
<p>Credit to @Ned Deily</p> <p>These steps seem to work if you want to run Scrapy 0.8 on OS X 10.6. It uses Macports install of Python 2.6 rather than the one bundled with the OS. Steps assume Macports is not installed yet.</p> <p>Get latest MacPorts installer from here and install:</p> <p><a href="http://www.macpor...
1
2010-03-04T16:14:33Z
[ "python", "osx", "libxml2", "scrapy" ]
Any ready solution for basic asynchronous (non-blocking) HTTP clients with Stackless Python 3.1?
2,372,762
<p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org...
3
2010-03-03T15:58:24Z
4,814,749
<p>I know this is like resurrecting the dead (and flow has probably long since solved his problem), but for completeness stackless is available for 3.1.3:</p> <ul> <li><a href="http://www.stackless.com/download" rel="nofollow">http://www.stackless.com/download</a></li> </ul> <p>For information on implementing a HTTP ...
0
2011-01-27T09:43:03Z
[ "python", "http", "stackless", "python-stackless" ]
Any ready solution for basic asynchronous (non-blocking) HTTP clients with Stackless Python 3.1?
2,372,762
<p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org...
3
2010-03-03T15:58:24Z
6,174,826
<p>Non blocking HTTP case is very well handled with twisted, what is does is creating a series of callbacks, and registering those callbacks with deferred. <a href="http://twistedmatrix.com/documents/current/core/howto/index.html" rel="nofollow">Twisted documentation</a> is worth checking out. Stackless uses microthrea...
0
2011-05-30T09:58:44Z
[ "python", "http", "stackless", "python-stackless" ]
Python: Fast querying in a big dbf (xbase) file
2,373,086
<p>I have a big DBF file (~700MB). I'd like to select only a few lines from it using a python script. I've seen that dbfpy is a nice module that allows to open this type of database, but for now I haven't found any querying capability. Iterating through all the elements from python is simply too slow.</p> <p>Can I do ...
5
2010-03-03T16:38:47Z
2,375,732
<p>If you are using Windows you can use the <a href="http://docs.activestate.com/activepython/2.5/pywin32/odbc.html" rel="nofollow">odbc</a> module in combination with the <a href="http://msdn.microsoft.com/en-us/vfoxpro/bb190233.aspx" rel="nofollow">Visual FoxPro ODBC Driver</a></p>
1
2010-03-03T23:10:48Z
[ "python", "performance", "python-3.x", "dbf", "xbase" ]
Python: Fast querying in a big dbf (xbase) file
2,373,086
<p>I have a big DBF file (~700MB). I'd like to select only a few lines from it using a python script. I've seen that dbfpy is a nice module that allows to open this type of database, but for now I haven't found any querying capability. Iterating through all the elements from python is simply too slow.</p> <p>Can I do ...
5
2010-03-03T16:38:47Z
2,375,874
<p>Chances are, your performance is more I/O bound than CPU bound. As such, the best way to speed it up is to optimize your search. You probably want to build some kind of index keyed by whatever your search predicate is.</p>
2
2010-03-03T23:34:22Z
[ "python", "performance", "python-3.x", "dbf", "xbase" ]
Python: Fast querying in a big dbf (xbase) file
2,373,086
<p>I have a big DBF file (~700MB). I'd like to select only a few lines from it using a python script. I've seen that dbfpy is a nice module that allows to open this type of database, but for now I haven't found any querying capability. Iterating through all the elements from python is simply too slow.</p> <p>Can I do ...
5
2010-03-03T16:38:47Z
6,682,426
<p>Using <a href="http://pypi.python.org/pypi/dbf/">my dbf module</a> you can create temporary indexes and then search using those:</p> <pre><code>import dbf table = dbf.Table('big.dbf') index = table.create_index(lambda rec: rec.field) # field should be actual field name records = index.search(match=('value',)) </c...
8
2011-07-13T16:41:05Z
[ "python", "performance", "python-3.x", "dbf", "xbase" ]
Flickr API automated login using Python library flickrapi
2,373,194
<p>I have a web application that I want to sync with Flickr. I don't want the users to have to log into Flickr so I plan to use a single login. I believe I'll need to do something like this:</p> <pre><code>import flickrapi flickr = flickrapi.FlickrAPI(myKey, mySecret) (token, frob) = flickr.get_token_part_one(perms='w...
0
2010-03-03T16:52:43Z
2,373,235
<p>If you don't want your users to authenticate with Flickr, you don't need to use the token-getting code at all. Just get a token for yourself once and include it with your code.</p> <p>Note that "syncing" other users' photos with your own account probably breaks Flickr's TOS.</p>
1
2010-03-03T16:57:07Z
[ "python", "django", "flickr" ]
Pythonic and efficient way of finding adjacent cells in grid
2,373,306
<p>I am building a tile based app in Python using pyglet/openGL wherein I'll need to find the all of the adjacent cells for a given cell. I am working in one quadrant of a Cartesian grid. Each cell has an x and y value indicating it's position in the grid( x_coord and y_coord ). These are not pixel values, rather grid ...
7
2010-03-03T17:05:28Z
2,373,460
<p>Well, this won't help performance any, but you can avoid code duplication by saying</p> <pre><code>if abs(c.x_coord - x_coord) == 1 or abs(c.y_coord - y_coord) == 1: result.append(c) </code></pre> <p>To affect performance, your grid cells should know who their neighbors are, either through an attribute like <c...
2
2010-03-03T17:23:54Z
[ "python", "grid", "pyglet" ]
Pythonic and efficient way of finding adjacent cells in grid
2,373,306
<p>I am building a tile based app in Python using pyglet/openGL wherein I'll need to find the all of the adjacent cells for a given cell. I am working in one quadrant of a Cartesian grid. Each cell has an x and y value indicating it's position in the grid( x_coord and y_coord ). These are not pixel values, rather grid ...
7
2010-03-03T17:05:28Z
2,373,463
<p>This is probably the most efficient way to look for neighbours if grid.cells is implemented as a set (though there's a mistake in the first if-statement - you need to test for equality to x_coord + 1 rather than to x_coord).</p> <p>However, implementing grid.cells as a list of lists would allow you to refer to indi...
1
2010-03-03T17:24:24Z
[ "python", "grid", "pyglet" ]
Pythonic and efficient way of finding adjacent cells in grid
2,373,306
<p>I am building a tile based app in Python using pyglet/openGL wherein I'll need to find the all of the adjacent cells for a given cell. I am working in one quadrant of a Cartesian grid. Each cell has an x and y value indicating it's position in the grid( x_coord and y_coord ). These are not pixel values, rather grid ...
7
2010-03-03T17:05:28Z
2,373,480
<p>Your code is going to be as slow as large is your grid, because you're iterating over the cells just to get 8 of them (of which you already know their coordinates).</p> <p>If you can do random access by their indices, I suggest something like the following:</p> <pre><code>adjacency = [(i,j) for i in (-1,0,1) for j...
6
2010-03-03T17:27:44Z
[ "python", "grid", "pyglet" ]
Pythonic and efficient way of finding adjacent cells in grid
2,373,306
<p>I am building a tile based app in Python using pyglet/openGL wherein I'll need to find the all of the adjacent cells for a given cell. I am working in one quadrant of a Cartesian grid. Each cell has an x and y value indicating it's position in the grid( x_coord and y_coord ). These are not pixel values, rather grid ...
7
2010-03-03T17:05:28Z
2,373,689
<p>It wasn't clear to me if there was other information in the cells than just the x and y coordinates. In any case, I think that a change of data structures is needed to make this faster. </p> <p>I assumed that there is extra information in the cells and made <code>grid.cells</code> as a dictionary with the keys bein...
5
2010-03-03T17:58:03Z
[ "python", "grid", "pyglet" ]
Django Form inheritance problem
2,373,348
<p>Why can't I do this?</p> <pre><code>from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): def __init__(self,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.tester = 'asdf' username = forms.CharField(label='Username',max...
1
2010-03-03T17:10:31Z
2,373,395
<p>You can just do it <a href="http://stackoverflow.com/questions/2344994/extra-parameter-for-django-models">this way</a></p> <pre><code>from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): username = forms.CharField(label='Username',max_length=100,initial=self.tester) ...
1
2010-03-03T17:16:05Z
[ "python", "django", "django-forms" ]
Django Form inheritance problem
2,373,348
<p>Why can't I do this?</p> <pre><code>from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): def __init__(self,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.tester = 'asdf' username = forms.CharField(label='Username',max...
1
2010-03-03T17:10:31Z
2,373,397
<p>What you've got doesn't work because your <code>CharField</code> gets created, and pointed to by <code>UserProfileConfig.username</code> when the class is created, not when the instance is created. <code>self.tester</code> doesn't exist until you call <code>__init__</code> at instance creation time.</p>
2
2010-03-03T17:16:27Z
[ "python", "django", "django-forms" ]
Django Form inheritance problem
2,373,348
<p>Why can't I do this?</p> <pre><code>from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): def __init__(self,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.tester = 'asdf' username = forms.CharField(label='Username',max...
1
2010-03-03T17:10:31Z
2,877,616
<p>You could do this:-</p> <pre><code>class UserProfileConfig(forms.Form): username = forms.CharField(label='Username',max_length=100) def view(request): user_form = UserProfileConfig(initial={'username': request.session['username',}) </code></pre> <p>Which is the generally accepted method, but you can als...
0
2010-05-20T20:38:52Z
[ "python", "django", "django-forms" ]
any python socket server framework?
2,373,430
<p>I'm looking for a python socket server framework - not to handle http, but to handle tcp sockets. I've done it myself, but adding all the features is tedious. This framework would handle thread pooling, socket setup, signal handling, etc.</p> <p>A big feature is code-reloading. If I use apache/mod_python, or djang...
2
2010-03-03T17:21:11Z
2,373,489
<p><a href="http://twistedmatrix.com/" rel="nofollow">Twisted</a> is the usual suspect. Reloading in the case of <code>mod_wsgi</code> is easy since only the WSGI server needs to be restarted, not the whole web server (not that restarting the web server is all that hard, mind you...).</p>
4
2010-03-03T17:29:18Z
[ "python", "frameworks", "tcp" ]
any python socket server framework?
2,373,430
<p>I'm looking for a python socket server framework - not to handle http, but to handle tcp sockets. I've done it myself, but adding all the features is tedious. This framework would handle thread pooling, socket setup, signal handling, etc.</p> <p>A big feature is code-reloading. If I use apache/mod_python, or djang...
2
2010-03-03T17:21:11Z
2,373,508
<p>Use Apache, mod_wsgi in daemon mode and follow <a href="http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode" rel="nofollow">these guidelines</a>.</p> <p><strong>Update:</strong> I mentioned Apache because you did in your question - I assumed you were talking about a web application that also acted as a socket...
2
2010-03-03T17:32:21Z
[ "python", "frameworks", "tcp" ]
How do I run Javascript tests in Windmill when using test_windmill for Django?
2,373,446
<p>I'm using the Windmill test system and have it running using test_windmill for Django which works fine for the Python tests. I'd like this to run a suite of Javascript tests also whilst the Django test server is running. I've used the run_js_tests call from the Windmill shell which works fine but I can't find a way ...
0
2010-03-03T17:22:29Z
2,468,981
<p>Ok, so couldn't find out how to do this so I'm running the website under Apache and using the windmill standard jstests parameter to run the Javascript tests against this.</p>
0
2010-03-18T10:23:48Z
[ "python", "django", "unit-testing", "automated-tests", "windmill" ]
fast java/python/C++ ipc
2,373,540
<p>I notice this thread: <a href="http://stackoverflow.com/questions/1163574/fast-ish-python-jython-ipc">Fastish Python/Jython IPC</a>, and I have a similar problem, but in different language.</p> <p>I have a Java front-end and a C++ back-end, which I am thinking about rewrite it in Python in some near future. What wi...
1
2010-03-03T17:36:47Z
2,373,591
<p>For the C++ backend you can use <a href="http://xmlrpcpp.sourceforge.net/" rel="nofollow">xmlrpc++</a> (LGPL'ed) - I'm planning to use it myself. It has very clean code so you can modify it easily if you need to.</p> <p>As for the frontends in Java/Python, you could make use of <a href="http://ws.apache.org/xmlrpc/...
2
2010-03-03T17:43:13Z
[ "java", "c++", "python", "ipc", "rpc" ]
Pycurl cannot connect to host
2,373,857
<p>I am writing a pycurl script, which worked right on linux, but on mac os x I get the error:</p> <pre><code>Traceback (most recent call last): File "curl.py", line 47, in &lt;module&gt; c.perform() pycurl.error: (7, "couldn't connect to host") </code></pre> <p>any help?</p> <p>Thanks</p>
0
2010-03-03T18:22:27Z
2,373,978
<p>solved using this:</p> <pre><code>c.setopt(pycurl.PROXY, "url") c.setopt(pycurl.PROXYPORT, 8000) c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_HTTP) </code></pre>
0
2010-03-03T18:40:40Z
[ "python", "curl" ]
Pycurl cannot connect to host
2,373,857
<p>I am writing a pycurl script, which worked right on linux, but on mac os x I get the error:</p> <pre><code>Traceback (most recent call last): File "curl.py", line 47, in &lt;module&gt; c.perform() pycurl.error: (7, "couldn't connect to host") </code></pre> <p>any help?</p> <p>Thanks</p>
0
2010-03-03T18:22:27Z
15,539,250
<pre><code>curl.setopt(pycurl.PROXY, "url") curl.setopt(pycurl.PROXYPORT, 8000) curl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_HTTP) </code></pre>
1
2013-03-21T04:00:58Z
[ "python", "curl" ]
Django - Access request.session in form
2,373,867
<p>I am calling a form as follows, then passing it to a template:</p> <pre><code>f = UserProfileConfig(request) </code></pre> <p>I need to be able to access the request.session within the form... so first I tried this:</p> <pre><code>class UserProfileConfig(forms.Form): def __init__(self,request,*args,**kwargs)...
5
2010-03-03T18:24:01Z
2,374,072
<p>Try this:</p> <pre><code>class UserProfileConfig(forms.Form): def __init__(self,request,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.fields['username'] = forms.CharField(label='Username',max_length=100,initial=request.session['some_var']) </code></pre> <p>I fin...
9
2010-03-03T18:52:53Z
[ "python", "django", "django-forms" ]
Django - Access request.session in form
2,373,867
<p>I am calling a form as follows, then passing it to a template:</p> <pre><code>f = UserProfileConfig(request) </code></pre> <p>I need to be able to access the request.session within the form... so first I tried this:</p> <pre><code>class UserProfileConfig(forms.Form): def __init__(self,request,*args,**kwargs)...
5
2010-03-03T18:24:01Z
38,548,485
<p>I am so surprised that Django use session in form is so hard. sometimes we really need use session data in form to valid fields.</p> <p>I create a small project can solve this. <a href="https://github.com/9nix00/django-account-helper" rel="nofollow">django-account-helper</a></p> <p>example code:</p> <pre><code>f...
0
2016-07-24T03:32:08Z
[ "python", "django", "django-forms" ]
Set database connection timeout in Python
2,374,079
<p>I'm creating a RESTful API which needs to access the database. I'm using Restish, Oracle, and SQLAlchemy. However, I'll try to frame my question as generically as possible, without taking Restish or other web APIs into account.</p> <p>I would like to be able to set a timeout for a connection executing a query. T...
9
2010-03-03T18:53:49Z
2,375,685
<p>You could look at setting up <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6010.htm#i2065930" rel="nofollow">PROFILE</a>s in Oracle to terminate the queries after a certain number of logical_reads_per_call and/or cpu_per_call</p>
0
2010-03-03T23:02:40Z
[ "python", "database", "oracle", "cx-oracle", "python-db-api" ]
Set database connection timeout in Python
2,374,079
<p>I'm creating a RESTful API which needs to access the database. I'm using Restish, Oracle, and SQLAlchemy. However, I'll try to frame my question as generically as possible, without taking Restish or other web APIs into account.</p> <p>I would like to be able to set a timeout for a connection executing a query. T...
9
2010-03-03T18:53:49Z
2,424,224
<p><strong>Timing Out with the System Alarm</strong></p> <p>Here's how to use the operating system timout to do this. It's generic, and works for things other than Oracle.</p> <pre><code>import signal class TimeoutExc(Exception): """this exception is raised when there's a timeout""" def __init__(self): Excep...
-3
2010-03-11T10:38:24Z
[ "python", "database", "oracle", "cx-oracle", "python-db-api" ]
Set database connection timeout in Python
2,374,079
<p>I'm creating a RESTful API which needs to access the database. I'm using Restish, Oracle, and SQLAlchemy. However, I'll try to frame my question as generically as possible, without taking Restish or other web APIs into account.</p> <p>I would like to be able to set a timeout for a connection executing a query. T...
9
2010-03-03T18:53:49Z
2,976,544
<p>for the query, you can look on timer and conn.cancel() call.</p> <p>something in those lines:</p> <pre><code>t = threading.Timer(timeout,conn.cancel) t.start() cursor = conn.cursor() cursor.execute(query) res = cursor.fetchall() t.cancel() </code></pre>
9
2010-06-04T17:54:41Z
[ "python", "database", "oracle", "cx-oracle", "python-db-api" ]
Set database connection timeout in Python
2,374,079
<p>I'm creating a RESTful API which needs to access the database. I'm using Restish, Oracle, and SQLAlchemy. However, I'll try to frame my question as generically as possible, without taking Restish or other web APIs into account.</p> <p>I would like to be able to set a timeout for a connection executing a query. T...
9
2010-03-03T18:53:49Z
12,614,764
<p>In linux see /etc/oracle/sqlnet.ora, </p> <p><code>sqlnet.outbound_connect_timeout= value</code></p> <p>also have options:</p> <p>tcp.connect_timeout and sqlnet.expire_time, good luck!</p>
2
2012-09-27T05:40:30Z
[ "python", "database", "oracle", "cx-oracle", "python-db-api" ]
How can I determine the final URL after redirection using python / urllib2?
2,374,122
<p>I need to get the final URL after redirection in python. </p> <p>What's a good way to do that?</p>
4
2010-03-03T18:58:46Z
2,374,160
<pre><code>&gt;&gt;&gt; import urllib2 &gt;&gt;&gt; var = urllib2.urlopen('http://www.stackoverflow.com/') &gt;&gt;&gt; var.geturl() 'http://stackoverflow.com/' </code></pre>
8
2010-03-03T19:05:14Z
[ "python", "redirect", "urllib2" ]
global set up in django test framework?
2,374,197
<p>Is there some way (using the standard Django.test.TestCase framework) to perform a global initialization of certain variables, so that it only happens <em>once</em>.</p> <p>Putting things setUp() makes it so that the variables are initialized before each test, which kills performance when the setup involves expensi...
10
2010-03-03T19:11:50Z
2,375,500
<p>You don't need to "re-write the whole test runner framework" but you will need to create a custom test_runner (you can just <a href="http://code.djangoproject.com/browser/django/trunk/django/test/simple.py" rel="nofollow">copy the existing one</a> and modify it to include your global setup code). It's about 100 line...
2
2010-03-03T22:28:33Z
[ "python", "django", "testing" ]
global set up in django test framework?
2,374,197
<p>Is there some way (using the standard Django.test.TestCase framework) to perform a global initialization of certain variables, so that it only happens <em>once</em>.</p> <p>Putting things setUp() makes it so that the variables are initialized before each test, which kills performance when the setup involves expensi...
10
2010-03-03T19:11:50Z
17,292,269
<p>What about a class with static variables ? Something like :</p> <pre><code>class InitialSetup(object): GEOLOCATOR = GeoLocator() DEFAULT_LOCATION = GEOLOCATOR.get_geocode_object(settings.DEFAULT_ADDRESS, with_country=True) def setUp(self): self.geolocator = InitialSetup.GEOLOCATOR self....
0
2013-06-25T08:10:49Z
[ "python", "django", "testing" ]
global set up in django test framework?
2,374,197
<p>Is there some way (using the standard Django.test.TestCase framework) to perform a global initialization of certain variables, so that it only happens <em>once</em>.</p> <p>Putting things setUp() makes it so that the variables are initialized before each test, which kills performance when the setup involves expensi...
10
2010-03-03T19:11:50Z
17,461,581
<p>This is partially addressed in newer versions of python/django by setUpClass() which will at least allow me to run class level setup.</p>
2
2013-07-04T03:50:59Z
[ "python", "django", "testing" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,374,215
<p>I'd say Python.</p> <p>Have a look here for string permutations: <a href="http://www.daniweb.com/code/snippet216786.html" rel="nofollow">Permutations using a Combinations Generator (Python)</a>. Another thing to look at is <code>itertools</code> in Python <a href="http://www.python.org/download/releases/2.6/" rel="...
2
2010-03-03T19:15:01Z
[ "python", "bash" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,374,361
<p>While I don't know bash and don't see how <code>permutations</code> would solve your problem, it seems that <code>itertools.product</code> is a fairly straightforward way to do this:</p> <pre><code>&gt;&gt;&gt; s = 'atgc' &gt;&gt;&gt; d = dict(zip(s, 'tacg')) &gt;&gt;&gt; import itertools &gt;&gt;&gt; for i in iter...
2
2010-03-03T19:37:53Z
[ "python", "bash" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,374,490
<p>Unrelated to your actual question but related to what you're (apparently) doing, have you checked out <a href="http://biopython.org" rel="nofollow">BioPython</a>?</p>
0
2010-03-03T19:59:19Z
[ "python", "bash" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,374,509
<p>Here you go: </p> <pre><code>&gt;&gt;&gt; from itertools import product &gt;&gt;&gt; seq = ("AGCT",) * 10 &gt;&gt;&gt; STA = [''.join(a) for a in product(*seq)] &gt;&gt;&gt; STB = list(reversed(STA)) </code></pre> <p>Incidentally, <code>len(STA)</code> is 2<sup>20</sup>. </p> <p><code>itertools.product</code> is ...
1
2010-03-03T20:01:25Z
[ "python", "bash" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,374,837
<p>Others have said how to generate STA.</p> <p>The most efficient way to convert a string STA into the equivalent string STB is to use the string <a href="http://docs.python.org/library/stdtypes.html#str.translate" rel="nofollow">translate</a> &amp; <a href="http://docs.python.org/library/string.html#string.maketrans...
2
2010-03-03T20:49:50Z
[ "python", "bash" ]
What is the best, python or bash for generating strings from combinations of letters?
2,374,201
<p>I need to generate the strings STA and STB.</p> <p>STA and STB are strings of length 10, and each one can contain only the characters A,T,G or C.</p> <p>I have to generate all possible combinations of STA, and depending on STA, I generate STB.</p> <p>The ways is that the character A is always associated with T an...
1
2010-03-03T19:12:29Z
2,375,511
<p>bash baby :)<br><br></p> <pre><code>STA=$(echo {A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}{A,C,T,G}) STB=$(echo $STA | tr ATCG TAGC) echo $STA echo $STB </code></pre>
1
2010-03-03T22:30:06Z
[ "python", "bash" ]
Django - Working with multiple forms
2,374,224
<p>What I'm trying to do is to manage several forms in one page, I know there are formsets, and I know how the form management works, but I got some problems with the idea I have in mind.</p> <p>Just to help you to imagine what my problem is I'm going to use the django example models:</p> <pre><code>from django.db im...
21
2010-03-03T19:16:46Z
2,374,240
<p>Use the <code>prefix</code> kwarg</p> <p>You can declare your form as:</p> <pre><code>form = MyFormClass(prefix='some_prefix') </code></pre> <p>and then, as long as the prefix is the same, process data as:</p> <pre><code>form = MyFormClass(request.POST, prefix='some_prefix') </code></pre> <p>Django will handle ...
45
2010-03-03T19:19:38Z
[ "python", "django", "forms", "django-forms" ]
What are the possible pitfalls in porting Psyco to 64-bit?
2,374,233
<p>The Psyco docs say:</p> <blockquote> <p>Just for reference, Psyco does not work on any 64-bit systems at all. This fact is worth being noted again, now that the latest Mac OS/X 10.6 "Snow Leopart" comes with a default Python that is 64-bit on 64-bit machines. The only way to use Psyco on OS/X 10.6 i...
10
2010-03-03T19:18:08Z
2,374,371
<p>Since psyco is a compiler, it would need to be aware of the underlying assembly language to generate useful code. That would mean it would need to know about the 8 new registers, new opcodes for 64 bit code, etc. </p> <p>Furthermore, to interop with the existing code, it would need to use the same calling convent...
3
2010-03-03T19:39:07Z
[ "python", "c", "64bit", "porting", "psyco" ]
What are the possible pitfalls in porting Psyco to 64-bit?
2,374,233
<p>The Psyco docs say:</p> <blockquote> <p>Just for reference, Psyco does not work on any 64-bit systems at all. This fact is worth being noted again, now that the latest Mac OS/X 10.6 "Snow Leopart" comes with a default Python that is 64-bit on 64-bit machines. The only way to use Psyco on OS/X 10.6 i...
10
2010-03-03T19:18:08Z
2,374,407
<p>+1 for "... how hard could it be?". </p> <p>Take a look here: <a href="http://codespeak.net/svn/psyco/dist/c/i386/iprocessor.c" rel="nofollow">http://codespeak.net/svn/psyco/dist/c/i386/iprocessor.c</a></p> <p>All that ASM would have to be ported, and there are assumptions all over the place about the underlying p...
1
2010-03-03T19:43:59Z
[ "python", "c", "64bit", "porting", "psyco" ]
What are the possible pitfalls in porting Psyco to 64-bit?
2,374,233
<p>The Psyco docs say:</p> <blockquote> <p>Just for reference, Psyco does not work on any 64-bit systems at all. This fact is worth being noted again, now that the latest Mac OS/X 10.6 "Snow Leopart" comes with a default Python that is 64-bit on 64-bit machines. The only way to use Psyco on OS/X 10.6 i...
10
2010-03-03T19:18:08Z
2,374,449
<p>Christian Tismer, one of the Psyco developers also seems to disagree with the "how hard could it be" - assumption (quoted from <a href="http://www.reddit.com/r/programming/comments/7u95x/psyco_development_continued_by_christian_tismer/" rel="nofollow">here</a>):</p> <blockquote> <p>Needs to come to x86-64? Why th...
4
2010-03-03T19:51:02Z
[ "python", "c", "64bit", "porting", "psyco" ]
What are the possible pitfalls in porting Psyco to 64-bit?
2,374,233
<p>The Psyco docs say:</p> <blockquote> <p>Just for reference, Psyco does not work on any 64-bit systems at all. This fact is worth being noted again, now that the latest Mac OS/X 10.6 "Snow Leopart" comes with a default Python that is 64-bit on 64-bit machines. The only way to use Psyco on OS/X 10.6 i...
10
2010-03-03T19:18:08Z
3,738,027
<p>Psyco assumes that sizeof(int) == sizeof(void*) a bit all over the place. That's much harder than just writing down 64bit calling conventions and assembler. On the sidenote, pypy has 64bit jit support these days.</p> <p>Cheers, fijal</p>
3
2010-09-17T18:40:45Z
[ "python", "c", "64bit", "porting", "psyco" ]
Is it possible to get sqlalchemy to create a composite primary key with an integer part without making it an IDENTITY type?
2,374,243
<p>I'm using sqlalchemy 6.0. The SQL Server T-SQL dialect seems to want to make any integer that's part of my primary key into an identity. That may be ok if the integer field were the primary key, but mine is a composite and this isn't going to work for me. Is there a way to suppress this behavior?</p> <p>Here's a de...
7
2010-03-03T19:20:14Z
2,747,823
<p>I got bit by the same problem. The solution is to add autoincrement=False to the int primary key column constructor:</p> <pre><code>Column(u'int_part', Integer, primary_key=True, nullable=False, autoincrement=False) </code></pre> <p>Otherwise, sqlalchemy assumes it should make it an identity column.</p>
10
2010-04-30T21:31:55Z
[ "python", "sql-server", "sqlalchemy" ]
Python win32crypt.CryptProtectData difference between 2.5 and 3.1?
2,374,331
<p>I'm trying to hash a password to dump into a .rdp file. I found a site that (more or less) shows how to do that <a href="http://www.remkoweijnen.nl/blog/2007/11/05/encrypt-rdp-password-in-python/" rel="nofollow">here</a> but it doesn't work in 3.1.</p> <p>In 2.5.4 I get this:</p> <pre><code>&gt;&gt;&gt; import win...
2
2010-03-03T19:32:06Z
5,486,314
<p>Use "password".encode('utf-16-le') instead.</p>
1
2011-03-30T12:35:00Z
[ "python", "winapi", "python-3.x", "remote-desktop", "python-2.5" ]
Static Variables in Python C API
2,374,334
<p>How would one expose "static" variables like this</p> <pre><code>class MyClass: X = 1 Y = 2 </code></pre> <p>via the C API? The only variable on the PyTypeObject that looks like it would work is tp_members, but I see no flag in the PyMemberDef to indicate that the member should be per-class, not per-instan...
2
2010-03-03T19:32:38Z
2,376,055
<p>Just put them in the type's <a href="http://docs.python.org/c-api/typeobj.html#tp_dict">tp_dict</a> e.g. with <a href="http://docs.python.org/c-api/dict.html#PyDict_SetItemString">PyDict_SetItemString</a>.</p>
5
2010-03-04T00:19:07Z
[ "python", "python-c-api" ]
Python 2.x - Write binary output to stdout?
2,374,427
<p>Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. </p> <p>EDIT, <strong>Solution</strong>: From ChristopheD's link, below:</p> <pre><code>import sys if...
28
2010-03-03T19:47:41Z
2,374,443
<p>In Python 2.x, all strings are binary character arrays by default, so I believe you should be able to just</p> <pre><code>&gt;&gt;&gt; sys.stdout.write(data) </code></pre> <p>EDIT: I've confirmed your experience.</p> <p>I created one file, gen_bytes.py</p> <pre><code>import sys for char in range(256): sys.st...
6
2010-03-03T19:50:19Z
[ "python", "binary", "stdout" ]
Python 2.x - Write binary output to stdout?
2,374,427
<p>Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. </p> <p>EDIT, <strong>Solution</strong>: From ChristopheD's link, below:</p> <pre><code>import sys if...
28
2010-03-03T19:47:41Z
2,374,507
<p>Which platform are you on?</p> <p>You could try <a href="http://code.activestate.com/recipes/65443-sending-binary-data-to-stdout-under-windows/">this recipe</a> if you're on Windows (the link suggests it's Windows specific anyway).</p> <pre><code>if sys.platform == "win32": import os, msvcrt msvcrt.setmode...
22
2010-03-03T20:01:20Z
[ "python", "binary", "stdout" ]
Python 2.x - Write binary output to stdout?
2,374,427
<p>Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. </p> <p>EDIT, <strong>Solution</strong>: From ChristopheD's link, below:</p> <pre><code>import sys if...
28
2010-03-03T19:47:41Z
14,682,822
<p>You can use <a href="https://pypi.python.org/pypi/argopen" rel="nofollow">argopen</a>.argopen(), it handles dash as stdin/stdout, and fixes binary mode on Windows.</p> <pre><code>import argopen stdout = argopen.argopen('-', 'wb') stdout.write(some_binary_data) </code></pre>
5
2013-02-04T08:21:07Z
[ "python", "binary", "stdout" ]
Python 2.x - Write binary output to stdout?
2,374,427
<p>Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. </p> <p>EDIT, <strong>Solution</strong>: From ChristopheD's link, below:</p> <pre><code>import sys if...
28
2010-03-03T19:47:41Z
21,838,432
<p>You can use unbuffered mode: <code>python -u script.py</code>.</p> <pre> -u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode. </pre>
6
2014-02-17T20:12:57Z
[ "python", "binary", "stdout" ]
Python 2.x - Write binary output to stdout?
2,374,427
<p>Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. </p> <p>EDIT, <strong>Solution</strong>: From ChristopheD's link, below:</p> <pre><code>import sys if...
28
2010-03-03T19:47:41Z
27,150,524
<p>I solved this using a wrapper for a file-descriptor. (Tested in Python 3.2.5 on Cygwin)</p> <pre><code>class BinaryFile(object): ''' Wraps a file-descriptor to binary read/write. The wrapped file can not be closed by an instance of this class, it must happen through the original file. :param fd: A ...
0
2014-11-26T13:30:16Z
[ "python", "binary", "stdout" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
2,374,662
<p>You might be interested in the <a href="http://docs.scipy.org/doc/scipy/reference/stats.html">SciPy Stats</a> package. It has <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.scoreatpercentile.html#scipy.stats.scoreatpercentile">the percentile function</a> you're after and many other statisti...
116
2010-03-03T20:24:34Z
[ "python", "numpy", "percentile" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
2,753,343
<p>By the way, there is <a href="http://code.activestate.com/recipes/511478-finding-the-percentile-of-the-values/">a pure-Python implementation of percentile function</a>, in case one doesn't want to depend on scipy. The function is copied below:</p> <pre><code>## {{{ http://code.activestate.com/recipes/511478/ (r1) ...
44
2010-05-02T11:46:20Z
[ "python", "numpy", "percentile" ]