title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
How to trim whitespace (including tabs)?
1,185,524
<p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
623
2009-07-26T20:54:38Z
33,968,149
<p>Whitespace includes <strong>space, tabs and CRLF</strong>. So an elegant and <strong>one-liner</strong> string function we can use is <strong>translate</strong>. </p> <p><code>' hello apple'.translate(None, ' \n\t\r')</code></p> <p><strong>OR</strong> if you want to be thorough</p> <pre><code>import string ' hel...
3
2015-11-28T05:45:56Z
[ "python", "string", "trim", "strip" ]
Python loop counter in a for loop
1,185,545
<p>In my example code below, is the counter = 0 really required, or is there a better, more Python, way to get access to a loop counter? I saw a few PEPs related to loop counters, but they were either deferred or rejected (<a href="http://www.python.org/dev/peps/pep-0212/">PEP 212</a> and <a href="http://www.python.org...
101
2009-07-26T21:05:26Z
1,185,557
<p><strong>Use <a href="http://docs.python.org/library/functions.html#enumerate"><code>enumerate()</code></a> like so:</strong></p> <pre><code>def draw_menu(options, selected_index): for counter, option in enumerate(options): if counter == selected_index: print " [*] %s" % option else: ...
188
2009-07-26T21:09:15Z
[ "loops", "for-loop", "python" ]
Python loop counter in a for loop
1,185,545
<p>In my example code below, is the counter = 0 really required, or is there a better, more Python, way to get access to a loop counter? I saw a few PEPs related to loop counters, but they were either deferred or rejected (<a href="http://www.python.org/dev/peps/pep-0212/">PEP 212</a> and <a href="http://www.python.org...
101
2009-07-26T21:05:26Z
1,185,564
<p>You could also do:</p> <pre><code> for option in options: if option == options[selected_index]: #print else: #print </code></pre> <p>Although you'd run into issues if there are duplicate options.</p>
4
2009-07-26T21:11:08Z
[ "loops", "for-loop", "python" ]
Python loop counter in a for loop
1,185,545
<p>In my example code below, is the counter = 0 really required, or is there a better, more Python, way to get access to a loop counter? I saw a few PEPs related to loop counters, but they were either deferred or rejected (<a href="http://www.python.org/dev/peps/pep-0212/">PEP 212</a> and <a href="http://www.python.org...
101
2009-07-26T21:05:26Z
1,185,599
<p>I'll sometimes do this:</p> <pre><code>def draw_menu(options, selected_index): for i in range(len(options)): if i == selected_index: print " [*] %s" % options[i] else: print " [ ] %s" % options[i] </code></pre> <p>Though I tend to avoid this if it means I'll be saying <c...
3
2009-07-26T21:28:17Z
[ "loops", "for-loop", "python" ]
How do I define a unique property for a Model in Google App Engine?
1,185,628
<p>I need some properties to be unique. How can I achieve this?</p> <p>Is there something like <code>unique=True</code>?</p> <p>I'm using Google App Engine for Python.</p>
32
2009-07-26T21:41:29Z
1,185,703
<p>There's no built-in constraint for making sure a value is unique. You can do this however:</p> <pre><code>query = MyModel.all(keys_only=True).filter('unique_property', value_to_be_used) entity = query.get() if entity: raise Exception('unique_property must have a unique value!') </code></pre> <p>I use <code>key...
21
2009-07-26T22:13:16Z
[ "python", "google-app-engine", "google-cloud-datastore" ]
How do I define a unique property for a Model in Google App Engine?
1,185,628
<p>I need some properties to be unique. How can I achieve this?</p> <p>Is there something like <code>unique=True</code>?</p> <p>I'm using Google App Engine for Python.</p>
32
2009-07-26T21:41:29Z
5,829,926
<p>Google has provided function to do that:</p> <p><a href="http://code.google.com/appengine/docs/python/datastore/modelclass.html#Model_get_or_insert">http://code.google.com/appengine/docs/python/datastore/modelclass.html#Model_get_or_insert</a></p> <pre><code>Model.get_or_insert(key_name, **kwds) </code></pre> <p>...
24
2011-04-29T08:44:07Z
[ "python", "google-app-engine", "google-cloud-datastore" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
1,185,638
<p>Key tools: entropy, greediness, branch-and-bound; Python, generators, itertools, decorate-undecorate pattern</p> <p>In answering this question, I wanted to build up a language of useful functions to explore the problem. I will go through these functions, describing them and their intent. Originally, these had exten...
39
2009-07-26T21:44:24Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
1,185,776
<p>Have you seem Raymond Hettingers <a href="http://code.activestate.com/recipes/496907/">attempt</a>? They certainly match up to some of your requirements.</p> <p>I wonder how his solutions compares to yours.</p>
7
2009-07-26T22:47:24Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
1,339,515
<p>There is a great site about MasterMind strategy <a href="http://home.pacific.net.hk/~kfzhou/mmh.html#Tutor" rel="nofollow">here</a>. The author starts off with very simple MasterMind problems (using numbers rather than letters, and ignoring order and repetition) and gradually builds up to a full MasterMind problem ...
4
2009-08-27T07:54:17Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
1,353,367
<p>I once wrote a "<a href="http://en.wikipedia.org/wiki/Jotto" rel="nofollow">Jotto</a>" solver which is essentially "Master Mind" with words. (We each pick a word and we take turns guessing at each other's word, scoring "right on" (exact) matches and "elsewhere" (correct letter/color, but wrong placement).</p> <p><...
10
2009-08-30T07:41:54Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
7,828,779
<p>Just thought I'd contribute my 90 odd lines of code. I've build upon <a href="http://stackoverflow.com/questions/1185634/how-to-solve-the-mastermind-guessing-game/1353367#1353367">@Jim Dennis</a>' answer, mostly taking away the hint on symetric scoring. I've implemented the minimax algorithm as described on the <a h...
1
2011-10-19T22:03:33Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
9,515,347
<p>To work out the "worst" case, instead of using entropic I am looking to the partition that has the maximum number of elements, then select the try that is a minimum for this maximum => This will give me the minimum number of remaining possibility when I am not lucky (which happens in the worst case).</p> <p>This al...
0
2012-03-01T11:28:31Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
13,945,649
<p>Here is a generic algorithm I wrote that uses numbers to represent the different colours. Easy to change, but I find numbers to be a lot easier to work with than strings. </p> <p>You can feel free to use any whole or part of this algorithm, as long as credit is given accordingly. </p> <p>Please note I'm only a Gra...
0
2012-12-19T04:45:00Z
[ "python", "algorithm" ]
How to solve the "Mastermind" guessing game?
1,185,634
<p>How would you create an algorithm to solve the following puzzle, "Mastermind"?</p> <p>Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not wh...
34
2009-07-26T21:43:36Z
20,725,715
<p>Here's a link to pure Python solver for Mastermind(tm): <a href="http://code.activestate.com/recipes/496907-mastermind-style-code-breaking/" rel="nofollow">http://code.activestate.com/recipes/496907-mastermind-style-code-breaking/</a> It has a simple version, a way to experiment with various guessing strategies, p...
0
2013-12-22T02:39:33Z
[ "python", "algorithm" ]
Python: is os.read() / os.write() on an os.pipe() threadsafe?
1,185,660
<p>Consider:</p> <pre><code>pipe_read, pipe_write = os.pipe() </code></pre> <p>Now, I would like to know two things:</p> <p><strong>(1)</strong> I have two threads. If I guarantee that only one is reading <code>os.read(pipe_read,n)</code> and the other is only writing <code>os.write(pipe_write)</code>, will I have a...
7
2009-07-26T21:53:25Z
1,186,161
<p><code>os.read</code> and <code>os.write</code> on the two fds returned from <code>os.pipe</code> is threadsafe, but you appear to demand more than that. Sub <code>(1)</code>, yes, there is no "atomicity" guarantee for sinle reads or writes -- the scenario you depict (a single short write ends up producing two reads)...
8
2009-07-27T02:19:07Z
[ "python", "multithreading", "thread-safety", "pipe" ]
Using a caesarian cipher on a string of text in python?
1,185,775
<p>I'm trying to slowly knock out all of the intricacies of python. Basically, I'm looking for some way, in python, to take a string of characters and push them all over by 'x' characters. </p> <p>For example, inputing abcdefg will give me cdefghi (if x is 2).</p>
2
2009-07-26T22:47:15Z
1,185,787
<p><strong>This solution works for both lowercase and uppercase:</strong></p> <pre><code>from string import lowercase, uppercase def caesar(text, key): result = [] for c in text: if c in lowercase: idx = lowercase.index(c) idx = (idx + key) % 26 result.append(lowerc...
2
2009-07-26T22:53:36Z
[ "python", "encryption" ]
Using a caesarian cipher on a string of text in python?
1,185,775
<p>I'm trying to slowly knock out all of the intricacies of python. Basically, I'm looking for some way, in python, to take a string of characters and push them all over by 'x' characters. </p> <p>For example, inputing abcdefg will give me cdefghi (if x is 2).</p>
2
2009-07-26T22:47:15Z
1,185,808
<p>I think your best bet is to look at <a href="http://www.tutorialspoint.com/python/string%5Ftranslate.htm">string.translate</a>. You may have to use make_trans to make the mapping you like.</p>
5
2009-07-26T22:58:16Z
[ "python", "encryption" ]
Using a caesarian cipher on a string of text in python?
1,185,775
<p>I'm trying to slowly knock out all of the intricacies of python. Basically, I'm looking for some way, in python, to take a string of characters and push them all over by 'x' characters. </p> <p>For example, inputing abcdefg will give me cdefghi (if x is 2).</p>
2
2009-07-26T22:47:15Z
1,185,809
<p>My first version:</p> <pre><code>&gt;&gt;&gt; key = 2 &gt;&gt;&gt; msg = "abcdefg" &gt;&gt;&gt; ''.join( map(lambda c: chr(ord('a') + (ord(c) - ord('a') + key)%26), msg) ) 'cdefghi' &gt;&gt;&gt; msg = "uvwxyz" &gt;&gt;&gt; ''.join( map(lambda c: chr(ord('a') + (ord(c) - ord('a') + key)%26), msg) ) 'wxyzab' </code...
7
2009-07-26T22:58:39Z
[ "python", "encryption" ]
Using a caesarian cipher on a string of text in python?
1,185,775
<p>I'm trying to slowly knock out all of the intricacies of python. Basically, I'm looking for some way, in python, to take a string of characters and push them all over by 'x' characters. </p> <p>For example, inputing abcdefg will give me cdefghi (if x is 2).</p>
2
2009-07-26T22:47:15Z
1,185,816
<p>I would do it this way (for conceptual simplicity):</p> <pre><code>def encode(s): l = [ord(i) for i in s] return ''.join([chr(i + 2) for i in l]) </code></pre> <p>Point being that you convert the letter to ASCII, add 2 to that code, convert it back, and "cast" it into a string (create a new string object)....
3
2009-07-26T23:01:48Z
[ "python", "encryption" ]
Using a caesarian cipher on a string of text in python?
1,185,775
<p>I'm trying to slowly knock out all of the intricacies of python. Basically, I'm looking for some way, in python, to take a string of characters and push them all over by 'x' characters. </p> <p>For example, inputing abcdefg will give me cdefghi (if x is 2).</p>
2
2009-07-26T22:47:15Z
1,185,820
<p>Another version. Allows for definition of your own alphabet, and doesn't translate any other characters (such as punctuation). The ugly part here is the loop, which might cause performance problems. I'm not sure about python but appending strings like this is a big no in other languages like Java and C#.</p> <pre><...
1
2009-07-26T23:02:46Z
[ "python", "encryption" ]
How to associate py extension with python launcher on Mac OS X?
1,185,817
<p>Does anyone know how to associate the py extension with the python interpreter on Mac OS X 10.5.7? I have gotten as far as selecting the application with which to associate it (/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python), but the python executable appears as a non-selectable grayed-out item....
4
2009-07-26T23:01:51Z
1,185,827
<p>Steve, add the following to the top of your python script:</p> <pre><code>#!/usr/bin/env python </code></pre> <p>It must occur as the first line of the file.</p> <p>Then make the file executable as so:</p> <pre><code>daves-macbookpro ~: chmod +x foo.py </code></pre> <p>Then all you need to do to run this is typ...
2
2009-07-26T23:06:47Z
[ "python", "osx" ]
How to associate py extension with python launcher on Mac OS X?
1,185,817
<p>Does anyone know how to associate the py extension with the python interpreter on Mac OS X 10.5.7? I have gotten as far as selecting the application with which to associate it (/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python), but the python executable appears as a non-selectable grayed-out item....
4
2009-07-26T23:01:51Z
1,185,893
<p>The file associations are done with the "Get Info". You select your .PY file, select the File menu; Get Info menu item.</p> <p>Mid-way down the Get Info page is "Open With".</p> <p>You can pick the Python Launcher. There's a <strong>Change All..</strong> button that changes the association for all <code>.py</co...
2
2009-07-26T23:37:33Z
[ "python", "osx" ]
How to associate py extension with python launcher on Mac OS X?
1,185,817
<p>Does anyone know how to associate the py extension with the python interpreter on Mac OS X 10.5.7? I have gotten as far as selecting the application with which to associate it (/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python), but the python executable appears as a non-selectable grayed-out item....
4
2009-07-26T23:01:51Z
1,185,899
<p>The python.org OS X Python installers include an application called "Python Launcher.app" which does exactly what you want. It gets installed into /Applications /Python n.n/ for n.n > 2.6 or /Applications/MacPython n.n/ for 2.5 and earlier. In its preference panel, you can specify which Python executable to launch...
6
2009-07-26T23:41:33Z
[ "python", "osx" ]
How to associate py extension with python launcher on Mac OS X?
1,185,817
<p>Does anyone know how to associate the py extension with the python interpreter on Mac OS X 10.5.7? I have gotten as far as selecting the application with which to associate it (/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python), but the python executable appears as a non-selectable grayed-out item....
4
2009-07-26T23:01:51Z
28,869,258
<p>The default python installation (atleast on 10.6.8) includes the <code>Python Launcher.app</code> in <code>/System/Library/Frameworks/Python.framework/Resources/</code>, which is aliased to the latest/current version of Python installed on the system. This application launches terminal and sets the right environment...
0
2015-03-05T03:02:25Z
[ "python", "osx" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,185,871
<p>You can simply use subprocess.Popen for that purpose, without any problems.</p> <p>However, you might want to simply install cronjobs on the remote machines. :-)</p>
1
2009-07-26T23:27:10Z
[ "python", "ssh", "parallel-processing" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,185,880
<p>Reading the paramiko API docs, it looks like it is possible to open one ssh connection, and multiplex as many ssh tunnels on top of that as are wished. Common ssh clients (openssh) often do things like this automatically behind the scene if there is already a connection open.</p>
1
2009-07-26T23:30:57Z
[ "python", "ssh", "parallel-processing" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,186,046
<p>It might be worth checking out what options are available in Twisted. For example, the Twisted.Conch page reports:</p> <blockquote> <p><a href="http://twistedmatrix.com/users/z3p/files/conch-talk.html" rel="nofollow">http://twistedmatrix.com/users/z3p/files/conch-talk.html</a></p> <p>Unlike OpenSSH, the Con...
3
2009-07-27T01:14:39Z
[ "python", "ssh", "parallel-processing" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,188,586
<p>Yes, you can do this with paramiko.</p> <p>If you're connecting to one server, you can run multiple channels through a single connection. If you're connecting to multiple servers, you can start multiple connections in separate threads. No need to manage multiple processes, although you could substitute the multipro...
3
2009-07-27T14:45:25Z
[ "python", "ssh", "parallel-processing" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,516,547
<p>This might not be relevant to your question. But there are tools like pssh, clusterssh etc. that can parallely spawn connections. You can couple Expect with pssh to control them too.</p>
-1
2009-10-04T14:34:34Z
[ "python", "ssh", "parallel-processing" ]
Parallel SSH in Python
1,185,855
<p>I wonder what is the best way to handle parallel SSH connections in python. I need to open several SSH connections to keep in background and to feed commands in interactive or timed batch way. Is this possible to do it with the paramiko libraries? It would be nice not to spawn a different SSH process for each connec...
3
2009-07-26T23:19:27Z
1,604,266
<p>I've tried clusterssh, and I don't like the multiwindow model. Too confusing in the common case when everything works. </p> <p>I've tried pssh, and it has a few problems with quotation escaping and password prompting.</p> <p>The best I've used is <a href="http://packages.debian.org/sid/dsh" rel="nofollow">dsh</a>:...
1
2009-10-21T23:45:06Z
[ "python", "ssh", "parallel-processing" ]
How can I execute CGI files from PHP?
1,185,867
<p>I'm trying to make a web app that will manage my Mercurial repositories for me. I want it so that when I tell it to load repository X:</p> <ul> <li>Connect to a MySQL server and make sure X exists.</li> <li>Check if the user is allowed to access the repository.</li> <li>If above is true, get the location of X from ...
0
2009-07-26T23:24:18Z
1,185,895
<p>You can run shell scripts from within PHP. There are various ways to do it, and complications with some hosts not providing the proper permissions, all of which are well-documented on php.net. That said, the simplest way is to simply enclose your command in backticks. So, to unzip a file, I could say:</p> <pre><cod...
2
2009-07-26T23:39:31Z
[ "php", "python", "mercurial", "cgi" ]
How can I execute CGI files from PHP?
1,185,867
<p>I'm trying to make a web app that will manage my Mercurial repositories for me. I want it so that when I tell it to load repository X:</p> <ul> <li>Connect to a MySQL server and make sure X exists.</li> <li>Check if the user is allowed to access the repository.</li> <li>If above is true, get the location of X from ...
0
2009-07-26T23:24:18Z
1,185,909
<p>As far as you question, no, you're not likely to get php to execute a modified script without writing it somewhere, whether that's a file on the disk, a virtual file mapped to ram, or something similar.</p> <p>It sounds like you might be trying to pound a railroad spike with a twig. If you're to the point where you...
0
2009-07-26T23:45:22Z
[ "php", "python", "mercurial", "cgi" ]
How can I execute CGI files from PHP?
1,185,867
<p>I'm trying to make a web app that will manage my Mercurial repositories for me. I want it so that when I tell it to load repository X:</p> <ul> <li>Connect to a MySQL server and make sure X exists.</li> <li>Check if the user is allowed to access the repository.</li> <li>If above is true, get the location of X from ...
0
2009-07-26T23:24:18Z
1,185,918
<p>Ryan Ballantyne has the right answer posted (I upvoted it). The backtick operator is the way to execute a shell script.</p> <p>The simplest solution is probably to modify the hgweb script so that it doesn't "contain" the path to the repository, per se. Instead, pass it as a command-line argument. This means you ...
2
2009-07-26T23:52:09Z
[ "php", "python", "mercurial", "cgi" ]
Can I use C++ features while extending Python?
1,185,878
<p>The Python manual says that you can create modules for Python in both C and C++. Can you take advantage of things like classes and templates when using C++? Wouldn't it create incompatibilities with the rest of the libraries and with the interpreter?</p>
5
2009-07-26T23:30:23Z
1,185,907
<p>It doesn't matter whether your implementation of the hook functions is implemented in C or in C++. In fact, I've already seen some Python extensions which make active use of C++ templates and even the Boost library. <b>No problem.</b> :-)</p>
8
2009-07-26T23:44:31Z
[ "c++", "python", "c", "python-c-api", "python-c-extension" ]
Can I use C++ features while extending Python?
1,185,878
<p>The Python manual says that you can create modules for Python in both C and C++. Can you take advantage of things like classes and templates when using C++? Wouldn't it create incompatibilities with the rest of the libraries and with the interpreter?</p>
5
2009-07-26T23:30:23Z
1,185,911
<p>What you're interested in is a program called <a href="http://www.swig.org" rel="nofollow">SWIG</a>. It will generate Python wrappers and interfaces for C++ code. I use it with templates, inheritance, namespaces, etc. and it works well.</p>
2
2009-07-26T23:46:42Z
[ "c++", "python", "c", "python-c-api", "python-c-extension" ]
Can I use C++ features while extending Python?
1,185,878
<p>The Python manual says that you can create modules for Python in both C and C++. Can you take advantage of things like classes and templates when using C++? Wouldn't it create incompatibilities with the rest of the libraries and with the interpreter?</p>
5
2009-07-26T23:30:23Z
1,185,954
<p>The boost folks have a nice automated way to do the wrapping of C++ code for use by python.</p> <p>It is called: Boost.Python</p> <p>It deals with some of the constructs of C++ better than SWIG, particularly template metaprogramming.</p>
3
2009-07-27T00:22:12Z
[ "c++", "python", "c", "python-c-api", "python-c-extension" ]
Can I use C++ features while extending Python?
1,185,878
<p>The Python manual says that you can create modules for Python in both C and C++. Can you take advantage of things like classes and templates when using C++? Wouldn't it create incompatibilities with the rest of the libraries and with the interpreter?</p>
5
2009-07-26T23:30:23Z
1,185,957
<p>You should be able to use all of the features of the C++ language. The <a href="http://docs.python.org/extending/extending.html" rel="nofollow">Extending Python Documentation (2.6.2)</a> says that you may use C++, but mentions the followings caveats:</p> <blockquote> <p>It is possible to write extension module...
1
2009-07-27T00:23:37Z
[ "c++", "python", "c", "python-c-api", "python-c-extension" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
1,186,011
<p>See the rarfile module:</p> <ul> <li><strike>http://grue.l-t.ee/~marko/src/rarfile/README.html</strike></li> <li><a href="http://pypi.python.org/pypi/rarfile/" rel="nofollow">http://pypi.python.org/pypi/rarfile/</a></li> <li><a href="https://github.com/markokr/rarfile" rel="nofollow">https://github.com/markokr/rarf...
7
2009-07-27T00:54:58Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
1,186,012
<p>Look at the Python "struct" module. You can then interpret the RAR file format directly in your Python program, allowing you to retrieve the content inside the RAR without depending on external software to do it for you.</p> <p>EDIT: This is of course vanilla Python - there are alternatives which use third-party mo...
0
2009-07-27T00:55:33Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
1,186,014
<p>The <a href="http://packages.debian.org/source/lenny/p7zip" rel="nofollow">free 7zip library</a> is also able to handle RAR files.</p>
0
2009-07-27T00:58:02Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
1,186,041
<p>The real answer is that there isn't a library, and you can't make one. You can use rarfile, or you can use 7zip unRAR (which is less free than 7zip, but still free as in beer), but both approaches require an external executable. The license for RAR basically requires this, as while you can get source code for unRA...
4
2009-07-27T01:11:12Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
1,186,099
<p>RAR is a proprietary format; I don't think there are any public specs, so third-party tool and library support is poor to non-existant.</p> <p>You're much better off using ZIP; it's completely free, has an accurate public spec, the compression library is available everywhere (zlib is one of the most widely-deployed...
1
2009-07-27T01:43:50Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
3,154,780
<p>The <a href="http://code.google.com/p/py-unrar2/" rel="nofollow">pyUnRAR2</a> library can extract files from RAR archives to memory (and disk if you want). It's available under the MIT license and simply wraps UnRAR.dll on Windows and unrar on Unix. Click "QuickTutorial" for usage examples.</p> <p>On Windows, it is...
1
2010-07-01T02:47:34Z
[ "python", "linux", "stream", "rar" ]
Read content of RAR file into memory in Python
1,185,959
<p>I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.</p> <p>That all said, ...
6
2009-07-27T00:25:14Z
4,436,131
<p>It seems like the limitation that rarsoft imposes on derivative works is that you may not use the unrar source code to create a variation of the RAR <em>COMPRESSION</em> algorithm. From the context, it would appear that it's specifically allowing folks to use his code (modified or not) to decompress files, but you ...
2
2010-12-14T05:19:23Z
[ "python", "linux", "stream", "rar" ]
Are there any examples on python-purple floating around?
1,186,062
<p>I want to learn it but I have <strong>no</strong> idea where to start. Everything out there suggests reading the <code>libpurple</code> source but I don't think I understand enough <code>c</code> to really get a grasp of it. </p>
8
2009-07-27T01:29:29Z
1,186,138
<p>Not sure how much help this will be but based on information from <a href="http://developer.pidgin.im/wiki/PythonHowTo" rel="nofollow">here</a>, it seems like you just install python-purple and import and call the functions as normal Python functions.</p>
1
2009-07-27T02:07:09Z
[ "python", "libpurple" ]
Are there any examples on python-purple floating around?
1,186,062
<p>I want to learn it but I have <strong>no</strong> idea where to start. Everything out there suggests reading the <code>libpurple</code> source but I don't think I understand enough <code>c</code> to really get a grasp of it. </p>
8
2009-07-27T01:29:29Z
1,186,141
<p>There isn't much about it yet... the <a href="http://brunoabinader.blogspot.com/2009/04/introducing-python-purple.html" rel="nofollow">intro</a>, the <a href="http://developer.pidgin.im/wiki/PythonHowTo" rel="nofollow">howto</a>, and the <a href="https://git.maemo.org/projects/python-purple/?p=python-purple;a=tree" ...
1
2009-07-27T02:07:52Z
[ "python", "libpurple" ]
Are there any examples on python-purple floating around?
1,186,062
<p>I want to learn it but I have <strong>no</strong> idea where to start. Everything out there suggests reading the <code>libpurple</code> source but I don't think I understand enough <code>c</code> to really get a grasp of it. </p>
8
2009-07-27T01:29:29Z
1,237,039
<p>Can't help you with a concrete example as I decided to use something else. However, one of the first things I wanted to do after I cloned the repo was remove the ecore dependency. Here's a patch submitted to the mailing list to do just that: <a href="https://garage.maemo.org/pipermail/python-purple-devel/2009-Marc...
0
2009-08-06T04:54:21Z
[ "python", "libpurple" ]
Nested Set Model and SQLAlchemy -- Adding New Nodes
1,186,086
<p>How should new nodes be added with SQLAlchemy to a tree implemented using the <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow">Nested Set Model</a>?</p> <pre><code>class Category(Base): __tablename__ = 'categories' id = Column(Integer, primary_key=True) name...
2
2009-07-27T01:38:20Z
1,194,549
<p>You might want to look at the <a href="http://docs.sqlalchemy.org/en/latest/_modules/examples/nested_sets/nested_sets.html" rel="nofollow">nested sets example</a> in the examples directory of SQLAlchemy. This implements the model at the Python level.</p> <p>Doing it at the database level with triggers would need so...
5
2009-07-28T14:36:57Z
[ "python", "sql", "tree", "sqlalchemy", "nested-sets" ]
Appengine and GWT - feeding the python some java
1,186,155
<p>I realize this is a dated question since appengine now comes in java, but I have a python appengine app that I want to access via GWT. Python is just better for server-side text processing (using pyparsing of course!). I have tried to interpret GWT's client-side RPC and that is convoluted since there is no python ...
3
2009-07-27T02:16:15Z
1,186,322
<p>The only alternative (if you can call it that) that I'm familiar with is <a href="http://pyjs.org/" rel="nofollow">Pyjamas</a>. Obviously, this is more of a GWT replacement than a GWT-RPC replacement. Beyond that, I think you would be stuck with writing your own communications layer using some sort of REST-type pr...
1
2009-07-27T03:45:09Z
[ "java", "python", "google-app-engine", "gwt" ]
Appengine and GWT - feeding the python some java
1,186,155
<p>I realize this is a dated question since appengine now comes in java, but I have a python appengine app that I want to access via GWT. Python is just better for server-side text processing (using pyparsing of course!). I have tried to interpret GWT's client-side RPC and that is convoluted since there is no python ...
3
2009-07-27T02:16:15Z
1,348,919
<p>You can maybe have a look at the GWT JSON RPC <a href="http://code.google.com/webtoolkit/examples/jsonrpc/" rel="nofollow">example</a>.</p> <p>If that fails, there are always several XML parser implementations in Python AND Java :)</p>
0
2009-08-28T19:33:10Z
[ "java", "python", "google-app-engine", "gwt" ]
Appengine and GWT - feeding the python some java
1,186,155
<p>I realize this is a dated question since appengine now comes in java, but I have a python appengine app that I want to access via GWT. Python is just better for server-side text processing (using pyparsing of course!). I have tried to interpret GWT's client-side RPC and that is convoluted since there is no python ...
3
2009-07-27T02:16:15Z
1,391,971
<p>I agree with your evaluation of Python's text processing and GWT's quality. Have you considered using Jython? Googling "pyparsing jython" gives some mixed reviews, but it seems there has been some success with recent versions of Jython.</p>
0
2009-09-08T04:32:08Z
[ "java", "python", "google-app-engine", "gwt" ]
Appengine and GWT - feeding the python some java
1,186,155
<p>I realize this is a dated question since appengine now comes in java, but I have a python appengine app that I want to access via GWT. Python is just better for server-side text processing (using pyparsing of course!). I have tried to interpret GWT's client-side RPC and that is convoluted since there is no python ...
3
2009-07-27T02:16:15Z
3,297,948
<p>I know I am late to this question...</p> <p>Have you seen this project?</p> <p><a href="http://code.google.com/p/python-gwt-rpc/" rel="nofollow">http://code.google.com/p/python-gwt-rpc/</a></p> <p>It might be useful as a starting point. </p>
0
2010-07-21T09:41:41Z
[ "java", "python", "google-app-engine", "gwt" ]
Python: update a list of tuples... fastest method
1,186,501
<p>This question is in relation to another question asked here: <a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python">Sorting 1M records</a></p> <p>I have since figured out the problem I was having with sorting. I was sorting items from a dictionary into a list every time I update...
1
2009-07-27T04:58:42Z
1,186,518
<p>You're scanning through all n records. You could instead do a binary search, which would be O(log(n)) instead of O(n). You can use the <a href="http://docs.python.org/library/bisect.html" rel="nofollow"><code>bisect</code></a> module to do this.</p>
2
2009-07-27T05:07:28Z
[ "python" ]
Python: update a list of tuples... fastest method
1,186,501
<p>This question is in relation to another question asked here: <a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python">Sorting 1M records</a></p> <p>I have since figured out the problem I was having with sorting. I was sorting items from a dictionary into a list every time I update...
1
2009-07-27T04:58:42Z
1,186,526
<p>Since apparently you don't care about the ending value of <code>self.sorted_records</code> actually <em>being</em> sorted (you have values in order 1, 45, 20, 76 -- that's NOT sorted!-), AND you only appear to care about IDs in <code>updated_records</code> that are also in <code>self.sorted_data</code>, a listcomp (...
1
2009-07-27T05:11:33Z
[ "python" ]
Python: update a list of tuples... fastest method
1,186,501
<p>This question is in relation to another question asked here: <a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python">Sorting 1M records</a></p> <p>I have since figured out the problem I was having with sorting. I was sorting items from a dictionary into a list every time I update...
1
2009-07-27T04:58:42Z
1,186,529
<p>Since you want to replace by dictionary key, but have the array sorted by dictionary value, you definitely need a linear search for the key. In that sense, your algorithm is the best you can hope for.</p> <p>If you would preserve the old dictionary value, then you could use a binary search for the value, and then l...
0
2009-07-27T05:13:55Z
[ "python" ]
Python: update a list of tuples... fastest method
1,186,501
<p>This question is in relation to another question asked here: <a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python">Sorting 1M records</a></p> <p>I have since figured out the problem I was having with sorting. I was sorting items from a dictionary into a list every time I update...
1
2009-07-27T04:58:42Z
1,188,064
<p>You'd probably be best served by some form of tree here (preserving sorted order while allowing O(log n) replacements.) There is no builtin balanaced tree type, but you can find many third party examples. Alternatively, you could either:</p> <ol> <li><p>Use a binary search to find the node. The bisect module wil...
1
2009-07-27T13:04:32Z
[ "python" ]
Customizing modelformset fields in Django
1,186,753
<p>I'd like to use the following form class in a modelformset. It takes a <em>maps</em> parameter and customizes the form fields accordingly.</p> <pre><code>class MyModelForm(forms.ModelForm): def __init__(self, maps, *args, **kwargs): super(MyModelForm, self).__init__(*args, **kwargs) #customize f...
0
2009-07-27T06:41:55Z
1,186,772
<p>Keep in mind that Django uses class <em>definition</em> as a sort of DSL to define various things. As such, instantiating at places where it expects the class object will break things.</p> <p>One approach is to create your own form factory. Something like:</p> <pre><code> def mymodelform_factory(maps): clas...
2
2009-07-27T06:47:28Z
[ "python", "django" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,818
<p>This is possible in Python 2 using</p> <pre><code>execfile("test2.py") </code></pre> <p>See the <a href="https://docs.python.org/2/library/functions.html#execfile" rel="nofollow">documentation</a> for the handling of namespaces, if important in your case.</p> <p>However, you should consider using a different appr...
78
2009-07-27T07:03:19Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,820
<p>Why not just import test1? every python script is a module. Better way would be to have function e.g. main/run in test1.py , import test1 and run test1.main() or you can execute test1.py as a subprocess.</p>
1
2009-07-27T07:04:07Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,826
<p>You should not be doing this. Instead, do:</p> <p>test1.py:</p> <pre><code> def print_test(): print "I am a test" print "see! I do nothing productive." </code></pre> <p>service.py</p> <pre><code>#near the top from test1 import print_test #lots of stuff here print_test() </code></pre>
8
2009-07-27T07:06:37Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,840
<p>Use <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-import-statement"><code>import test1</code></a> for the 1st use - it will execute the script. For later invocations, treat the script as an imported module, and call the <a href="http://docs.python.org/library/functions.html#reload"><code>reload(t...
6
2009-07-27T07:11:08Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,844
<p>If you want test1.py to remain executable with the same functionality as when it's called inside service.py, then do something like:</p> <p>test1.py</p> <pre><code>def main(): print "I am a test" print "see! I do nothing productive." if __name__ == "__main__": main() </code></pre> <p>service.py</p> ...
14
2009-07-27T07:11:51Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
1,186,847
<p>The usual way to do this is something like the following.</p> <p>test1.py</p> <pre><code>def some_func(): print 'in test 1, unproductive' if __name__ == '__main__': # test1.py executed as script # do something some_func() </code></pre> <p>service.py</p> <pre><code>import test1 def service_func(...
134
2009-07-27T07:12:30Z
[ "python", "eval" ]
What is the best way to call a Python script from another Python script?
1,186,789
<p>I have a script named test1.py which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call test1.py from the script running as a service.</p> <p>For example:</p> <h3>File t...
136
2009-07-27T06:52:48Z
11,230,471
<p>Another way:</p> <h3>File test1.py:</h3> <pre><code>print "test1.py" </code></pre> <h3>File service.py:</h3> <pre><code>import subprocess subprocess.call("test1.py", shell=True) </code></pre> <p>The advantage to this method is that you don't have to edit an existing Python script to put all its code into a sub...
34
2012-06-27T16:01:06Z
[ "python", "eval" ]
jQuery getJSON callback does not work - even with valid JSON - and seems to be using "OPTION" request not "GET"
1,186,827
<p>The background is that I've got a celery distributed job server configured with a Django view that returns the status of a running job in JSON. The job server is located at celeryserver.mydomain.com and the page I'm executing the jQuery from is www.mydomain.com so I shouldn't need to consider JSONP for this should ...
4
2009-07-27T07:06:53Z
1,186,865
<p>Are you fetching the JSON from another domain? If so, you're most likely running into cross-domain issues. You'll need to use JSONP. jQuery does this automatically, but the server needs to know that. </p> <p>See:</p> <p><a href="http://www.ibm.com/developerworks/library/wa-aj-jsonp1/" rel="nofollow">http://www.i...
0
2009-07-27T07:19:09Z
[ "jquery", "python", "django", "json" ]
jQuery getJSON callback does not work - even with valid JSON - and seems to be using "OPTION" request not "GET"
1,186,827
<p>The background is that I've got a celery distributed job server configured with a Django view that returns the status of a running job in JSON. The job server is located at celeryserver.mydomain.com and the page I'm executing the jQuery from is www.mydomain.com so I shouldn't need to consider JSONP for this should ...
4
2009-07-27T07:06:53Z
1,186,874
<p>I think you have a cross-subdomain issue, <code>sub.domain.tld</code> and <code>domain.ltd</code> are not the same.</p> <p>I recommend you to install <a href="http://getfirebug.com/" rel="nofollow">Firebug</a> and check if your code is throwing an <em>Permission denied</em> Exception when the request starts, if it...
3
2009-07-27T07:22:12Z
[ "jquery", "python", "django", "json" ]
jQuery getJSON callback does not work - even with valid JSON - and seems to be using "OPTION" request not "GET"
1,186,827
<p>The background is that I've got a celery distributed job server configured with a Django view that returns the status of a running job in JSON. The job server is located at celeryserver.mydomain.com and the page I'm executing the jQuery from is www.mydomain.com so I shouldn't need to consider JSONP for this should ...
4
2009-07-27T07:06:53Z
1,187,595
<p>change your url to something like:</p> <p>"https://celeryserver.mydomain.com/done/" + job_id + "?callback=?"</p> <p>and then on your django view result should be something to the effect of:</p> <pre><code>'{callback}({json})'.format(callback=request.GET['callback'], json=MyJSON) </code></pre> <p>...there are pro...
1
2009-07-27T11:05:19Z
[ "jquery", "python", "django", "json" ]
jQuery getJSON callback does not work - even with valid JSON - and seems to be using "OPTION" request not "GET"
1,186,827
<p>The background is that I've got a celery distributed job server configured with a Django view that returns the status of a running job in JSON. The job server is located at celeryserver.mydomain.com and the page I'm executing the jQuery from is www.mydomain.com so I shouldn't need to consider JSONP for this should ...
4
2009-07-27T07:06:53Z
1,191,760
<p>As several people stated, sub-domains count as domains and I had a cross-domain issue :)</p> <p>I solved it by creating a little piece of Django Middleware that changes the response from my views if they're returning JSON and the request had a callback attached.</p> <pre><code>class JSONPMiddleware: def proce...
1
2009-07-28T03:14:40Z
[ "jquery", "python", "django", "json" ]
Real world guide on using and/or setting up REST web services?
1,186,839
<p>I've only used XML RPC and I haven't really delved into SOAP but I'm trying to find a good comprehensive guide, with real world examples or even a walkthrough of some minimal REST application.</p> <p>I'm most comfortable with Python/PHP.</p>
0
2009-07-27T07:11:06Z
1,186,876
<p>I like the examples in the Richardson &amp; Ruby book, "RESTful Web Services" from O'Reilly.</p>
1
2009-07-27T07:22:47Z
[ "php", "python", "xml", "rest", "soap" ]
Real world guide on using and/or setting up REST web services?
1,186,839
<p>I've only used XML RPC and I haven't really delved into SOAP but I'm trying to find a good comprehensive guide, with real world examples or even a walkthrough of some minimal REST application.</p> <p>I'm most comfortable with Python/PHP.</p>
0
2009-07-27T07:11:06Z
1,186,879
<p>There is a good example with the Google App Engine Documentation. <a href="http://code.google.com/appengine/articles/rpc.html" rel="nofollow">http://code.google.com/appengine/articles/rpc.html</a>. It also talks you through some security aspects of doing REST</p>
1
2009-07-27T07:23:31Z
[ "php", "python", "xml", "rest", "soap" ]
Real world guide on using and/or setting up REST web services?
1,186,839
<p>I've only used XML RPC and I haven't really delved into SOAP but I'm trying to find a good comprehensive guide, with real world examples or even a walkthrough of some minimal REST application.</p> <p>I'm most comfortable with Python/PHP.</p>
0
2009-07-27T07:11:06Z
1,186,996
<p>Here are a few links:</p> <ul> <li><a href="http://www.infoq.com/articles/webber-rest-workflow" rel="nofollow">http://www.infoq.com/articles/webber-rest-workflow</a></li> <li><a href="http://microformats.org/wiki/rest/urls" rel="nofollow">http://microformats.org/wiki/rest/urls</a></li> <li><a href="http://blog.feed...
1
2009-07-27T08:04:40Z
[ "php", "python", "xml", "rest", "soap" ]
How to open python source files using the IDLE shell?
1,186,884
<p>If I import a module in IDLE using: </p> <pre><code>import &lt;module_name&gt; print &lt;module_name&gt;.__file__ </code></pre> <p>how can I open it without going through the Menu->File->Open multiple-step procedure?</p> <p>It would be nice to open it via a command that takes the path and outputs a separate edito...
1
2009-07-27T07:24:48Z
1,188,735
<p>I don't think IDLE will do it for you, but if you use Wing, you can mouse over the name of the module, and do a &lt;Ctrl>-&lt;Left Click>, or open the right click context menu on the module name, and select "Goto definition." Simple. You don't even have to know the module's <strong>file</strong> location; you just...
0
2009-07-27T15:11:11Z
[ "python", "file", "ide" ]
How to open python source files using the IDLE shell?
1,186,884
<p>If I import a module in IDLE using: </p> <pre><code>import &lt;module_name&gt; print &lt;module_name&gt;.__file__ </code></pre> <p>how can I open it without going through the Menu->File->Open multiple-step procedure?</p> <p>It would be nice to open it via a command that takes the path and outputs a separate edito...
1
2009-07-27T07:24:48Z
1,196,993
<ul> <li>You can use <code>ALT-M</code> and write the name of the module in the popup box</li> <li>You can use <code>CTRL-O</code> to open a file</li> </ul>
2
2009-07-28T21:59:13Z
[ "python", "file", "ide" ]
python SOAPpy problem
1,186,922
<p>This my code</p> <p>service part <hr /></p> <pre><code>class Test: def hello(): return "Hello World" </code></pre> <p>server Part <hr /></p> <pre><code>import SOAPpy from first_SOAP import * host = "127.0.0.1" port = 5551 SOAPpy.Config.debug = 1 server = SOAPpy.SOAPServer((host, port)) server.regis...
0
2009-07-27T07:39:32Z
1,187,039
<p>Do you really want to make test() a class method? I suggest you change your code like this.</p> <pre><code>class Test: def hello(self): return "Hello World" </code></pre> <p>Then you must create an instance of the Test class and register:</p> <pre><code>server.registerObject(Test()) </code></pre> <p>Then t...
0
2009-07-27T08:20:01Z
[ "python", "soappy" ]
Persistent Python Command-Line History
1,186,958
<p>I'd like to be able to "up-arrow" to commands that I input in a previous Python interpreter. I have found the <code>readline</code> module which offers functions like: <code>read_history_file</code>, <code>write_history_file</code>, and <code>set_startup_hook</code>. I'm not quite savvy enough to put this into pra...
14
2009-07-27T07:53:11Z
1,186,975
<p>Try using <a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> as a python shell. It already has everything you ask for. They have packages for most popular distros, so install should be very easy.</p>
4
2009-07-27T08:01:30Z
[ "interpreter", "python" ]
Persistent Python Command-Line History
1,186,958
<p>I'd like to be able to "up-arrow" to commands that I input in a previous Python interpreter. I have found the <code>readline</code> module which offers functions like: <code>read_history_file</code>, <code>write_history_file</code>, and <code>set_startup_hook</code>. I'm not quite savvy enough to put this into pra...
14
2009-07-27T07:53:11Z
1,186,981
<p>I think the suggestions in the Python documentation pretty much cover what you want. Look at the example pystartup file toward the end of section 13.3:</p> <ul> <li><a href="http://docs.python.org/tutorial/interactive.html">http://docs.python.org/tutorial/interactive.html</a></li> </ul> <p>or see this page:</p> ...
13
2009-07-27T08:02:14Z
[ "interpreter", "python" ]
Persistent Python Command-Line History
1,186,958
<p>I'd like to be able to "up-arrow" to commands that I input in a previous Python interpreter. I have found the <code>readline</code> module which offers functions like: <code>read_history_file</code>, <code>write_history_file</code>, and <code>set_startup_hook</code>. I'm not quite savvy enough to put this into pra...
14
2009-07-27T07:53:11Z
20,718,928
<p>Use PIP to install the <em>pyreadline</em> package:</p> <pre><code>pip install pyreadline </code></pre>
0
2013-12-21T12:19:12Z
[ "interpreter", "python" ]
Persistent Python Command-Line History
1,186,958
<p>I'd like to be able to "up-arrow" to commands that I input in a previous Python interpreter. I have found the <code>readline</code> module which offers functions like: <code>read_history_file</code>, <code>write_history_file</code>, and <code>set_startup_hook</code>. I'm not quite savvy enough to put this into pra...
14
2009-07-27T07:53:11Z
31,440,042
<p>If all you want is to use interactive history substitution without all the file stuff, all you need to do is import readline:</p> <pre><code>import readline </code></pre> <p>And then you can use the up/down keys to navigate past commands. Same for 2 or 3.</p> <p>This wasn't clear to me from the docs, but maybe I ...
0
2015-07-15T20:07:58Z
[ "interpreter", "python" ]
How do I control number formatting in the python interpreter?
1,187,000
<p>I often use the python interpreter for doing quick numerical calculations and would like all numerical results to be automatically printed using, e.g., exponential notation. Is there a way to set this for the entire session?</p> <p>For example, I want:</p> <pre><code>&gt;&gt;&gt; 1.e12 1.0e+12 </code></pre> <p>n...
2
2009-07-27T08:06:00Z
1,187,012
<p>As you know you can use <a href="http://www.python.org/doc/2.5.2/lib/typesseq-strings.html" rel="nofollow">the <code>%</code> operator</a> or <a href="http://docs.python.org/library/stdtypes.html#str.format" rel="nofollow"><code>str.format</code></a> to format strings:</p> <p>For example:</p> <pre><code>&gt;&gt;&g...
1
2009-07-27T08:09:46Z
[ "python", "ipython" ]
How do I control number formatting in the python interpreter?
1,187,000
<p>I often use the python interpreter for doing quick numerical calculations and would like all numerical results to be automatically printed using, e.g., exponential notation. Is there a way to set this for the entire session?</p> <p>For example, I want:</p> <pre><code>&gt;&gt;&gt; 1.e12 1.0e+12 </code></pre> <p>n...
2
2009-07-27T08:06:00Z
1,187,029
<p>Hm... It's not a 100% solution, but this have come to my mind...</p> <p>How about defining a subclass of float which would have an overridden <code>__str__</code> method (to print with the exp notation). And then you would have to wrap all the expressions with object construction of this class). It would be a bit s...
1
2009-07-27T08:17:41Z
[ "python", "ipython" ]
How do I control number formatting in the python interpreter?
1,187,000
<p>I often use the python interpreter for doing quick numerical calculations and would like all numerical results to be automatically printed using, e.g., exponential notation. Is there a way to set this for the entire session?</p> <p>For example, I want:</p> <pre><code>&gt;&gt;&gt; 1.e12 1.0e+12 </code></pre> <p>n...
2
2009-07-27T08:06:00Z
1,187,067
<p>Create a Python script called whatever you want (say <code>mystartup.py</code>) and then set an environment variable <code>PYTHONSTARTUP</code> to the path of this script. Python will then load this script on startup of an interactive session (but not when running scripts). In this script, define a function similar ...
4
2009-07-27T08:31:41Z
[ "python", "ipython" ]
How do I control number formatting in the python interpreter?
1,187,000
<p>I often use the python interpreter for doing quick numerical calculations and would like all numerical results to be automatically printed using, e.g., exponential notation. Is there a way to set this for the entire session?</p> <p>For example, I want:</p> <pre><code>&gt;&gt;&gt; 1.e12 1.0e+12 </code></pre> <p>n...
2
2009-07-27T08:06:00Z
1,187,309
<p>Building on Dave Webb's hint above. You can of course set the precision if you like ("%.3e") and perhaps override writelines if needed.</p> <pre><code>import os import sys class ExpFloatFileObject: def write(self, s): try: s = "%e"%float(s) except ValueError: pass ...
1
2009-07-27T09:45:13Z
[ "python", "ipython" ]
In Python, how to tell if being called by exception handling code?
1,187,102
<p>I would like to write a function in Python (2.6) that can determine if it is being called from exception handling code somewhere up the stack.</p> <p>This is for a specialized logging use. In python's <code>logging</code> module, the caller has to explicitly specify that exception information should be logged (eith...
2
2009-07-27T08:40:55Z
1,187,130
<p>If you clear the exception using <code>sys.exc_clear</code> in your exception handlers, then <code>sys.exc_info</code> should work for you. For example: If you run the following script:</p> <pre><code>import sys try: 1 / 0 except: print sys.exc_info() sys.exc_clear() print sys.exc_info() </code></pre> ...
2
2009-07-27T08:48:21Z
[ "python", "exception" ]
In Python, how to tell if being called by exception handling code?
1,187,102
<p>I would like to write a function in Python (2.6) that can determine if it is being called from exception handling code somewhere up the stack.</p> <p>This is for a specialized logging use. In python's <code>logging</code> module, the caller has to explicitly specify that exception information should be logged (eith...
2
2009-07-27T08:40:55Z
1,187,484
<p>Like everything in Python, an exception is an object. Therefore, you could keep a (weak!) reference to the last exception handled and then use <code>sys.exc_info()</code>. Note: in case of multithreading code, you may have issues with this approach. And there could be other corner cases as well.</p> <p>However, <a ...
0
2009-07-27T10:29:42Z
[ "python", "exception" ]
How to install a module as an egg under IronPython?
1,187,110
<p>Maybe, it is a stupid question but I can't use python eggs with IronPython.</p> <p>I would like to test with IronPython 2.0.2 one module that I've developped. This modules is pure python. It works ok with python 2.6 and is installed as a python egg thanks to setuptools.</p> <p>I thought that the process for instal...
2
2009-07-27T08:43:54Z
1,187,165
<p>AFAIK it's still not possible - it's work in progress. See <a href="http://ironpython-urls.blogspot.com/2009/01/jeff-hardy-django-zlib-and-easyinstall.html" rel="nofollow">this post</a>, for example. IronPython's main strength is in integration with the .NET ecosystem - it's not a drop-in replacement for CPython. Se...
1
2009-07-27T08:56:12Z
[ "python", "ironpython", "egg" ]
How to check if some process is running in task manager with python
1,187,264
<p>I have one function in python which should start running when some process (eg. proc.exe) showed up in tasks manager.<br> How can I monitor processes running in tasks manager with python?</p>
4
2009-07-27T09:26:20Z
1,187,338
<p>here is something, I've adapted from <a href="http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx?mfr=true">microsoft</a></p> <pre> import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(str...
10
2009-07-27T09:54:04Z
[ "python", "process" ]
How to check if some process is running in task manager with python
1,187,264
<p>I have one function in python which should start running when some process (eg. proc.exe) showed up in tasks manager.<br> How can I monitor processes running in tasks manager with python?</p>
4
2009-07-27T09:26:20Z
7,180,235
<p>Try the WMI module: <a href="http://timgolden.me.uk/python/wmi/cookbook.html" rel="nofollow">http://timgolden.me.uk/python/wmi/cookbook.html</a></p>
0
2011-08-24T18:13:32Z
[ "python", "process" ]
How to resize svg image file using librsvg Python binding
1,187,358
<p>When rasterizing svg file, I would like to be able to set width and height for the resulting png file. With the following code, only the canvas is set to the desired width and height, the actual image content with the original svg file dimension is rendered in the top left corner on the (500, 600) canvas.</p> <pre...
3
2009-07-27T10:00:20Z
1,187,406
<p>There is a <a href="http://library.gnome.org/devel/rsvg/stable/rsvg-Core-API.html#rsvg-handle-set-size-callback" rel="nofollow">resize function</a> in librsvg, but it is deprecated.</p> <p>Set up a <a href="http://cairographics.org/manual/cairo-Transformations.html#cairo-scale" rel="nofollow">scale matrix</a> in Ca...
6
2009-07-27T10:12:28Z
[ "python", "cairo", "librsvg" ]
How to resize svg image file using librsvg Python binding
1,187,358
<p>When rasterizing svg file, I would like to be able to set width and height for the resulting png file. With the following code, only the canvas is set to the desired width and height, the actual image content with the original svg file dimension is rendered in the top left corner on the (500, 600) canvas.</p> <pre...
3
2009-07-27T10:00:20Z
26,133,667
<p>This is the code that works for me. It implements the answer by Luper above:</p> <pre><code>import rsvg import cairo # Load the svg data svg_xml = open('topthree.svg', 'r') svg = rsvg.Handle() svg.write(svg_xml.read()) svg.close() # Prepare the Cairo context img = cairo.ImageSurface(cairo.FORMAT_ARGB32, WI...
2
2014-10-01T03:30:09Z
[ "python", "cairo", "librsvg" ]
How to make the program run again after unexpected exit in Python?
1,187,653
<p>I'm writing an IRC bot in Python, due to the alpha nature of it, it will likely get unexpected errors and exit.</p> <p>What's the techniques that I can use to make the program run again?</p>
1
2009-07-27T11:29:23Z
1,187,671
<p>The easiest way is to catch errors, and close the old and open a new instance of the program when you do catch em.</p> <p>Note that it will not always work (in cases it stops working without throwing an error).</p>
0
2009-07-27T11:34:22Z
[ "python", "irc" ]
How to make the program run again after unexpected exit in Python?
1,187,653
<p>I'm writing an IRC bot in Python, due to the alpha nature of it, it will likely get unexpected errors and exit.</p> <p>What's the techniques that I can use to make the program run again?</p>
1
2009-07-27T11:29:23Z
1,187,733
<p>You can create wrapper using subprocess(<a href="http://docs.python.org/library/subprocess.html" rel="nofollow">http://docs.python.org/library/subprocess.html</a>) which will spawn your application as a child process and track it's execution.</p>
1
2009-07-27T11:49:31Z
[ "python", "irc" ]
How to make the program run again after unexpected exit in Python?
1,187,653
<p>I'm writing an IRC bot in Python, due to the alpha nature of it, it will likely get unexpected errors and exit.</p> <p>What's the techniques that I can use to make the program run again?</p>
1
2009-07-27T11:29:23Z
1,187,787
<p>You can use <code>sys.exit()</code> to tell that the program exited abnormally (generally, 1 is returned in case of error).</p> <p>Your Python script could look something like this:</p> <pre><code>import sys def main(): # ... if __name__ == '__main__': try: main() except Exception as e: ...
5
2009-07-27T11:59:31Z
[ "python", "irc" ]
To set up environmental variables for a Python web application
1,187,716
<p>I need to set up the following env variables such that I can a database program which use PostgreSQL</p> <pre><code>export PGDATA="/home/masi/postgres/var" export PGPORT="12428" </code></pre> <p>I know that the problem may be solved by adding the files to .zshrc. However, I am not sure whether it is the right way ...
1
2009-07-27T11:46:30Z
1,188,055
<p>Put this somewhere in the main page of your app :</p> <pre><code>import os os.environ["PGDATA"] = "/home/masi/postgres/var" os.environ["PGPORT"] = 12428 </code></pre> <p>however, isn't there a better way to set that in the framework you use?</p>
2
2009-07-27T13:02:29Z
[ "python", "postgresql" ]
To set up environmental variables for a Python web application
1,187,716
<p>I need to set up the following env variables such that I can a database program which use PostgreSQL</p> <pre><code>export PGDATA="/home/masi/postgres/var" export PGPORT="12428" </code></pre> <p>I know that the problem may be solved by adding the files to .zshrc. However, I am not sure whether it is the right way ...
1
2009-07-27T11:46:30Z
1,192,987
<p>You only need to set the PGDATA variable in the script that starts the <em>server</em>. The client only cares about the port.</p> <p>You do have to set the port value if you must run it on a non-standard port. I assume you have a good reason to not just run it on the default port? If you do run it on the default po...
3
2009-07-28T09:32:30Z
[ "python", "postgresql" ]
Empty XML element handling in Python
1,187,718
<p>I'm puzzled by minidom parser handling of empty element, as shown in following code section.</p> <pre><code>import xml.dom.minidom doc = xml.dom.minidom.parseString('&lt;value&gt;&lt;/value&gt;') print doc.firstChild.nodeValue.__repr__() # Out: None print doc.firstChild.toxml() # Out: &lt;value/&gt; doc = xml.dom...
2
2009-07-27T11:46:32Z
1,188,437
<pre><code>value = thing.firstChild.nodeValue or '' </code></pre>
1
2009-07-27T14:21:13Z
[ "python", "xml", "string" ]
Empty XML element handling in Python
1,187,718
<p>I'm puzzled by minidom parser handling of empty element, as shown in following code section.</p> <pre><code>import xml.dom.minidom doc = xml.dom.minidom.parseString('&lt;value&gt;&lt;/value&gt;') print doc.firstChild.nodeValue.__repr__() # Out: None print doc.firstChild.toxml() # Out: &lt;value/&gt; doc = xml.dom...
2
2009-07-27T11:46:32Z
1,188,448
<p>Xml spec does not distinguish these two cases.</p>
1
2009-07-27T14:22:57Z
[ "python", "xml", "string" ]
Empty XML element handling in Python
1,187,718
<p>I'm puzzled by minidom parser handling of empty element, as shown in following code section.</p> <pre><code>import xml.dom.minidom doc = xml.dom.minidom.parseString('&lt;value&gt;&lt;/value&gt;') print doc.firstChild.nodeValue.__repr__() # Out: None print doc.firstChild.toxml() # Out: &lt;value/&gt; doc = xml.dom...
2
2009-07-27T11:46:32Z
1,190,379
<p>Cracking open xml.dom.minidom and searching for "/>", we find this:</p> <pre><code># Method of the Element(Node) class. def writexml(self, writer, indent="", addindent="", newl=""): # [snip] if self.childNodes: writer.write("&gt;%s"%(newl)) for node in self.childNodes: node.write...
3
2009-07-27T20:17:32Z
[ "python", "xml", "string" ]
How to exit from Python without traceback?
1,187,970
<p>I would like to know how to I exit from Python without having an traceback dump on the output. </p> <p>I still want want to be able to return an error code but I do not want to display the traceback log.</p> <p>I want to be able to exit using <code>exit(number)</code> without trace but in case of an Exception (not...
156
2009-07-27T12:44:15Z
1,187,975
<pre><code>import sys sys.exit(1) </code></pre>
30
2009-07-27T12:45:38Z
[ "python", "exit", "traceback" ]
How to exit from Python without traceback?
1,187,970
<p>I would like to know how to I exit from Python without having an traceback dump on the output. </p> <p>I still want want to be able to return an error code but I do not want to display the traceback log.</p> <p>I want to be able to exit using <code>exit(number)</code> without trace but in case of an Exception (not...
156
2009-07-27T12:44:15Z
1,187,976
<p>something like <code>import sys; sys.exit(0)</code> ?</p>
6
2009-07-27T12:45:44Z
[ "python", "exit", "traceback" ]
How to exit from Python without traceback?
1,187,970
<p>I would like to know how to I exit from Python without having an traceback dump on the output. </p> <p>I still want want to be able to return an error code but I do not want to display the traceback log.</p> <p>I want to be able to exit using <code>exit(number)</code> without trace but in case of an Exception (not...
156
2009-07-27T12:44:15Z
1,188,086
<p>You are presumably encountering an exception and the program is exiting because of this (with a traceback). The first thing to do therefore is to catch that exception, before exiting cleanly (maybe with a message, example given).</p> <p>Try something like this in your <code>main</code> routine:</p> <pre><code>imp...
182
2009-07-27T13:10:40Z
[ "python", "exit", "traceback" ]