title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
892,274
<p>If it look like truly random behavior than it could be a multi-cpu/core issue. You could try to set the interpreter affinity to a fixed cpu and see if this issue still comes up.</p> <p>Google for something like: imagecfg process affinity For more information about that.</p>
0
2009-05-21T10:34:45Z
[ "python", "python-3.x", "python-idle" ]
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
980,926
<p>Or..you could forget IDLE and try <a href="http://ipython.org/" rel="nofollow">IPython</a> instead. It may not exhibit the same error at all. I've never had a problem with it. You get some cool functionality with it that IDLE doesn't have. I find it very useful when working with Python.</p>
0
2009-06-11T13:00:26Z
[ "python", "python-3.x", "python-idle" ]
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
7,840,915
<p>Simple. Just cut all files with .py extension, paste them in a place different from the os path, one of the files is causing such error. Run the IDLE again.</p>
1
2011-10-20T19:06:07Z
[ "python", "python-3.x", "python-idle" ]
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
9,645,737
<p>I was getting the same error message. What was causing the problem for me was that I named one of my scripts 'string.py'. Every time I tried to run a script with 'string.py' in the same directory this happened.</p>
5
2012-03-10T10:37:44Z
[ "python", "python-3.x", "python-idle" ]
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
11,510,272
<p>I had this same problem in 2.7.3. I found that when I was learning how to use tkinter and I made a basic program to open a window, I named it Tkinter.py and put it in the same folder as the program I was trying to run with IDLE. It would always compile the program called Tkinter and make a second compiled file. When...
2
2012-07-16T18:26:18Z
[ "python", "python-3.x", "python-idle" ]
Python IDLE subprocess error?
874,757
<blockquote> <p>IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.</p> </blockquote> <p>Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager &...
9
2009-05-17T14:42:48Z
24,290,513
<p>i had the same error. I did a modem reboot and to my surprise, it worked !</p>
0
2014-06-18T16:18:04Z
[ "python", "python-3.x", "python-idle" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
874,865
<p>stdout will be buffered - so you won't get anything till that buffer is filled, or the subprocess exits.</p> <p>You can try flushing <code>stdout</code> from the sub-process, or using stderr, or changing stdout on non-buffered mode.</p>
6
2009-05-17T15:51:49Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
874,868
<p>It sounds like the issue might be the use of buffered output by the subprocess - if a relatively small amount of output is created, it could be buffered until the subprocess exits. Some background can be found <a href="http://www.pixelbeat.org/programming/stdio%5Fbuffering/" rel="nofollow">here</a>:</p>
2
2009-05-17T15:53:38Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
875,281
<p>Update with code that appears not to work (on windows anyway)</p> <pre><code>class ThreadWorker(threading.Thread): def __init__(self, callable, *args, **kwargs): super(ThreadWorker, self).__init__() self.callable = callable self.args = args self.kwargs = kwargs self.setDa...
8
2009-05-17T19:16:53Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
1,456,182
<p>I've used the pexpect module for this, it seems to work ok. <a href="http://sourceforge.net/projects/pexpect/" rel="nofollow">http://sourceforge.net/projects/pexpect/</a></p>
0
2009-09-21T18:51:59Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
1,945,380
<p>Here's what worked for me:</p> <pre><code>cmd = ["./tester_script.bash"] p = subprocess.Popen( cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) while p.poll() is None: out = p.stdout.readline() do_something_with( out, err ) </code></pre> <p>In your case you could try to pass a reference t...
2
2009-12-22T10:06:00Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
2,328,115
<p>I've been running into this problem as well. The problem occurs because you are trying to read stderr as well. If there are no errors, then trying to read from stderr would block. </p> <p>On Windows, there is no easy way to poll() file descriptors (only Winsock sockets).</p> <p>So a solution is not to try and read...
1
2010-02-24T17:37:13Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
2,858,790
<p>Using pexpect [http://www.noah.org/wiki/Pexpect] with non-blocking readlines will resolve this problem. It stems from the fact that pipes are buffered, and so your app's output is getting buffered by the pipe, therefore you can't get to that output until the buffer fills or the process dies.</p>
1
2010-05-18T15:42:43Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
15,699,282
<p>This seems to be a well-known Python limitation, see <a href="http://www.python.org/dev/peps/pep-3145/" rel="nofollow" title="PEP 3145">PEP 3145</a> and maybe others.</p>
1
2013-03-29T07:39:02Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
24,346,632
<p>Read one character at a time: <a href="http://blog.thelinuxkid.com/2013/06/get-python-subprocess-output-without.html" rel="nofollow">http://blog.thelinuxkid.com/2013/06/get-python-subprocess-output-without.html</a></p> <pre><code>import contextlib import subprocess # Unix, Windows and old Macintosh end-of-line new...
1
2014-06-21T23:02:35Z
[ "python", "subprocess", "stdout", "popen" ]
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
874,815
<p>I'd like to use the subprocess module in the following way:</p> <ol> <li>create a new process that potentially takes a long time to execute. </li> <li>capture <code>stdout</code> (or <code>stderr</code>, or potentially both, either together or separately) </li> <li>Process data from the subprocess <strong>as it co...
41
2009-05-17T15:20:29Z
38,775,458
<p>Using subprocess.Popen, I can run the .exe of one of my C# projects and redirect the output to my Python file. I am able now to <code>print()</code> all the information being output to the C# console (using <code>Console.WriteLine()</code>) to the Python console.</p> <p>Python code:</p> <pre><code>from subprocess ...
0
2016-08-04T19:05:36Z
[ "python", "subprocess", "stdout", "popen" ]
wxPython launches my app twice when importing a sub-package
874,856
<p>I'm sorry for the verbal description.</p> <p>I have a wxPython app in a file called <code>applicationwindow.py</code> that resides in a package called <code>garlicsimwx</code>. When I launch the app by launching the aforementioned file, it all works well. However, I have created a file <code>rundemo.py</code> in a ...
0
2009-05-17T15:45:07Z
874,879
<p>I think you have code in one of your modules that looks like this:</p> <pre><code>import wx class MyFrame(wx.Frame): def __init__(...): ... frame = MyFrame(...) </code></pre> <p>The frame will be created when this module is first imported. To prevent that, use the common Python idiom:</p> <pre><code>...
4
2009-05-17T16:05:06Z
[ "python", "import", "wxpython" ]
wxPython launches my app twice when importing a sub-package
874,856
<p>I'm sorry for the verbal description.</p> <p>I have a wxPython app in a file called <code>applicationwindow.py</code> that resides in a package called <code>garlicsimwx</code>. When I launch the app by launching the aforementioned file, it all works well. However, I have created a file <code>rundemo.py</code> in a ...
0
2009-05-17T15:45:07Z
875,039
<p>You could create a global boolean variable like <code>g_window_was_drawn</code> and check it in the function that does the work of creating a window. The value would be false at the start of the program and would change to True when first creating a window. The function that creates the window would check if the <co...
0
2009-05-17T17:26:59Z
[ "python", "import", "wxpython" ]
wxPython launches my app twice when importing a sub-package
874,856
<p>I'm sorry for the verbal description.</p> <p>I have a wxPython app in a file called <code>applicationwindow.py</code> that resides in a package called <code>garlicsimwx</code>. When I launch the app by launching the aforementioned file, it all works well. However, I have created a file <code>rundemo.py</code> in a ...
0
2009-05-17T15:45:07Z
875,059
<p>Got it: There was no</p> <pre><code>if __name__=='__main__': </code></pre> <p>in my <code>rundemo</code> file. It was actually a <code>multiprocessing</code> issue: The new window was opened in a separate process.</p>
0
2009-05-17T17:36:17Z
[ "python", "import", "wxpython" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
878,313
<p>In order not to give too much away, I'd suggest two things:</p> <ol> <li><p>Analyze the sequence of numbers you've produced though brute-force: they all share a common characteristic. If you find what it is, you may then have a shot at brute forcing your way to a solution.</p></li> <li><p>Find a more sophisticated ...
1
2009-05-18T15:29:11Z
[ "python", "algorithm", "math" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
881,439
<p>Multiply primes. What I did, is first check every 2-prime product; store the ones that are successes. Then using the stored products, check those with more primes (every 3-prime product shown in your brute force has a 2-prime subset that works). Use these stored products, and try again with 4 primes, 5 primes etc...
3
2009-05-19T07:44:41Z
[ "python", "algorithm", "math" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
911,612
<p>Project Euler isn't fond of discussing problems on public forums like StackOverflow. All tasks are made to be done solo, if you encounter problems you may ask help for a specific mathematical or programming concept, but you can't just decide to ask how to solve the problem at hand - takes away the point of project E...
9
2009-05-26T16:37:17Z
[ "python", "algorithm", "math" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
914,300
<p>Let me continue what jug started, but try a somewhat different approach. The goal again is to just find the numbers that have two distinct factors n=pq. As you already pointed out we are looking for the numbers such that n-phi(n) divides n-1. I.e., if n=pq then that means we are looking for p,q such that</p> <pre><...
5
2009-05-27T06:44:33Z
[ "python", "algorithm", "math" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
914,340
<p>I haven't found a full solution, but I would like to share my thoughts. Perhaps someone could help.</p> <p>I believe that one should try to reduce the problem to</p> <p><img src="http://www.texify.com/img/%5CLARGE%5C%21O%28%5Csqrt%7Bn%7D%29.gif" alt="O(sqrt(n)" /></p> <p>complexity.The following facts can be used...
0
2009-05-27T07:01:08Z
[ "python", "algorithm", "math" ]
Project Euler Problem 245
875,027
<p>I'm onto <a href="http://projecteuler.net/index.php?section=problems&amp;id=245" rel="nofollow">problem 245</a> now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:</p> <p>We need to find n=ab with a and b positive...
7
2009-05-17T17:20:00Z
916,466
<p>no direct help for this problem, but maybe interesting for future math projects: instead of using WolframAlpha to analyze the sequence, I'd recommend <a href="http://www.research.att.com/~njas/sequences/" rel="nofollow">"The On-Line Encyclopedia of Integer Sequences"</a> on research.att.com.</p> <p>Have fun solving...
1
2009-05-27T15:38:37Z
[ "python", "algorithm", "math" ]
Receiving 16-bit integers in Python
875,046
<p>I'm reading 16-bit integers from a piece of hardware over the serial port.</p> <p>Using Python, how can I get the LSB and MSB right, and make Python understand that it is a 16 bit signed integer I'm fiddling with, and not just two bytes of data?</p>
8
2009-05-17T17:31:50Z
875,062
<p>Try using the <a href="http://docs.python.org/library/struct.html">struct</a> module:</p> <pre><code>import struct # read 2 bytes from hardware as a string s = hardware.readbytes(2) # h means signed short # &lt; means "little-endian, standard size (16 bit)" # &gt; means "big-endian, standard size (16 bit)" value = ...
19
2009-05-17T17:36:48Z
[ "python", "integer" ]
How to print a list, dict or collection of objects, in Python
875,074
<p>I have written a class in python that implements <code>__str__(self)</code> but when I use print on a list containing instances of this class, I just get the default output <code>&lt;__main__.DSequence instance at 0x4b8c10&gt;</code>. Is there another magic function I need to implement to get this to work, or do I h...
17
2009-05-17T17:41:03Z
875,077
<p>Yes, you need to use <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Frepr%5F%5F"><code>__repr__</code></a>. A quick example of its behavior:</p> <pre><code>&gt;&gt;&gt; class Foo: ... def __str__(self): ... return '__str__' ... def __repr__(self): ... return '__...
21
2009-05-17T17:42:22Z
[ "python", "list" ]
How to print a list, dict or collection of objects, in Python
875,074
<p>I have written a class in python that implements <code>__str__(self)</code> but when I use print on a list containing instances of this class, I just get the default output <code>&lt;__main__.DSequence instance at 0x4b8c10&gt;</code>. Is there another magic function I need to implement to get this to work, or do I h...
17
2009-05-17T17:41:03Z
875,197
<p>Just a little enhancement avoiding the + for concatenating:</p> <pre><code>def __str__(self): return '[%s] -&gt; [%s]' % (self.sid, self.seq) </code></pre>
1
2009-05-17T18:48:02Z
[ "python", "list" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,128
<p>Navigating through a binary search tree requires state (in which node I am?) and comparisons (is that value less or greater than that?), things that cannot be done by a finite state automaton.</p> <p>Sure, you can search for the node with a given value, but how then you could, for example, remove a node that isn't ...
1
2009-05-17T18:13:22Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,131
<p>I don't know a general purpose langugae that can do that, but it seems to me that you are looking for something like <a href="http://en.wikipedia.org/wiki/XPath">XPath</a>.</p>
5
2009-05-17T18:17:02Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,133
<p>There is <a href="http://www.txl.ca/" rel="nofollow">TXL</a> for pattern based tree rewriting.</p> <p>Tree rewriting with patterns is also done with parser toolkits such as <a href="http://www.antlr.org/wiki/display/~admin/2008/11/30/Example%2Btree%2Brewriting%2Bwith%2Bpatterns" rel="nofollow">ANTLR</a></p> <p>Cod...
4
2009-05-17T18:17:31Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,137
<p><a href="http://www.perl.com/pub/a/2003/06/06/regexps.html" rel="nofollow">This</a> article gives some tasty hints about recursive Perl regular expressions, but honestly it's rare to see a tree structure approached this way.</p> <p>More typically, one would write a state machine style parser, that might use regexes...
1
2009-05-17T18:17:55Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,168
<p>Pattern Matching, provided by languages such as Scala, F#, Erlang and Haskell (I'm sure there's more) is designed to succinctly manipulate data structures like trees, esp when used with recursion. </p> <p><a href="http://www.scala-lang.org/node/120" rel="nofollow">here</a> is a very high level view of what pattren ...
1
2009-05-17T18:33:12Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
875,462
<p>I'm somewhat surprised that <a href="http://www.w3schools.com/xsl/" rel="nofollow">XSLT</a> hasn't come up as an answer. Granted, I don't think it's a particularly elegant language, and most existent solutions tend to favour procedural approaches rather than pattern matching, and it's gotten a mighty bad rep from be...
1
2009-05-17T20:51:00Z
[ "java", "python", "c", "regex", "tree-structure" ]
Regex for tree structures?
875,100
<p>Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for.</p> <p>Here is an example that might clarify what I am looking for.</p> <pre><code>&lt;root&gt; &lt;node name="1"&gt; subtrees .... &lt;/node&gt; &lt;n...
6
2009-05-17T17:57:26Z
6,082,100
<p>TSurgeon and Tregex from Stanford is capable of doing that. You can download the library from <a href="http://nlp.stanford.edu/software/tregex.shtml">http://nlp.stanford.edu/software/tregex.shtml</a></p>
6
2011-05-21T13:40:55Z
[ "java", "python", "c", "regex", "tree-structure" ]
Zlib in database - Django
875,122
<p>When I try to put a zlibbed string in models.TextField</p> <pre><code>&gt;&gt;&gt; f = VCFile(head = 'blahblah'.encode('zlib')) &gt;&gt;&gt; f.save() </code></pre> <p>it fails:</p> <pre><code> ... raise DjangoUnicodeDecodeError(s, *e.args) DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x9c in positi...
1
2009-05-17T18:10:58Z
875,153
<p>If you don't want to encode it, you have to store it as a binary object (BLOB), not a string. Django doesn't seem to support BlobFields out of the box, so go find it on the net or hack something together.</p>
0
2009-05-17T18:24:58Z
[ "python", "database", "django", "django-models", "zlib" ]
Zlib in database - Django
875,122
<p>When I try to put a zlibbed string in models.TextField</p> <pre><code>&gt;&gt;&gt; f = VCFile(head = 'blahblah'.encode('zlib')) &gt;&gt;&gt; f.save() </code></pre> <p>it fails:</p> <pre><code> ... raise DjangoUnicodeDecodeError(s, *e.args) DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x9c in positi...
1
2009-05-17T18:10:58Z
878,719
<p>Like Marcus says, you'll have to use BLOB if you want to keep it in binary format. If you're OK with encoding it, you can use base64 encoding:</p> <pre><code>from base64 import binascii f = VCFile(head = binascii.b2a_base64('blahblah'.encode('zlib'))) </code></pre> <p>In my very basic tests with 33k characters, t...
1
2009-05-18T16:59:28Z
[ "python", "database", "django", "django-models", "zlib" ]
Daemon python wrapper "subprocess I/O timed out", need some directions
875,190
<p>I am not very familiar with the way of creating a daemon in Python, therefore wheb trying to install and run a third party open source TeX Python Wrapper i got bite by an error i do nor really understand.</p> <p>I added some print to help debugging.</p> <p>The faulty one is called texdp.py</p> <p>When i run mathr...
1
2009-05-17T18:43:17Z
875,827
<p>The timeout is based on the <code>select</code> call </p> <pre><code>readable, writable = select(output_fds, input_fds, [], 0.1)[0:2] </code></pre> <p>The timeout is 0.1 seconds. Is this appropriate? </p> <p>The variable names are murky ("pointer" makes little sense in Python). However, it appears that if noth...
2
2009-05-18T00:27:11Z
[ "python", "daemon", "tex" ]
Simple data storing in Python
875,228
<p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> <p>I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get i...
3
2009-05-17T19:00:20Z
875,272
<p><a href="http://docs.python.org/library/pickle.html" rel="nofollow">http://docs.python.org/library/pickle.html</a></p>
6
2009-05-17T19:13:10Z
[ "python", "file-io", "csv", "multidimensional-array", "fileparsing" ]
Simple data storing in Python
875,228
<p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> <p>I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get i...
3
2009-05-17T19:00:20Z
875,280
<p>Must the file be human readable? If not, <a href="http://docs.python.org/library/shelve.html" rel="nofollow">shelve</a> is really easy to use.</p>
4
2009-05-17T19:15:45Z
[ "python", "file-io", "csv", "multidimensional-array", "fileparsing" ]
Simple data storing in Python
875,228
<p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> <p>I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get i...
3
2009-05-17T19:00:20Z
875,347
<p>In addition to <code>pickle</code> (<a href="http://stackoverflow.com/questions/875228/simple-data-storing-in-python/875272#875272">mentioned above</a>), there's <a href="http://docs.python.org/library/json.html" rel="nofollow"><code>json</code></a> (built in to 2.6, available via <a href="http://pypi.python.org/pyp...
10
2009-05-17T19:51:09Z
[ "python", "file-io", "csv", "multidimensional-array", "fileparsing" ]
Simple data storing in Python
875,228
<p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> <p>I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get i...
3
2009-05-17T19:00:20Z
875,525
<blockquote> <p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> </blockquote> <p>Is the data only ever going to be parsed by Python programs? If not, then I'd avoid pickle et al (shelve and marshal)...
2
2009-05-17T21:16:12Z
[ "python", "file-io", "csv", "multidimensional-array", "fileparsing" ]
Simple data storing in Python
875,228
<p>I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.</p> <p>I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get i...
3
2009-05-17T19:00:20Z
1,416,925
<p>This solution at SourceForge uses only standard Python modules:</p> <p>y_serial.py module :: warehouse Python objects with SQLite</p> <p>"Serialization + persistance :: in a few lines of code, compress and annotate Python objects into SQLite; then later retrieve them chronologically by keywords without any SQL. Mo...
1
2009-09-13T05:29:56Z
[ "python", "file-io", "csv", "multidimensional-array", "fileparsing" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,342
<pre><code>map(lambda item: item.my_func(), items) </code></pre>
-3
2009-05-17T19:48:14Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,344
<p>You could use <a href="http://docs.python.org/3.0/library/functions.html#map"><code>map</code></a> instead of the <code>for</code> loop you've shown, but since you do not appear to use the result of <code>item.my_func()</code>, this is <strong>not recommended</strong>. <code>map</code> should be used if you want to ...
23
2009-05-17T19:49:16Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,353
<p>The main advantage of <code>map</code> is when you want to get the result of some calculation on every element in a list. For example, this snippet doubles every value in a list:</p> <pre><code>map(lambda x: x * 2, [1,2,3,4]) #=&gt; [2, 4, 6, 8] </code></pre> <p>It is important to note that <code>map</code> retur...
1
2009-05-17T19:53:35Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,369
<p>You can write this using map like this:</p> <pre><code>map(cls.my_func, items) </code></pre> <p>replacing cls with the class of the items you are iterating over.</p> <p>As mentioned by Stephan202, this is <strong>not recommended</strong> in this case.</p> <p>As a rule, if you want to create a new list by applyin...
5
2009-05-17T20:00:38Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,406
<p>There is a slight semantic difference, which is probably closed in python language spec. The <em>map</em> is explicitly parallelizable, while <em>for</em> only in special situations. Code can <em>break</em> out from <em>for</em>, but only escape with exception from <em>map</em>.</p> <p>In my opinion <em>map</em> sh...
2
2009-05-17T20:18:55Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
875,581
<p>You can switch Your <code>map</code> to some cool threaded OR multiprocessing OR distributed computing framework if You need to. <a href="http://discoproject.org/" rel="nofollow">Disco</a> is an example of distributed, resistant to failures erlang-and-python based framework. I configured it on 2 boxes of 8 cores and...
2
2009-05-17T21:53:43Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
877,606
<p>Use an explicit for-loop when you don't need a list of results back (eg. functions with side-effects).</p> <p>Use a list comprehension when you do need a list of results back (eg. functions that return a value based directly on the input).</p> <p>Use map() when you're trying to convince Lisp users that Python is w...
2
2009-05-18T12:57:04Z
[ "python", "for-loop", "map-function" ]
Is there a value in using map() vs for?
875,337
<p>Does map() iterate through the list like "for" would? Is there a value in using map vs for?</p> <p>If so, right now my code looks like this:</p> <pre><code>for item in items: item.my_func() </code></pre> <p>If it makes sense, I would like to make it map(). Is that possible? What is an example like?</p>
10
2009-05-17T19:45:43Z
880,046
<p>Map can sometimes be faster for built-in functions than manually coding a for loop. Try timing map(str, range(1000000)) vs. a similar for loop.</p>
0
2009-05-18T22:02:03Z
[ "python", "for-loop", "map-function" ]
Printing Daemonic Thread Exceptions in Python
875,453
<p>Python does not print traceback messages from exceptions raised in daemon threads.</p> <p>For example, this code creates a daemonic thread and raises an exception in the new thread:</p> <pre><code>def error_raiser(): raise Exception import threading thread = threading.Thread(target=error_raiser) thread.daemon...
7
2009-05-17T20:45:28Z
875,485
<p>According to Wikipedia, by definition a daemon should detach itself from the controlling tty, so I think it's correct that no exception is shown (and after all, a daemon should keep working even if you close the shell that launched it)..<br /> See <a href="http://en.wikipedia.org/wiki/Daemon%5F%28computer%5Fsoftware...
6
2009-05-17T20:56:46Z
[ "python", "multithreading" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
875,502
<p>I have no experience with this, but have a look at the <a href="http://docs.python.org/library/wave.html" rel="nofollow">wave</a> module present in the standard library. That may do what you want. Otherwise you'll have to read the file as a byte stream an cut out sequences of 0-bytes (but you cannot just cut out all...
1
2009-05-17T21:00:43Z
[ "python", "audio" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
875,571
<p>You might want to try using <a href="http://linux.die.net/man/1/sox" rel="nofollow">sox</a>, a command-line sound processing tool. It has many modes, one of them is <code>silence</code>:</p> <blockquote> <p>silence: Removes silence from the beginning, middle, or end of a sound file. Silence is anything below a sp...
1
2009-05-17T21:46:24Z
[ "python", "audio" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
875,775
<p>Python has a <a href="http://docs.python.org/library/wave.html">wav module</a>. You can use it to open a wav file for reading and use the `getframes(1)' command to walk through the file frame by frame.</p> <pre><code>import wave w = wave.open('beeps.wav', 'r') for i in range(): frame = w.readframes(1) </code></pre...
14
2009-05-17T23:50:00Z
[ "python", "audio" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
877,551
<p>You will need to come up with some threshold value of a minimum number of consecutive zeros before you cut them. Otherwise you'll be removing perfectly valid zeros from the middle of normal audio data. You can iterate through the wave file, copying any non-zero values, and buffering up zero values. When you're buffe...
1
2009-05-18T12:44:19Z
[ "python", "audio" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
878,275
<p>See also <a href="http://stackoverflow.com/questions/841049/how-to-edit-raw-pcm-audio-data-without-an-audio-library">How to edit raw PCM audio data without an audio library?</a></p>
2
2009-05-18T15:19:45Z
[ "python", "audio" ]
editing a wav files using python
875,476
<p>and between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's)</p> <p>how can I cut the non-silence sound ?</p> <p>I'm programming using python</p> <p>thanks</p>
3
2009-05-17T20:54:38Z
25,130,170
<p>I have been doing some research on this topic for a project I'm working on and I came across a few problems with the solution provided, namely the method for determining silence is incorrect. A "more correct" implementation would be:</p> <pre><code>import struct import wave wave_file = wave.open("sound_file.wav", ...
2
2014-08-05T02:05:33Z
[ "python", "audio" ]
How can I color certain things in Emacs?
875,543
<p>I program Django/Python in emacs, and I would like things like {% comment %} FOO {% endcomment %} to turn orange.</p> <p>How can I set up some colors for important Django template tags?</p>
4
2009-05-17T21:26:58Z
875,549
<p><a href="http://code.djangoproject.com/wiki/Emacs" rel="nofollow">Here</a> <a href="http://www.chickenwingsoftware.com/scratches/python/how-i-edit-django-templates" rel="nofollow">are</a> <a href="http://www.chickenwingsoftware.com/scratches/python/more-on-editing-django-templates-in-xemacs" rel="nofollow">some</a> ...
1
2009-05-17T21:32:18Z
[ "python", "django", "emacs", "syntax-highlighting" ]
How can I color certain things in Emacs?
875,543
<p>I program Django/Python in emacs, and I would like things like {% comment %} FOO {% endcomment %} to turn orange.</p> <p>How can I set up some colors for important Django template tags?</p>
4
2009-05-17T21:26:58Z
875,628
<p>You could use dedicated modes like <a href="http://code.djangoproject.com/wiki/Emacs">django-mode</a> or <a href="http://www.emacswiki.org/emacs/MuMaMo">MuMaMo</a>.</p> <p>If you want something very basic, and assuming you're editing in <code>html-mode</code>, you could try the following:</p> <pre><code>(defun dja...
6
2009-05-17T22:17:10Z
[ "python", "django", "emacs", "syntax-highlighting" ]
How can I color certain things in Emacs?
875,543
<p>I program Django/Python in emacs, and I would like things like {% comment %} FOO {% endcomment %} to turn orange.</p> <p>How can I set up some colors for important Django template tags?</p>
4
2009-05-17T21:26:58Z
880,114
<p>Here's what I do. It's a little more general than the code above, and it uses the built-in font-lock mechanisms.</p> <pre><code>(defvar django-tag-face (make-face 'django-tag-face)) (defvar django-variable-face (make-face 'django-variable-face)) (set-face-background 'django-tag-face "Aquamarine") (set-face-foregrou...
3
2009-05-18T22:23:11Z
[ "python", "django", "emacs", "syntax-highlighting" ]
PersistentSet in ZODB 3
875,607
<p>ZODB provides a <code>PersistentList</code> and a <code>PersistentMapping</code>, but I'd like a <code>PersistentSet</code>. I wrote a quick class that mirrors the ancient <a href="http://sysinf0.klabs.be/usr/share/zope2.7/lib/python/ZODB/PersistentList.py?f=view" rel="nofollow"><code>PersistentList</code></a> from...
3
2009-05-17T22:07:09Z
876,415
<p>Forward all attribute requests to the internal set:</p> <pre><code>class PersistentSet(Persistent): def __init__(self): self.inner_set = set() def __getattribute__(self, name): try: inner_set = Persistent.__getattribute__(self, "inner_set") output = getattr(inner_set...
1
2009-05-18T05:51:30Z
[ "python", "set", "zodb" ]
PersistentSet in ZODB 3
875,607
<p>ZODB provides a <code>PersistentList</code> and a <code>PersistentMapping</code>, but I'd like a <code>PersistentSet</code>. I wrote a quick class that mirrors the ancient <a href="http://sysinf0.klabs.be/usr/share/zope2.7/lib/python/ZODB/PersistentList.py?f=view" rel="nofollow"><code>PersistentList</code></a> from...
3
2009-05-17T22:07:09Z
1,717,187
<p>Why don't you use the persistent set class provided with the <a href="http://www.zodb.org/documentation/guide/modules.html#btrees-package" rel="nofollow">BTree</a> libraries in ZODB. There are 4 such classes available. IITreeSet and IOTreeSet manage sets of integers and OITreeSet and OOTreeSet manage set of arbitrar...
3
2009-11-11T18:30:34Z
[ "python", "set", "zodb" ]
PersistentSet in ZODB 3
875,607
<p>ZODB provides a <code>PersistentList</code> and a <code>PersistentMapping</code>, but I'd like a <code>PersistentSet</code>. I wrote a quick class that mirrors the ancient <a href="http://sysinf0.klabs.be/usr/share/zope2.7/lib/python/ZODB/PersistentList.py?f=view" rel="nofollow"><code>PersistentList</code></a> from...
3
2009-05-17T22:07:09Z
27,656,955
<p>For future readings, I just wanted to offer a slight improvement over the already proposed answers...</p> <p><strong>Custom persistent set class</strong></p> <pre><code>class PersistentSet(Persistent): def __init__(self, *args, **kwargs): self._set = set(*args, **kwargs) def __getattr__(self, nam...
0
2014-12-26T12:12:25Z
[ "python", "set", "zodb" ]
python-fastcgi extension
875,713
<p>There's not much documentation surrounding the <a href="http://pypi.python.org/pypi/python-fastcgi" rel="nofollow">python-fastcgi</a> C library, so I'm wondering if someone could provide a simple example on how to make a simple FastCGI server with it. A "Hello World" example would be great.</p>
3
2009-05-17T23:13:29Z
876,116
<p><strong>Edit:</strong> I misread the question. Ooops.</p> <p><a href="http://jonpy.sourceforge.net/" rel="nofollow">Jon's Python modules</a> is a collection of useful modules and includes a great FastCGI module: <a href="http://jonpy.sourceforge.net/fcgi.html" rel="nofollow">http://jonpy.sourceforge.net/fcgi.html</...
4
2009-05-18T03:20:07Z
[ "python", "fastcgi" ]
python-fastcgi extension
875,713
<p>There's not much documentation surrounding the <a href="http://pypi.python.org/pypi/python-fastcgi" rel="nofollow">python-fastcgi</a> C library, so I'm wondering if someone could provide a simple example on how to make a simple FastCGI server with it. A "Hello World" example would be great.</p>
3
2009-05-17T23:13:29Z
878,118
<p>I would recommend using a fastcgi WSGI wrapper such as <a href="http://svn.saddi.com/py-lib/trunk/fcgi.py" rel="nofollow">this one</a>, so you aren't tied in to the fastcgi approach from the start.</p> <p>And then a simple test.fgi file like such:</p> <pre><code>#!/usr/bin/env python from fcgi import WSGIServer ...
3
2009-05-18T14:45:40Z
[ "python", "fastcgi" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,777
<p>One way of doing the encode/decode is to use the package base64, for an example:</p> <pre><code>import base64 import sys encoded = base64.b64encode(sys.stdin.read()) print encoded decoded = base64.b64decode(encoded) print decoded </code></pre> <p>Is it what you were looking for? With your particular case you get...
9
2009-05-17T23:51:22Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,782
<p>The base64 module provides encoding and decoding for a string to and from different bases, since python 2.4.</p> <p>In you example, you would do the following:</p> <pre><code>import base64 string_b = base64.b64encode(string_a) string_a = base64.b64decode(string_b) </code></pre> <p>For full API: <a href="http://do...
2
2009-05-17T23:54:06Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,783
<p>Are you looking to encrypt the string or encode it to remove illegal characters for urls? If the latter, you can use <a href="http://docs.python.org/library/urllib.html#quote" rel="nofollow"><code>urllib.quote</code></a>:</p> <pre><code>&gt;&gt;&gt; quoted = urllib.quote("12234_1_Hello'World_34433_22acb_4554344_acc...
4
2009-05-17T23:54:47Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,785
<p>Are you after encryption, compression, or just urlencoding? The string can be passed after urlencoding, but that will not make it smaller as in your example. Compression might shrink it, but you would still need to urlencode the result.</p> <p>Do you actually need to hide the string data from the viewer (e.g. sen...
5
2009-05-17T23:56:46Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,844
<p>To make it really short -> just insert a row into the database. Store something like a list of <code>(id auto_increment, url)</code> tuples. Then you can <code>base64</code> encode the id to get a "proxy url". Decode it by decoding the id and looking up the proper url in the database. Or if you don't mind the identi...
5
2009-05-18T00:41:19Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
875,847
<p>It's hard to reduce the size of a string and preserve arbitrary content.</p> <p>You have to restrict the data to something you can usefully compress.</p> <p>Your alternative is to do the following.</p> <ol> <li><p>Save "all the arguments in the URL" in a database row.</p></li> <li><p>Assign a GUID key to this col...
2
2009-05-18T00:43:06Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
876,161
<p>Another method that would also shorten the string would be to calculate the md5/sha1 hash of the string (concatenated with a seed if you wished):</p> <pre><code>import hashlib &gt;&gt;&gt; hashlib.sha1("12234_1_Hello'World_34433_22acb_4554344_accCC44").hexdigest() 'e1153227558aadc00a2e90b5013fdd6b0804fdfb' </code><...
1
2009-05-18T03:36:04Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
How does one encode and decode a string with Python for use in a URL?
875,771
<p>I have a string like this: </p> <pre><code>String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] </code></pre> <p>I would like to encrypt String A to be used in a clean URL. something like this:</p> <pre><code>String B: [ cYdfkeYss4543423sdfHsaaZ ] </code></pre> <p>Is there a encode API in python, given ...
4
2009-05-17T23:45:12Z
1,184,226
<p>note that theres a huge difference between encoding and encryption.</p> <p>if you want to send sensitive data, then dont use the encoding mentioned above ;)</p>
9
2009-07-26T10:27:29Z
[ "python", "string", "hash", "urlencode", "clean-urls" ]
PyQt: splash screen while loading "heavy" libraries
876,107
<p>My PyQt application that uses <code>matplotlib</code> takes several seconds to load for the first time, even on a fast machine (the second load time is much shorter as the DLLs are kept in memory by Windows).</p> <p>I'm wondering whether it's feasible to show a splash screen while the <code>matplotlib</code> librar...
2
2009-05-18T03:15:35Z
876,151
<p>Yes, loading the module takes place at the line where the import statement is. If you create your <code>QApplication</code> and show your splash screen before that, you should be able to do what you want -- also you need to call <code>QApplication.processEvents()</code> whenever you need the splash screen to update...
2
2009-05-18T03:33:49Z
[ "python", "performance", "matplotlib", "pyqt" ]
is there any AES encryption python library that will work well with python 3.0?
876,258
<p>I want to know is there any python 3.0 supported library for encryption. To encrypt files of 128 bits of data??</p>
0
2009-05-18T04:34:12Z
876,284
<p>I suggest my open-source project <code>slowaes</code>, <a href="http://code.google.com/p/slowaes/" rel="nofollow">http://code.google.com/p/slowaes/</a> -- should be trivial to adapt if it doesn't work out of the box, as it's pure-Python (and for 128 bits of data, the "slow" part shouldn't matter).</p>
3
2009-05-18T04:49:10Z
[ "python", "encryption", "aes" ]
is there any AES encryption python library that will work well with python 3.0?
876,258
<p>I want to know is there any python 3.0 supported library for encryption. To encrypt files of 128 bits of data??</p>
0
2009-05-18T04:34:12Z
876,304
<p>To properly encrypt data, you need more than just an encryption algorithm. It's probably best you find a complete library with documentation showing how to do things properly, if you absolutely must do it yourself. </p> <p>Encryption alone is not sufficient. How are you generating keys? What mode of operation are y...
0
2009-05-18T05:01:14Z
[ "python", "encryption", "aes" ]
Generating color ranges in Python
876,853
<p>I want to generate a list of color specifications in the form of (r, g, b) tuples, that span the entire color spectrum with as many entries as I want. So for 5 entries I would want something like:</p> <ul> <li>(0, 0, 1)</li> <li>(0, 1, 0)</li> <li>(1, 0, 0)</li> <li>(1, 0.5, 1)</li> <li>(0, 0, 0.5)</li> </ul> <p>O...
9
2009-05-18T09:24:32Z
876,872
<p>Use the HSV/HSB/HSL color space (three names for more or less the same thing). Generate N tuples equally spread in hue space, then just convert them to RGB.</p> <p>Sample code:</p> <pre><code>import colorsys N = 5 HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)] RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*...
27
2009-05-18T09:29:59Z
[ "python", "colors" ]
Generating color ranges in Python
876,853
<p>I want to generate a list of color specifications in the form of (r, g, b) tuples, that span the entire color spectrum with as many entries as I want. So for 5 entries I would want something like:</p> <ul> <li>(0, 0, 1)</li> <li>(0, 1, 0)</li> <li>(1, 0, 0)</li> <li>(1, 0.5, 1)</li> <li>(0, 0, 0.5)</li> </ul> <p>O...
9
2009-05-18T09:24:32Z
876,885
<p>This has already been answered in <a href="http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors">http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors</a> so you can use that in python too</p> <p>also look at this thread <a href="http://mail.p...
1
2009-05-18T09:33:48Z
[ "python", "colors" ]
Generating color ranges in Python
876,853
<p>I want to generate a list of color specifications in the form of (r, g, b) tuples, that span the entire color spectrum with as many entries as I want. So for 5 entries I would want something like:</p> <ul> <li>(0, 0, 1)</li> <li>(0, 1, 0)</li> <li>(1, 0, 0)</li> <li>(1, 0.5, 1)</li> <li>(0, 0, 0.5)</li> </ul> <p>O...
9
2009-05-18T09:24:32Z
17,684,501
<p>I created the following function based on <a href="http://stackoverflow.com/users/54486/kquinn">kquinn's</a> answer. </p> <pre><code>import colorsys def get_N_HexCol(N=5): HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in xrange(N)] hex_out = [] for rgb in HSV_tuples: rgb = map(lambda x: int(x*255),c...
2
2013-07-16T18:41:30Z
[ "python", "colors" ]
Django reusable app for like functionality as in friendfeed
876,898
<p>I am looking to implement "like" functionallity a bit similar as they do in <a href="http://friendfeed.com" rel="nofollow">friendfeed</a>. Is there a django reusable app that already does this?</p> <p>Thanks! Nick.</p>
2
2009-05-18T09:36:15Z
876,982
<p>You could put your own together using parts of <a href="http://pinaxproject.com/" rel="nofollow">Pinax</a>.</p> <p>There isn't one app that would do this for you as it's too specific and reusable Django apps are supposed to be very focussed.</p>
1
2009-05-18T09:58:35Z
[ "python", "django" ]
Django reusable app for like functionality as in friendfeed
876,898
<p>I am looking to implement "like" functionallity a bit similar as they do in <a href="http://friendfeed.com" rel="nofollow">friendfeed</a>. Is there a django reusable app that already does this?</p> <p>Thanks! Nick.</p>
2
2009-05-18T09:36:15Z
877,014
<p>Search <a href="http://djangoplugables.com/" rel="nofollow">http://djangoplugables.com/</a> </p>
0
2009-05-18T10:07:37Z
[ "python", "django" ]
Django reusable app for like functionality as in friendfeed
876,898
<p>I am looking to implement "like" functionallity a bit similar as they do in <a href="http://friendfeed.com" rel="nofollow">friendfeed</a>. Is there a django reusable app that already does this?</p> <p>Thanks! Nick.</p>
2
2009-05-18T09:36:15Z
877,045
<p>This sort of thing you should just write yourself from scratch. A 'like' in its most basic form is going to be an object with relations to a user and some other object. Look at the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/" rel="nofollow">contenttypes framework</a> docs to see how to us...
4
2009-05-18T10:17:08Z
[ "python", "django" ]
How can I create an local webserver for my python scripts?
877,033
<p>I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.</p> <p>I've been looking, therefore, for a ligh...
14
2009-05-18T10:13:26Z
877,053
<p>Don't waste a lot of time creating Windows service.</p> <p>Don't waste a lot of time on Windows Apache.</p> <p>Just make a Python service that responds to HTTP requests. </p> <p>Look at <a href="http://docs.python.org/library/basehttpserver.html">http://docs.python.org/library/basehttpserver.html</a> Python off...
15
2009-05-18T10:19:46Z
[ "python", "webserver", "simplehttpserver" ]
How can I create an local webserver for my python scripts?
877,033
<p>I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.</p> <p>I've been looking, therefore, for a ligh...
14
2009-05-18T10:13:26Z
877,056
<p>Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.</p> <p>BTW: I had a similar question on stackoverflow: <a h...
0
2009-05-18T10:20:45Z
[ "python", "webserver", "simplehttpserver" ]
How can I create an local webserver for my python scripts?
877,033
<p>I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.</p> <p>I've been looking, therefore, for a ligh...
14
2009-05-18T10:13:26Z
22,310,248
<p>Best way is to make your own local server by using command prompt.</p> <ol> <li>Make a new folder say Project</li> <li>Make a new folder inside project &amp; name it as "cgi-bin"(without quotes)</li> <li>Paste your .py file inside the cgi-bin folder</li> <li>Open cmd and change to the directory from which you want ...
1
2014-03-10T20:09:19Z
[ "python", "webserver", "simplehttpserver" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,081
<p>I'm not an expert of Python, but what is wrong with a simple loop from start to end of first array? </p> <p>In C# I would do something like:</p> <pre><code>int match=0; for (int cnt=0; cnt&lt; A.Count;cnt++) { if ((A[cnt]==B[cnt]==1)) match++; } </code></pre> <p>Would that be possible in your language?</p>
1
2009-05-18T10:29:06Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,082
<p>A little shorter and hopefully more pythonic way:</p> <pre><code>&gt;&gt;&gt; A=[0,0,0,1,0,1] &gt;&gt;&gt; B=[0,0,1,1,1,1] x = sum(1 for a,b in zip(A,B) if (a==b==1)) &gt;&gt;&gt; x 2 </code></pre>
19
2009-05-18T10:29:26Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,102
<p>Motivated by brief need to be perverse, I offer the following solution:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] print len(set(i for i, n in enumerate(A) if n == 1) &amp; set(i for i, n in enumerate(B) if n == 1)) </code></pre> <p>(Drakosha's suggestion is a far more reasonable way to solve th...
1
2009-05-18T10:40:34Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,243
<p>With <a href="http://www.scipy.org" rel="nofollow">SciPy</a>:</p> <pre><code>&gt;&gt;&gt; from scipy import array &gt;&gt;&gt; A=array([0,0,0,1,0,1]) &gt;&gt;&gt; B=array([0,0,1,1,1,1]) &gt;&gt;&gt; A==B array([ True, True, False, True, False, True], dtype=bool) &gt;&gt;&gt; sum(A==B) 4 &gt;&gt;&gt; A!=B array...
0
2009-05-18T11:23:16Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,443
<p>Slightly shorter variation of Drakosha's:</p> <pre><code>&gt;&gt;&gt; A = [0,0,0,1,0,1] &gt;&gt;&gt; B = [0,0,1,1,1,1] &gt;&gt;&gt; sum(a*b for a, b in zip(A, B) ) 2 </code></pre>
3
2009-05-18T12:15:33Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,450
<p>Here comes another method which exploits the fact that the array just contains zeros and ones.</p> <p>The scalar product of two vectors x and y is sum( x(i)*y(i) ) the only situation yielding a non zero result is if x(i)==y(i)==1 thus using numpy for instance</p> <pre><code>from numpy import * x = array([0,0,0,1,0...
0
2009-05-18T12:17:45Z
[ "python", "list" ]
Find the number of 1s in the same position in two arrays
877,059
<p>I have two lists:</p> <pre><code>A = [0,0,0,1,0,1] B = [0,0,1,1,1,1] </code></pre> <p>I want to find the number of 1s in the same position in both lists.</p> <p>The answer for these arrays would be 2.</p>
7
2009-05-18T10:21:45Z
877,915
<pre><code>[A[i]+B[i] for i in range(min([len(A), len(B)]))].count(2) </code></pre> <p>Basically this just creates a new list which has all the elements of the other two added together. You know there were two 1's if the sum is 2 (assuming only 0's and 1's in the list). Therefore just perform the count operation on ...
0
2009-05-18T14:05:20Z
[ "python", "list" ]
Learning threading concepts
877,068
<p>I have started threading in C and also Python recently and would like to know any good tutorials available for it.</p>
4
2009-05-18T10:23:17Z
877,078
<p>I could think of couple of MSDN links (for windows):</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms810438.aspx" rel="nofollow">Multithreading for Rookies</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/y6h8hye8%28VS.80%29.aspx" rel="nofollow">Multithreading with C and Win32</a> </p>
0
2009-05-18T10:27:40Z
[ "python", "c", "multithreading" ]
Learning threading concepts
877,068
<p>I have started threading in C and also Python recently and would like to know any good tutorials available for it.</p>
4
2009-05-18T10:23:17Z
877,094
<p><strong>C - Recommended Books</strong></p> <p>Unix: <a href="http://rads.stackoverflow.com/amzn/click/0201633922" rel="nofollow">Butenhof, David R. - Programming with POSIX(R) Threads (Addison-Wesley Professional Computing Series)</a></p> <p>Windows: <a href="http://rads.stackoverflow.com/amzn/click/0321256190" re...
2
2009-05-18T10:35:53Z
[ "python", "c", "multithreading" ]
Learning threading concepts
877,068
<p>I have started threading in C and also Python recently and would like to know any good tutorials available for it.</p>
4
2009-05-18T10:23:17Z
877,135
<p>You could write the threading yourself, it could be hard but doing that, you will learn more about threading.</p> <p>Or you could use a preexisting threading library. It will let you implement threading faster in your application, but you may not learn as much as to what goes on "under the hood".</p> <p>From your ...
1
2009-05-18T10:47:48Z
[ "python", "c", "multithreading" ]
Learning threading concepts
877,068
<p>I have started threading in C and also Python recently and would like to know any good tutorials available for it.</p>
4
2009-05-18T10:23:17Z
878,644
<p>I have found Interprocess <a href="http://rads.stackoverflow.com/amzn/click/0130460427" rel="nofollow">Communications in Linux: The Nooks and Crannies</a> to be extremely useful for IPC (and threading) in C.</p>
0
2009-05-18T16:47:18Z
[ "python", "c", "multithreading" ]
HTTPSConnection module missing in Python 2.6 on CentOS 5.2
877,072
<p>I'm playing around with a Python application on CentOS 5.2. It uses the Boto module to communicate with Amazon Web Services, which requires communication through a HTTPS connection.</p> <p>When I try running my application I get an error regarding HTTPSConnection being missing: "AttributeError: 'module' object has ...
7
2009-05-18T10:24:57Z
877,292
<p>citing from the python documentation (<a href="http://docs.python.org/library/httplib.html">http://docs.python.org/library/httplib.html</a>):</p> <p><strong>Note</strong> HTTPS support is only available if the socket module was compiled with SSL support.</p> <p>You should find out how python on the CentOS you are ...
7
2009-05-18T11:38:46Z
[ "python", "centos" ]
HTTPSConnection module missing in Python 2.6 on CentOS 5.2
877,072
<p>I'm playing around with a Python application on CentOS 5.2. It uses the Boto module to communicate with Amazon Web Services, which requires communication through a HTTPS connection.</p> <p>When I try running my application I get an error regarding HTTPSConnection being missing: "AttributeError: 'module' object has ...
7
2009-05-18T10:24:57Z
877,549
<p>How come you have python 2.6? In CentOS 2.4 is standard, this might be the cause of your problem. Might be worth installing boto again as the library paths might not be correct</p>
0
2009-05-18T12:44:01Z
[ "python", "centos" ]
HTTPSConnection module missing in Python 2.6 on CentOS 5.2
877,072
<p>I'm playing around with a Python application on CentOS 5.2. It uses the Boto module to communicate with Amazon Web Services, which requires communication through a HTTPS connection.</p> <p>When I try running my application I get an error regarding HTTPSConnection being missing: "AttributeError: 'module' object has ...
7
2009-05-18T10:24:57Z
2,598,936
<p>Please install openssl and openssl-devel before you install python2.6.</p> <p>You can simply install those packages using yum, and do a re-install of python2.6 (no need to remove already installed python2.6)</p> <pre><code>]# yum install openssl openssl-devel Python-2.6.x]# ./configure Python-2.6.x]# make &amp;&a...
6
2010-04-08T10:01:32Z
[ "python", "centos" ]