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 |
|---|---|---|---|---|---|---|---|---|---|
Matching text within P tags in HTML | 923,472 | <p>I'd like to match the contents within each paragraph in html using a python regular expression. These paragraphs always have BR tags inside them like so:</p>
<pre><code><p class="thisClass">this is nice <br /><br /> isn't it?</p>
</code></pre>
<p>I'm currently using this pattern:</p>
<pre>... | 2 | 2009-05-28T22:16:13Z | 923,530 | <p>It turns out the answer was to include re.S as a flag which allows the "." character to match newlines as well.</p>
<pre><code>pattern = re.compile('<p class=\"thisClass\">(.*?)<\/p>', re.S)
</code></pre>
<p>This works perfectly.</p>
| 3 | 2009-05-28T22:31:34Z | [
"python",
"html",
"regex"
] |
python - match on array return value | 923,553 | <p>I want to do a functional like pattern match to get the first two elements, and then the rest of an array return value.</p>
<p>For example, assume that perms(x) returns a list of values, and I want to do this:</p>
<pre><code>seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
</code></pre>
<p>Of course I can shorte... | 2 | 2009-05-28T22:37:42Z | 923,562 | <p>You can do it in Python 3 like this:</p>
<pre><code>(a, b, *rest) = seq
</code></pre>
<p>See the <a href="http://www.python.org/dev/peps/pep-3132/" rel="nofollow">extended iterable unpacking PEP</a> for more details.</p>
| 6 | 2009-05-28T22:41:11Z | [
"python",
"list"
] |
python - match on array return value | 923,553 | <p>I want to do a functional like pattern match to get the first two elements, and then the rest of an array return value.</p>
<p>For example, assume that perms(x) returns a list of values, and I want to do this:</p>
<pre><code>seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
</code></pre>
<p>Of course I can shorte... | 2 | 2009-05-28T22:37:42Z | 923,571 | <p>For Python 2, I know you can do it with a function:</p>
<pre><code>>>> def getValues(a, b, *more):
return a, b, more
>>> seq = [1,2,3,4,5]
>>> a, b, more = getValues(*seq)
>>> a
1
>>> b
2
>>> more
(3, 4, 5)
</code></pre>
<p>But not sure if there's any way ... | 2 | 2009-05-28T22:43:54Z | [
"python",
"list"
] |
python - match on array return value | 923,553 | <p>I want to do a functional like pattern match to get the first two elements, and then the rest of an array return value.</p>
<p>For example, assume that perms(x) returns a list of values, and I want to do this:</p>
<pre><code>seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
</code></pre>
<p>Of course I can shorte... | 2 | 2009-05-28T22:37:42Z | 923,574 | <p>In python 2, your question is very close to an answer already:</p>
<pre><code>a, b, more = (seq[0], seq[1], seq[2:])
</code></pre>
<p>or:</p>
<pre><code>(a, b), more = (seq[0:2], seq[2:])
</code></pre>
| 3 | 2009-05-28T22:44:22Z | [
"python",
"list"
] |
python - match on array return value | 923,553 | <p>I want to do a functional like pattern match to get the first two elements, and then the rest of an array return value.</p>
<p>For example, assume that perms(x) returns a list of values, and I want to do this:</p>
<pre><code>seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
</code></pre>
<p>Of course I can shorte... | 2 | 2009-05-28T22:37:42Z | 975,403 | <p>Very nice, thanks.</p>
<p>The suggestions where one dissects the array on the fight-hand side don't work so well for me, as I actually wanted to pattern match on the returns from a generator expression.</p>
<p>for (a, b, more) in perms(seq): ...</p>
<p>I like the P3 solution, but have to wait for Komodo to suppo... | 0 | 2009-06-10T12:59:16Z | [
"python",
"list"
] |
Python Environment Variables in Windows? | 923,586 | <p>I'm developing a script that runs a program with other scripts over and over for testing purposes.</p>
<p>How it currently works is I have one Python script which I launch. That script calls the program and loads the other scripts. It kills the program after 60 seconds to launch the program again with the next scri... | 0 | 2009-05-28T22:48:17Z | 923,787 | <p>You could use <a href="http://docs.python.org/library/atexit.html" rel="nofollow">atexit</a> to write a small file (flag.txt) when script1.py exits. mainscript.py could regularly be checking for the existence of flag.txt and when it finds it, will kill program.exe and exit.</p>
<p>Edit:
I've set persistent environ... | 1 | 2009-05-28T23:55:33Z | [
"python",
"windows",
"testing",
"environment-variables"
] |
Python Environment Variables in Windows? | 923,586 | <p>I'm developing a script that runs a program with other scripts over and over for testing purposes.</p>
<p>How it currently works is I have one Python script which I launch. That script calls the program and loads the other scripts. It kills the program after 60 seconds to launch the program again with the next scri... | 0 | 2009-05-28T22:48:17Z | 924,069 | <p>This seems like a perfect use case for sockets, in particular <a href="http://docs.python.org/library/asyncore.html" rel="nofollow">asyncore</a>.</p>
| 0 | 2009-05-29T01:54:30Z | [
"python",
"windows",
"testing",
"environment-variables"
] |
Python Environment Variables in Windows? | 923,586 | <p>I'm developing a script that runs a program with other scripts over and over for testing purposes.</p>
<p>How it currently works is I have one Python script which I launch. That script calls the program and loads the other scripts. It kills the program after 60 seconds to launch the program again with the next scri... | 0 | 2009-05-28T22:48:17Z | 2,318,893 | <p>You cannot use environment variables in this way. As you have discovered it is not persistent after the setting application completes</p>
| 0 | 2010-02-23T14:36:00Z | [
"python",
"windows",
"testing",
"environment-variables"
] |
When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation | 923,680 | <p>Scenario:</p>
<p>I have a php page in which I call a python script. </p>
<p>Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file.</p>
<p>Python script when run through php, doesn't do either.</p>
<p>Elaboration:</p>
<p>I use a simple system ... | 1 | 2009-05-28T23:21:44Z | 923,761 | <p>Check that the user the python script is running is has write permissions in CWD. Also, try shell_exec() or passthru() to call the script, rather than system().</p>
| 0 | 2009-05-28T23:48:39Z | [
"php",
"python",
"linux"
] |
When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation | 923,680 | <p>Scenario:</p>
<p>I have a php page in which I call a python script. </p>
<p>Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file.</p>
<p>Python script when run through php, doesn't do either.</p>
<p>Elaboration:</p>
<p>I use a simple system ... | 1 | 2009-05-28T23:21:44Z | 924,481 | <p><strong>A permission problem</strong> is most likely the case.</p>
<p>If apache is running as <code>apache</code>, then it will not have access to write to a file unless</p>
<ol>
<li>The file is owned by <code>apache</code></li>
<li>The file is in the group <code>apache</code> and group writable</li>
<li>The file ... | 1 | 2009-05-29T05:14:54Z | [
"php",
"python",
"linux"
] |
When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation | 923,680 | <p>Scenario:</p>
<p>I have a php page in which I call a python script. </p>
<p>Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file.</p>
<p>Python script when run through php, doesn't do either.</p>
<p>Elaboration:</p>
<p>I use a simple system ... | 1 | 2009-05-28T23:21:44Z | 925,872 | <p>I bet your py script has some bug which couses it to break when called from inside PHP.
Try</p>
<pre><code>passthru('/usr/python/bin/python3 ../cgi-bin/tabular.py 1 2>&1');
</code></pre>
<p>to investigate (notice <strong>2>&1</strong> which causess stderr to be written to stdout).</p>
| 2 | 2009-05-29T13:09:39Z | [
"php",
"python",
"linux"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,703 | <p>nohup for starters (at least on *nix boxes) - and redirect the output to some log file where you can come back and monitor it of course.</p>
| 3 | 2009-05-28T23:28:15Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,708 | <p>So now that I understand what you really want, I think the best solution would be to create a lite daemon to run whatever process you want. The daemon could then dump the output to a log file so if it takes a shorter amount of time to run than you expect, you can still get the output. This would be more reliable tha... | 3 | 2009-05-28T23:29:23Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,719 | <p>As @Gandalf mentions, you'll need <code>nohup</code> in addition to the backgrounding &, or the process will be SIGKILLed when the login session terminates. If you redirect your output to a log file, you'll be able to look at it later easily (and not have to install screen on all your machines).</p>
| 0 | 2009-05-28T23:31:34Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,720 | <p>Most commercial products install an "Agent" on the remote machines.</p>
<p>In the linux world, you have numerous such agents. rexec and rlogin and rsh all jump to mind.</p>
<p>These are all clients that communication with daemons running on the remote hosts.</p>
<p>If you don't want to use these agents, you can ... | 0 | 2009-05-28T23:32:11Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,726 | <p>For a quick, lightweight solution you can't beat <a href="http://www.gnu.org/software/screen/" rel="nofollow">screen</a>. If you want to automate things completely it makes sense to set up the process to <strong>run as a daemon</strong> and write to the system log using <code>syslog</code>. Your system may have a ... | 1 | 2009-05-28T23:34:40Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 923,729 | <p>If you want a script to continue after you leave, you could call it through "nohup" (man nohup). You could also put code in the script you call to have it daemonize itself... it forks, makes the child into a daemon, and then exits. A quick search turned up: <a href="http://code.activestate.com/recipes/278731/" rel... | 1 | 2009-05-28T23:35:58Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 926,177 | <p>Instead of screen, since it's for a single process, I would suggest its lightweight sibling, <a href="http://dtach.sourceforge.net/" rel="nofollow">dtach</a>.</p>
<p>For a fairly complete recipe of dæmonizing a process in Python, see the <a href="http://code.activestate.com/recipes/278731/" rel="nofollow">Creating... | 0 | 2009-05-29T14:11:33Z | [
"python",
"testing",
"scripting"
] |
How to start a process on a remote server, disconnect, then later collect output? | 923,691 | <p>I am writing automation code in python to test the behavior of a network application. As such, my code needs to be able to start a process/script (say, tcpdump or a python script) on a server in the network, disconnect, run other processes and then later return and shutdown/evaluate the process started earlier. My... | 1 | 2009-05-28T23:25:14Z | 20,889,031 | <p>If you are using python to run the automation... I would attempt to automate everything using paramiko. It's a versatile ssh library for python. Instead of going back to the output, you could collect multiple lines of output live and then disconnect when you no longer need the process and let ssh do the killing fo... | 0 | 2014-01-02T18:09:41Z | [
"python",
"testing",
"scripting"
] |
Python taskbar applet | 923,701 | <p>I want to code up a panel that will be used both in Linux and Windows. Ideally it will be written in Python using PyQT.</p>
<p>What I've found so far is the QSystemTrayIcon widget, and while that is quite useful, that's not quite what I'm looking for. That widget lets you attach a menu to the left and right clicks ... | 4 | 2009-05-28T23:28:09Z | 923,757 | <p>Widgets inside the GNOME panel are called applets, and to my knowledge it's not possible to write them with anything but Gtk, since you have to use the respective GNOME library libpanel-applet (in either C, C++ or Python). </p>
<p>System tray icons are different, because they only allow icons to be displayed inside... | 5 | 2009-05-28T23:44:38Z | [
"python",
"qt4",
"pyqt"
] |
Python taskbar applet | 923,701 | <p>I want to code up a panel that will be used both in Linux and Windows. Ideally it will be written in Python using PyQT.</p>
<p>What I've found so far is the QSystemTrayIcon widget, and while that is quite useful, that's not quite what I'm looking for. That widget lets you attach a menu to the left and right clicks ... | 4 | 2009-05-28T23:28:09Z | 924,771 | <p>Sounds like you are looking for <a href="http://www.youtube.com/watch?v=DzraMSNvhQI" rel="nofollow">Plasmoids</a>, which can be integrated into the task bar. There are a Plasmoid tutorials in <a href="http://techbase.kde.org/Development/Tutorials/Plasma/GettingStarted" rel="nofollow">C++</a> and <a href="http://tech... | -1 | 2009-05-29T07:16:27Z | [
"python",
"qt4",
"pyqt"
] |
How do I call template defs with names only known at runtime in the Python template language Mako? | 923,837 | <p>I am trying to find a way of calling def templates determined by the data available in the context.</p>
<p><strong>Edit:</strong> A simpler instance of the same question. </p>
<p>It is possible to emit the value of an object in the context:</p>
<pre><code># in python
ctx = Context(buffer, website='stackoverflow.c... | 0 | 2009-05-29T00:10:25Z | 924,049 | <p>How about if you first generate the template (from another template :), and then run that with your data?</p>
| 0 | 2009-05-29T01:48:31Z | [
"python",
"templates",
"mako"
] |
How do I call template defs with names only known at runtime in the Python template language Mako? | 923,837 | <p>I am trying to find a way of calling def templates determined by the data available in the context.</p>
<p><strong>Edit:</strong> A simpler instance of the same question. </p>
<p>It is possible to emit the value of an object in the context:</p>
<pre><code># in python
ctx = Context(buffer, website='stackoverflow.c... | 0 | 2009-05-29T00:10:25Z | 930,404 | <p>Takes some playing with mako's <code>local</code> namespace, but here's a working example:</p>
<pre><code>from mako.template import Template
from mako.runtime import Context
from StringIO import StringIO
mytemplate = Template("""
<%def name='html_link(w)'>
<a href='http://${w}'>${w}</a>
</%def... | 1 | 2009-05-30T19:33:33Z | [
"python",
"templates",
"mako"
] |
Python RegEx - Getting multiple pieces of information out of a string | 924,127 | <p>I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file an... | 2 | 2009-05-29T02:18:56Z | 924,137 | <p>You can use <code>|</code> to match any one of various possible things, and <code>re.findall</code> to get all non-overlapping matches to some RE.</p>
| 5 | 2009-05-29T02:25:19Z | [
"python",
"regex"
] |
Python RegEx - Getting multiple pieces of information out of a string | 924,127 | <p>I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file an... | 2 | 2009-05-29T02:18:56Z | 924,146 | <p>Could it be as simple as "SERVICE NOTIFICATION" in your pattern doesn't match "SERVICE ALERT" in your example?</p>
| 0 | 2009-05-29T02:29:27Z | [
"python",
"regex"
] |
Python RegEx - Getting multiple pieces of information out of a string | 924,127 | <p>I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file an... | 2 | 2009-05-29T02:18:56Z | 924,166 | <p>The question is a bit confusing. But you don't need to do <em>everything</em> with regular expressions, there are some good plain old string functions you might want to try, like 'split'.</p>
<p>This version will also refrain from loading the entire file in memory at once, and it will close the file even when an e... | 1 | 2009-05-29T02:33:57Z | [
"python",
"regex"
] |
Python RegEx - Getting multiple pieces of information out of a string | 924,127 | <p>I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file an... | 2 | 2009-05-29T02:18:56Z | 924,173 | <p>If you are looking to split out those particular parts of the line then.</p>
<p>Something along the lines of:</p>
<pre><code>match = re.match(r'^\[(\d+)\] (.*?): (.*?);.*?;(.*?);',line)
</code></pre>
<p>Should give each of those parts in their respective index in groups.</p>
| 1 | 2009-05-29T02:38:31Z | [
"python",
"regex"
] |
Python RegEx - Getting multiple pieces of information out of a string | 924,127 | <p>I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file an... | 2 | 2009-05-29T02:18:56Z | 924,205 | <p>You can use more than one group at a time, e.g.:</p>
<pre><code>import re
logstring = '[1242248375] SERVICE ALERT: myhostname.com;DNS: Recursive;CRITICAL;SOFT;1;CRITICAL - Plugin timed out while executing system call'
exp = re.compile('^\[(\d+)\] ([A-Z ]+): ([A-Za-z0-9.\-]+);[^;]+;([A-Z]+);')
m = exp.search(logstr... | 2 | 2009-05-29T02:55:00Z | [
"python",
"regex"
] |
Capturing Implicit Signals of Interest in Django | 924,530 | <p>To set the background: I'm interested in:</p>
<ul>
<li>Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache</li>
</ul>
<p>Let's say, for instance, my site sells books. As a user browses around my site I'd lik... | 0 | 2009-05-29T05:34:24Z | 924,611 | <p><em>What approach would you suggest? (doesn't have to be one of the above) Thanks!</em></p>
<p>hmmmm ...this like been in a four walled room with only one door and saying i want to get out of room but not through the only door...</p>
<p>There was an article i was reading sometime back (can't get the link now) that... | 1 | 2009-05-29T06:08:49Z | [
"python",
"mysql",
"django",
"collaborative-filtering"
] |
Capturing Implicit Signals of Interest in Django | 924,530 | <p>To set the background: I'm interested in:</p>
<ul>
<li>Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache</li>
</ul>
<p>Let's say, for instance, my site sells books. As a user browses around my site I'd lik... | 0 | 2009-05-29T05:34:24Z | 924,649 | <p>Either a document datastore (mongo/couchdb), or a persistent key value store (tokyodb, memcachedb etc) may be explored. </p>
<p>No definite recommendations from me as the final solution depends on multiple factors - load, your willingness to learn/deploy a new technology, size of the data...</p>
| 1 | 2009-05-29T06:22:03Z | [
"python",
"mysql",
"django",
"collaborative-filtering"
] |
Capturing Implicit Signals of Interest in Django | 924,530 | <p>To set the background: I'm interested in:</p>
<ul>
<li>Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache</li>
</ul>
<p>Let's say, for instance, my site sells books. As a user browses around my site I'd lik... | 0 | 2009-05-29T05:34:24Z | 924,944 | <p>Seems to me that one approach could be to use memcached to keep the counter, but have a cron running regularly to store the value from memcached to the db or disk. That way you'd get all the performance of memcached, but in the case of a crash you wouldn't lose more than a couple of minutes' data.</p>
| 0 | 2009-05-29T08:20:00Z | [
"python",
"mysql",
"django",
"collaborative-filtering"
] |
Capturing Implicit Signals of Interest in Django | 924,530 | <p>To set the background: I'm interested in:</p>
<ul>
<li>Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache</li>
</ul>
<p>Let's say, for instance, my site sells books. As a user browses around my site I'd lik... | 0 | 2009-05-29T05:34:24Z | 925,420 | <p>If this data is not an unimportant statistic that might or might not be available I'd suggest taking the simple approach and using a model. It will surely hit the database everytime. </p>
<p>Unless you are absolutely positively sure these queries <strong>are</strong> actually degrading overall experience there is n... | 3 | 2009-05-29T10:50:57Z | [
"python",
"mysql",
"django",
"collaborative-filtering"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,719 | <p>You can <em>treat</em> your text file as a python module and load it dynamically using <a href="https://docs.python.org/2/library/imp.html#imp.load_source" rel="nofollow"><code>imp.load_source</code></a>:</p>
<pre><code>import imp
imp.load_source( name, pathname[, file])
</code></pre>
<p>Example:</p>
<pre><code>... | 13 | 2009-05-29T06:56:12Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,723 | <p>Use ConfigParser.</p>
<p>Your config:</p>
<pre><code>[myvars]
var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>Your python code:</p>
<pre><code>import ConfigParser
config = ConfigParser.ConfigParser()
config.read("config.ini")
var_a = config.get("myvars", "var_a")
var_b = config.get("myvars", "var_b")
va... | 18 | 2009-05-29T06:57:58Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,835 | <p>Load your file with <a href="http://docs.python.org/library/json.html" rel="nofollow">JSON</a> or <a href="http://pyyaml.org/wiki/PyYAML" rel="nofollow">PyYAML</a> into a dictionary <code>the_dict</code> (see doc for JSON or PyYAML for this step, both can store data type) and add the dictionary to your globals dicti... | 11 | 2009-05-29T07:42:27Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,866 | <blockquote>
<p>But what i'll love is to refer to the variable direclty, as i declared it in the python script..</p>
</blockquote>
<p>Assuming you're happy to change your syntax slightly, just use python and import the "config" module.</p>
<pre><code># myconfig.py:
var_a = 'home'
var_b = 'car'
var_c = 15.5
</code>... | 39 | 2009-05-29T07:54:55Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,870 | <p>What you want appear to want is the following, but this is <strong>NOT RECOMMENDED</strong>:</p>
<pre><code>>>> for line in open('dangerous.txt'):
... exec('%s = %s' % tuple(line.split(':', 1)))
...
>>> var_a
'home'
</code></pre>
<p>This creates somewhat similar behavior to PHP's <a href="ht... | 1 | 2009-05-29T07:55:57Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 924,967 | <p>How reliable is your format? If the seperator is always exactly ': ', the following works. If not, a comparatively simple regex should do the job.</p>
<p>As long as you're working with fairly simple variable types, Python's eval function makes persisting variables to files surprisingly easy.</p>
<p>(The below give... | 2 | 2009-05-29T08:27:04Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 9,816,149 | <p>Suppose that you have a file Called "test.txt" with:</p>
<pre><code>a=1.251
b=2.65415
c=3.54
d=549.5645
e=4684.65489
</code></pre>
<p>And you want to find a variable (a,b,c,d or e):</p>
<pre><code>ffile=open('test.txt','r').read()
variable=raw_input('Wich is the variable you are looking for?\n')
ini=ffile.find(... | 3 | 2012-03-22T03:43:22Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 11,799,592 | <p>The other solutions posted here didn't work for me, because: </p>
<ul>
<li>i just needed parameters from a file for a normal script</li>
<li><code>import *</code> didn't work for me, as i need a way to override them by choosing another file</li>
<li>Just a file with a dict wasn't fine, as I needed comments in it.</... | 3 | 2012-08-03T16:21:55Z | [
"python",
"json",
"variables",
"text-files"
] |
Best way to retrieve variable values from a text file - Python - Json | 924,700 | <p>Referring on <a href="http://stackoverflow.com/questions/868112/loading-files-into-variables-in-python">this question</a>, I have a similar -but not the same- problem..</p>
<p>On my way, I'll have some text file, structured like:</p>
<pre><code>var_a: 'home'
var_b: 'car'
var_c: 15.5
</code></pre>
<p>And I need th... | 20 | 2009-05-29T06:48:30Z | 35,526,906 | <p>hbn's answer won't work out of the box if the file to load <a href="http://stackoverflow.com/q/1260792/812102">is in a subdirectory</a> or <a href="http://stackoverflow.com/q/8350853/812102">is named with dashes</a>.</p>
<p>In such a case you may consider this alternative :</p>
<pre><code>exec open(myconfig.py).r... | 0 | 2016-02-20T17:55:43Z | [
"python",
"json",
"variables",
"text-files"
] |
How can I remove the top and right axis in matplotlib? | 925,024 | <p>Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:</p>
<pre><code>+------+ |
| | |
| | ---> |
| | |
+------+ +-------
</code></pre>
<p>This should be easy, but I can't find the necessary options in the docs.</p>
| 45 | 2009-05-29T08:45:12Z | 925,141 | <p>[edit] matplotlib in now (2013-10) on version 1.3.0 which includes this</p>
<p>That ability was actually just added, and you need the Subversion version for it. You can see the example code <a href="http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html">here</a>.</p>
<p>I am just updating to say... | 24 | 2009-05-29T09:21:20Z | [
"python",
"matplotlib"
] |
How can I remove the top and right axis in matplotlib? | 925,024 | <p>Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:</p>
<pre><code>+------+ |
| | |
| | ---> |
| | |
+------+ +-------
</code></pre>
<p>This should be easy, but I can't find the necessary options in the docs.</p>
| 45 | 2009-05-29T08:45:12Z | 925,289 | <p>If you don't need ticks and such (e.g. for plotting qualitative illustrations) you could also use this quick workaround: </p>
<p>Make the axis invisible (e.g. with <code>plt.gca().axison = False</code>) and then draw them manually with <code>plt.arrow</code>.</p>
| 6 | 2009-05-29T10:06:22Z | [
"python",
"matplotlib"
] |
How can I remove the top and right axis in matplotlib? | 925,024 | <p>Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:</p>
<pre><code>+------+ |
| | |
| | ---> |
| | |
+------+ +-------
</code></pre>
<p>This should be easy, but I can't find the necessary options in the docs.</p>
| 45 | 2009-05-29T08:45:12Z | 8,011,585 | <p>Alternatively, this</p>
<pre><code>def simpleaxis(ax):
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
</code></pre>
<p>seems to achieve the same effect on an axis without losing rotated label support.</p>
<p>(Matplo... | 41 | 2011-11-04T15:20:04Z | [
"python",
"matplotlib"
] |
How can I remove the top and right axis in matplotlib? | 925,024 | <p>Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:</p>
<pre><code>+------+ |
| | |
| | ---> |
| | |
+------+ +-------
</code></pre>
<p>This should be easy, but I can't find the necessary options in the docs.</p>
| 45 | 2009-05-29T08:45:12Z | 27,361,819 | <p>This is the suggested Matplotlib 1.4 solution from the official website <a href="http://matplotlib.org/examples/ticks_and_spines/spines_demo.html">HERE</a>:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
ax = plt.subplot(111)
ax.plot(x, y)
# Hide ... | 16 | 2014-12-08T15:58:27Z | [
"python",
"matplotlib"
] |
How can I remove the top and right axis in matplotlib? | 925,024 | <p>Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:</p>
<pre><code>+------+ |
| | |
| | ---> |
| | |
+------+ +-------
</code></pre>
<p>This should be easy, but I can't find the necessary options in the docs.</p>
| 45 | 2009-05-29T08:45:12Z | 34,714,905 | <p>This is much more rudimentary, but might do the trick:</p>
<p>remove_border()</p>
| 0 | 2016-01-11T05:44:38Z | [
"python",
"matplotlib"
] |
A Python walker that can ignore directories | 925,056 | <p>I need a file system walker that I could instruct to ignore traversing
directories that I want to leave untouched, including all subdirectories
below that branch.
The os.walk and os.path.walk just don't do it.</p>
| 8 | 2009-05-29T08:52:46Z | 925,081 | <p>So I made this home-roles walker function:</p>
<pre><code>import os
from os.path import join, isdir, islink, isfile
def mywalk(top, topdown=True, onerror=None, ignore_list=('.ignore',)):
try:
# Note that listdir and error are globals in this module due
# to earlier import-*.
names = os.... | 1 | 2009-05-29T08:59:52Z | [
"python",
"directory-walk",
"ignore-files"
] |
A Python walker that can ignore directories | 925,056 | <p>I need a file system walker that I could instruct to ignore traversing
directories that I want to leave untouched, including all subdirectories
below that branch.
The os.walk and os.path.walk just don't do it.</p>
| 8 | 2009-05-29T08:52:46Z | 925,287 | <p>It is possible to modify the second element of <a href="http://docs.python.org/library/os.html#module-os"><code>os.walk</code></a>'s return values in-place:</p>
<blockquote>
<p>[...] the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the sub... | 7 | 2009-05-29T10:05:38Z | [
"python",
"directory-walk",
"ignore-files"
] |
A Python walker that can ignore directories | 925,056 | <p>I need a file system walker that I could instruct to ignore traversing
directories that I want to leave untouched, including all subdirectories
below that branch.
The os.walk and os.path.walk just don't do it.</p>
| 8 | 2009-05-29T08:52:46Z | 925,291 | <p>Actually, <code>os.walk</code> may do exactly what you want. Say I have a list (perhaps a set) of directories to ignore in <code>ignore</code>. Then this should work:</p>
<pre><code>def my_walk(top_dir, ignore):
for dirpath, dirnames, filenames in os.walk(top_dir):
dirnames[:] = [
dn for ... | 9 | 2009-05-29T10:06:40Z | [
"python",
"directory-walk",
"ignore-files"
] |
A Python walker that can ignore directories | 925,056 | <p>I need a file system walker that I could instruct to ignore traversing
directories that I want to leave untouched, including all subdirectories
below that branch.
The os.walk and os.path.walk just don't do it.</p>
| 8 | 2009-05-29T08:52:46Z | 8,828,438 | <p>Here's the best and simple solution. </p>
<pre><code>def walk(ignores):
global ignore
path = os.getcwd()
for root, dirs, files in os.walk(path):
for ignore in ignores:
if(ignore in dirs):
dirs.remove(ignore)
print root
print dirs
print files
wa... | 2 | 2012-01-11T23:55:17Z | [
"python",
"directory-walk",
"ignore-files"
] |
Scope, using functions in current module | 925,075 | <p>I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module?</p>
<p>For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to ... | 1 | 2009-05-29T08:58:04Z | 925,089 | <p>A function needs to be defined before it can be called. If you want to have the code that needs to be executed at the top of the file, just define a <code>main</code> function and call it from the bottom:</p>
<pre><code>import sys
def main(args):
pass
# All your other function definitions here
if __name__ ==... | 5 | 2009-05-29T09:04:40Z | [
"python",
"function",
"scope",
"module",
"structure"
] |
Scope, using functions in current module | 925,075 | <p>I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module?</p>
<p>For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to ... | 1 | 2009-05-29T08:58:04Z | 925,358 | <p>If your lookup dict is unchanging, the simplest way is to just make it a module scope variable. ie:</p>
<pre><code>lookup = {
'A' : 'AA',
'B' : 'BB',
...
}
</code></pre>
<p>If you may need to make changes, and later re-initialise it, you can do this in an initialisation function:</p>
<pre><code>def i... | 0 | 2009-05-29T10:32:39Z | [
"python",
"function",
"scope",
"module",
"structure"
] |
Scope, using functions in current module | 925,075 | <p>I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module?</p>
<p>For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to ... | 1 | 2009-05-29T08:58:04Z | 925,361 | <p>Here's a more pythonic ways to do this. There aren't a lot of choices, BTW.</p>
<p>A function <em>must</em> be defined before it can be <em>used</em>. Period. </p>
<p>However, you don't have to strictly order all functions for the compiler's benefit. You merely have to put your execution of the functions last. ... | 1 | 2009-05-29T10:34:29Z | [
"python",
"function",
"scope",
"module",
"structure"
] |
Scope, using functions in current module | 925,075 | <p>I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module?</p>
<p>For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to ... | 1 | 2009-05-29T08:58:04Z | 933,125 | <p>I think that keeping the names in a flat text file, and loading them at runtime would be a good alternative. I try to stick to the lowest level of complexity possible with my data, starting with plain text and working up to a RDMS (I lifted this idea from <a href="http://www.pragprog.com/the-pragmatic-programmer" re... | 0 | 2009-05-31T23:43:14Z | [
"python",
"function",
"scope",
"module",
"structure"
] |
python queue & multiprocessing queue: how they behave? | 925,100 | <p>This sample code works (I can write something in the file):</p>
<pre><code>from multiprocessing import Process, Queue
queue = Queue()
def _printer(self, queue):
queue.put("hello world!!")
def _cmdDisp(self, queue):
f = file("Cmd.log", "w")
print >> f, queue.get()
f.close()
</code></pre>
<p>... | 13 | 2009-05-29T09:08:28Z | 925,241 | <p>For your second example, you already gave the explanation yourself---<code>Queue</code> is a module, which cannot be called.</p>
<p>For the third example: I assume that you use <code>Queue.Queue</code> together with <code>multiprocessing</code>. A <code>Queue.Queue</code> will not be shared between processes. If ... | 31 | 2009-05-29T09:53:20Z | [
"python",
"queue"
] |
Uploading multiple images in Django admin | 925,305 | <p>I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it.</p>
<p>The most user-friendly way I can see would be a file upload form with a JavaS... | 7 | 2009-05-29T10:12:53Z | 925,339 | <p><a href="http://code.google.com/p/django-photologue/">photologue</a> is a feature-rich photo app for django. it e.g. lets you upload galleries as zip files (which in a sense means uploading multiple files at once), automatically creates thumbnails of different custom sizes and can apply effects to images. I used it ... | 8 | 2009-05-29T10:26:07Z | [
"python",
"django",
"image-uploading"
] |
Uploading multiple images in Django admin | 925,305 | <p>I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it.</p>
<p>The most user-friendly way I can see would be a file upload form with a JavaS... | 7 | 2009-05-29T10:12:53Z | 925,590 | <p>You can extend the Admin interface pretty easily using Javascript. There's a <a href="http://www.arnebrodowski.de/blog/507-Add-and-remove-Django-Admin-Inlines-with-JavaScript.html">good article</a> on doing exactly what you want with a bit of jQuery magic.</p>
<p>You would just have to throw all of his code into on... | 9 | 2009-05-29T11:36:35Z | [
"python",
"django",
"image-uploading"
] |
Giving anonymous users the same functionality as registered ones | 925,456 | <p>I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:</p>
<pre><code>class Cart(models.Model):
user = models.OneToOneField(User)
class... | 6 | 2009-05-29T11:00:55Z | 925,465 | <p>I haven't done this before but from reading your description I would simply create a user object when someone needs to do something that requires it. You then send the user a cookie which links to this user object, so if someone comes back (without clearing their cookies) they get the same skeleton user object.</p>... | 9 | 2009-05-29T11:04:43Z | [
"python",
"django",
"session"
] |
Giving anonymous users the same functionality as registered ones | 925,456 | <p>I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:</p>
<pre><code>class Cart(models.Model):
user = models.OneToOneField(User)
class... | 6 | 2009-05-29T11:00:55Z | 925,483 | <p>Just save the user data the user table and don't populate then userid/password tables.</p>
<p>if a user registers then you just have to populate those fields.</p>
<p>You will have to have some "cleanup" script run periodically to clear out any users who haven't visited in some arbitrary period. I'd make this clean... | 2 | 2009-05-29T11:12:19Z | [
"python",
"django",
"session"
] |
Giving anonymous users the same functionality as registered ones | 925,456 | <p>I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:</p>
<pre><code>class Cart(models.Model):
user = models.OneToOneField(User)
class... | 6 | 2009-05-29T11:00:55Z | 925,514 | <p>Seems to me that the easiest way to do this would be to store both the user id or the session id:</p>
<pre><code>class Cart(models.Model):
user = models.ForeignKey(User, null=True)
session = models.CharField(max_length=32, null=True)
</code></pre>
<p>Then, when a user registers, you can take their <code>re... | 4 | 2009-05-29T11:18:41Z | [
"python",
"django",
"session"
] |
Giving anonymous users the same functionality as registered ones | 925,456 | <p>I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:</p>
<pre><code>class Cart(models.Model):
user = models.OneToOneField(User)
class... | 6 | 2009-05-29T11:00:55Z | 927,303 | <p>I think you were on the right track thinking about using sessions. I would store a list of Product id's in the users session and then when the user registers, create a cart as you have defined and then add the items. Check out the <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">se... | 0 | 2009-05-29T17:57:18Z | [
"python",
"django",
"session"
] |
Need help for facebook fql query | 925,476 | <p>I wanted to know why is this code wrong.</p>
<pre><code>new_query = "SELECT time,message FROM status WHERE (uid=%s % request.facebook.uid) AND time > someval.time"
new_result = request.facebook.fql.query(new_query)
</code></pre>
<p>Someval.time is correct time format according to facebook time format.
So why d... | 1 | 2009-05-29T11:10:42Z | 925,591 | <p>Did you mean:</p>
<pre><code>new_query = "SELECT ... AND time > %s" % someval.time
</code></pre>
<p>or similar?</p>
<p><strong>Edit</strong>:</p>
<p>You've posted several pieces of code that look like this:</p>
<pre><code>"Select something WHERE x=%s % something"
</code></pre>
<p>with the percent operator ... | 0 | 2009-05-29T11:36:42Z | [
"python",
"django",
"facebook"
] |
Need help for facebook fql query | 925,476 | <p>I wanted to know why is this code wrong.</p>
<pre><code>new_query = "SELECT time,message FROM status WHERE (uid=%s % request.facebook.uid) AND time > someval.time"
new_result = request.facebook.fql.query(new_query)
</code></pre>
<p>Someval.time is correct time format according to facebook time format.
So why d... | 1 | 2009-05-29T11:10:42Z | 9,019,596 | <p>Use the <code>me()</code> FQL shorthand to get at the user id for whom the token is issued for</p>
<p><code>SELECT time,message FROM status WHERE uid=me()</code></p>
| 0 | 2012-01-26T14:29:43Z | [
"python",
"django",
"facebook"
] |
Is there a uniform python library to transfer files using different protocols | 925,716 | <p>I know there is <code>ftplib</code> for ftp, <code>shutil</code> for local files, what about NFS? I know urllib2 can <strong>get</strong> files via HTTP/HTTPS/FTP/FTPS, but it can't <strong>put</strong> files.</p>
<p>If there is a uniform library that automatically detects the protocol (FTP/NFS/LOCAL) with URI and ... | 3 | 2009-05-29T12:22:05Z | 926,044 | <p>Have a look at KDE IOSlaves. They can manage all the protocol you describe, plus a few others (samba, ssh, ...).</p>
<p>You can instantiates IOSlaves through PyKDE or if that dependency is too big, you can probably manage the ioslave from python with the subprocess module.</p>
| 1 | 2009-05-29T13:45:36Z | [
"python",
"file",
"ftp",
"networking",
"nfs"
] |
Is there a uniform python library to transfer files using different protocols | 925,716 | <p>I know there is <code>ftplib</code> for ftp, <code>shutil</code> for local files, what about NFS? I know urllib2 can <strong>get</strong> files via HTTP/HTTPS/FTP/FTPS, but it can't <strong>put</strong> files.</p>
<p>If there is a uniform library that automatically detects the protocol (FTP/NFS/LOCAL) with URI and ... | 3 | 2009-05-29T12:22:05Z | 927,764 | <p>You want to look up and use pycurl/libcurl. Libcurl: <a href="http://curl.haxx.se/" rel="nofollow">http://curl.haxx.se/</a> PyCurl: <a href="http://pycurl.sourceforge.net/" rel="nofollow">http://pycurl.sourceforge.net/</a> - curl supports the http://, file://, and ftp:// uris. I have used it with much success.</p>
| 2 | 2009-05-29T19:40:07Z | [
"python",
"file",
"ftp",
"networking",
"nfs"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 926,190 | <p>If you are already running in debug mode you can set an additional breakpoint if the program execution is currently paused (e.g. because you are already at a breakpoint). I just tried it out now with the latest Pydev - it works just fine. </p>
<p>If you are running normally (i.e. not in debug mode) all breakpoints ... | -2 | 2009-05-29T14:14:00Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 926,408 | <p>I've long been using this code in my <code>sitecustomize.py</code> to start a debugger on an exception. This can also be triggered by Ctrl+C. It works beautifully in the shell, don't know about eclipse. </p>
<pre><code>import sys
def info(exception_type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isat... | 2 | 2009-05-29T14:52:58Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 956,448 | <p>You can jump into an interactive session using <code>code.InteractiveConsole</code> as described <a href="http://code.activestate.com/recipes/355319/" rel="nofollow">here</a>; however I don't know how to trigger this from Eclipse.</p>
<p>A solution might be to intercept Ctrl+C to jump into this interactive console ... | 2 | 2009-06-05T15:20:58Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 960,237 | <p>Not truely an answer to your question, but just a pointer to iPython. Just in case you aren't aware of it. I use it side-by-side with eclipse/pydev for just such things.</p>
<p>Of relevence is this info on embedding <a href="http://ipython.scipy.org/doc/manual/html/interactive/reference.html#embedding" rel="nofollo... | 1 | 2009-06-06T18:19:42Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 962,124 | <p>This is from an old project, and I didn't write it, but it does something similar to what you want using ipython.</p>
<pre><code>'''Start an IPython shell (for debugging) with current environment.
Runs Call db() to start a shell, e.g.
def foo(b... | 6 | 2009-06-07T15:41:31Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
Jump into a Python Interactive Session mid-program? | 925,832 | <p>Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering:</p>
<p><strong>Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution?</strong></p>
<p>I think that would be pretty handy ;... | 11 | 2009-05-29T12:58:07Z | 3,650,728 | <p>So roughly a year on from the OP's question, PyDev has this capability built in. I am not sure when this feature was introduced, but all I know is I've spent the last ~2hrs Googling... configuring iPython and whatever (which was looking like it would have done the job), but only to realise Eclipse/PyDev has what I w... | 8 | 2010-09-06T10:28:37Z | [
"python",
"eclipse",
"debugging",
"breakpoints",
"pydev"
] |
parsing in python | 925,839 | <p>I have following string</p>
<p>adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0</p>
<p>I need only the value of adId,siteId and userId.
means </p>
<p>4028cb901dd9720a011e1160afbc01a3</p>
<p>8a8ee4f720e6beb70120e6d8e08b0002</p>
<p>5082a05c-... | 3 | 2009-05-29T13:00:15Z | 925,843 | <p>You can split them to a dictionary if you don't need any fancy parsing:</p>
<pre><code>In [2]: dict(kvpair.split(':') for kvpair in s.split(';'))
Out[2]:
{'adId': '4028cb901dd9720a011e1160afbc01a3',
'siteId': '8a8ee4f720e6beb70120e6d8e08b0002',
'userId': '5082a05c-015e-4266-9874-5dc6262da3e0'}
</code></pre>
| 18 | 2009-05-29T13:02:42Z | [
"python"
] |
parsing in python | 925,839 | <p>I have following string</p>
<p>adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0</p>
<p>I need only the value of adId,siteId and userId.
means </p>
<p>4028cb901dd9720a011e1160afbc01a3</p>
<p>8a8ee4f720e6beb70120e6d8e08b0002</p>
<p>5082a05c-... | 3 | 2009-05-29T13:00:15Z | 925,851 | <p>There is an awesome method called <a href="http://docs.python.org/library/string.html#deprecated-string-functions" rel="nofollow">split()</a> for python that will work nicely for you. I would suggest using it twice, once for ';' then again for each one of those using ':'.</p>
| 0 | 2009-05-29T13:05:08Z | [
"python"
] |
parsing in python | 925,839 | <p>I have following string</p>
<p>adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0</p>
<p>I need only the value of adId,siteId and userId.
means </p>
<p>4028cb901dd9720a011e1160afbc01a3</p>
<p>8a8ee4f720e6beb70120e6d8e08b0002</p>
<p>5082a05c-... | 3 | 2009-05-29T13:00:15Z | 925,853 | <pre><code>matches = re.findall("([a-z0-9A-Z_]+):([a-zA-Z0-9\-]+);", buf)
for m in matches:
#m[1] is adid and things
#m[2] is the long string.
</code></pre>
<p>You can also limit the lengths using {32} like</p>
<pre><code>([a-zA-Z0-9]+){32};
</code></pre>
<p>Regular expressions allow you to <strong>validate... | 1 | 2009-05-29T13:05:21Z | [
"python"
] |
parsing in python | 925,839 | <p>I have following string</p>
<p>adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0</p>
<p>I need only the value of adId,siteId and userId.
means </p>
<p>4028cb901dd9720a011e1160afbc01a3</p>
<p>8a8ee4f720e6beb70120e6d8e08b0002</p>
<p>5082a05c-... | 3 | 2009-05-29T13:00:15Z | 925,856 | <p>You could do something like this:</p>
<pre><code>input='adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0'
result={}
for pair in input.split(';'):
(key,value) = pair.split(':')
result[key] = value
print result['adId']
print result['si... | 1 | 2009-05-29T13:05:28Z | [
"python"
] |
Fedora Python Upgrade broke easy_install | 925,965 | <p>Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases.</p>
<p>To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9.</p>
<p>I downloaded 2.5.4, did <code>./configure; make;... | 0 | 2009-05-29T13:29:39Z | 926,006 | <p>I suggest you create a virtualenv (or several) for installing packages into.</p>
| 2 | 2009-05-29T13:37:07Z | [
"python",
"fedora",
"easy-install"
] |
Fedora Python Upgrade broke easy_install | 925,965 | <p>Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases.</p>
<p>To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9.</p>
<p>I downloaded 2.5.4, did <code>./configure; make;... | 0 | 2009-05-29T13:29:39Z | 926,636 | <p>I've had similar experiences and issues when installing Python 2.5 on an older release of ubuntu that supplied 2.4 out of the box.</p>
<p>I first tried to patch <code>easy_install</code>, but this led to problems with anything that wanted to use the os-supplied version of python. I was often fiddling with the tool ... | 2 | 2009-05-29T15:35:51Z | [
"python",
"fedora",
"easy-install"
] |
Fedora Python Upgrade broke easy_install | 925,965 | <p>Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases.</p>
<p>To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9.</p>
<p>I downloaded 2.5.4, did <code>./configure; make;... | 0 | 2009-05-29T13:29:39Z | 928,408 | <p>Normally, you would only have one version of a python release installed. Since 2.5.1 and 2.5.4 are from the same release, copying your libraries should work fine. What you would need to watch out for, is that you now have /usr/bin/python, and /usr/local/bin/python in your path, and some utilities may get confused. <... | 4 | 2009-05-29T22:24:10Z | [
"python",
"fedora",
"easy-install"
] |
Are inner-classes unpythonic? | 926,327 | <p>My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic.</p>
<p>What do people here think? Are inner-classes something which are more appropriate to Java etc than Python?</p>
<p>NB : I don't think this is a "subjective" qu... | 2 | 2009-05-29T14:40:35Z | 926,351 | <p>Actually, I'm not sure if I agree with the whole premise that "Flat is better than nested". Sometimes, quite often actually, the best way to represent something is hierarchically... Even nature itself, often uses hierarchy.</p>
| 1 | 2009-05-29T14:44:23Z | [
"python"
] |
Are inner-classes unpythonic? | 926,327 | <p>My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic.</p>
<p>What do people here think? Are inner-classes something which are more appropriate to Java etc than Python?</p>
<p>NB : I don't think this is a "subjective" qu... | 2 | 2009-05-29T14:40:35Z | 926,388 | <p>"Flat is better than nested" is focused on avoiding <em>excessive</em> nesting -- i.e., seriously deep hierarchies. One level of nesting, per se, is no big deal: as long as your nesting still respects (a weakish form of) the <a href="http://en.wikipedia.org/wiki/Law%5Fof%5FDemeter" rel="nofollow">Law of Demeter</a>,... | 8 | 2009-05-29T14:49:32Z | [
"python"
] |
Are inner-classes unpythonic? | 926,327 | <p>My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic.</p>
<p>What do people here think? Are inner-classes something which are more appropriate to Java etc than Python?</p>
<p>NB : I don't think this is a "subjective" qu... | 2 | 2009-05-29T14:40:35Z | 926,443 | <p>This may not deserve a [subjective] tag on StackOverflow, but it's subjective on the larger stage: some language communities encourage nesting and others discourage it. So why would the Python community discourage nesting? Because Tim Peters put it in <a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Pyt... | 8 | 2009-05-29T14:58:56Z | [
"python"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,590 | <p>Because <code>cb[0]</code> is the same as <code>cb.__getitem__(0)</code>. See the <a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">python documentation</a> on this.</p>
| 3 | 2009-05-29T15:26:14Z | [
"python",
"iterator",
"overloading"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,598 | <p>Special methods such as <code>__getitem__</code> add special behaviors to objects, including iteration. </p>
<p><a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fgetitem%5F%5F">http://docs.python.org/reference/datamodel.html#object.<strong>getitem</strong></a></p>
<p>"for loops expect that an ... | 5 | 2009-05-29T15:28:06Z | [
"python",
"iterator",
"overloading"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,609 | <p>If you take a look at <a href="http://www.python.org/dev/peps/pep-0234">PEP234</a> defining iterators, it says:</p>
<pre><code>1. An object can be iterated over with "for" if it implements
__iter__() or __getitem__().
2. An object can function as an iterator if it implements next().
</code></pre>
| 33 | 2009-05-29T15:29:22Z | [
"python",
"iterator",
"overloading"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,645 | <p>Iteration's support for <code>__getitem__</code> can be seen as a "legacy feature" which allowed smoother transition when PEP234 introduced iterability as a primary concept. It only applies to classes without <code>__iter__</code> whose <code>__getitem__</code> accepts integers 0, 1, &c, and raises <code>IndexEr... | 42 | 2009-05-29T15:37:35Z | [
"python",
"iterator",
"overloading"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,649 | <p><code>__getitem__</code> predates the iterator protocol, and was in the past the <em>only</em> way to make things iterable. As such, it's still supported as a method of iterating. Essentially, the protocol for iteration is:</p>
<ol>
<li><p>Check for an <code>__iter__</code> method. If it exists, use the new iter... | 16 | 2009-05-29T15:38:10Z | [
"python",
"iterator",
"overloading"
] |
Why does defining __getitem__ on a class make it iterable in python? | 926,574 | <p>Why does defining __getitem__ on a class make it iterable? </p>
<p>For instance if I write:</p>
<pre><code>class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
</code></pre>
<p>I get the output:</p>
<pre><code>0
1
2
3
4
5
6
7
8
...
</code></pre>
<p>I would really expect to see an ... | 34 | 2009-05-29T15:22:53Z | 926,652 | <p>This is so for historical reasons. Prior to Python 2.2 __getitem__ was the only way to create a class that could be iterated over with the for loop. In 2.2 the __iter__ protocol was added but to retain backwards compatibility __getitem__ still works in for loops.</p>
| 4 | 2009-05-29T15:38:23Z | [
"python",
"iterator",
"overloading"
] |
Configure Apache to recover from mod_python errors | 926,579 | <p>I am hosting a Django app on Apache using mod_python. Occasionally, I get some cryptic mod_python errors, usually of the <code>ImportError</code> variety, although not usually referring to the same module. The thing is, these seem to come up for a single forked subprocess, while the others operate fine, even when ... | 0 | 2009-05-29T15:23:29Z | 928,519 | <p>As a workaround, and assuming you are free to install new Apache modules on the server, you might try one of</p>
<ul>
<li>mod_scgi</li>
<li>mod_fastcgi</li>
<li>mod_wsgi </li>
</ul>
<p>instead. I use SCGI to connect an nginx frontend webserver to my Django apps, which highlights a major benefit (decoupling from th... | 1 | 2009-05-29T23:16:35Z | [
"python",
"django",
"apache",
"mod-python"
] |
Configure Apache to recover from mod_python errors | 926,579 | <p>I am hosting a Django app on Apache using mod_python. Occasionally, I get some cryptic mod_python errors, usually of the <code>ImportError</code> variety, although not usually referring to the same module. The thing is, these seem to come up for a single forked subprocess, while the others operate fine, even when ... | 0 | 2009-05-29T15:23:29Z | 981,610 | <p>A more detailed version of this question with accepted answer is available at this reposting:</p>
<p><a href="http://stackoverflow.com/questions/970953/testing-for-mysterious-load-errors-in-python-django">http://stackoverflow.com/questions/970953/testing-for-mysterious-load-errors-in-python-django</a></p>
| 0 | 2009-06-11T14:56:31Z | [
"python",
"django",
"apache",
"mod-python"
] |
How can I make a class in python support __getitem__, but not allow iteration? | 926,688 | <p>I want to define a class that supports <code>__getitem__</code>, but does not allow iteration.
for example:</p>
<pre><code>class B:
def __getitem__(self, k):
return k
cb = B()
for x in cb:
print x
</code></pre>
<p>What could I add to the class <code>B</code> to force the <code>for x in cb:</code> to ... | 1 | 2009-05-29T15:45:35Z | 926,705 | <p>From the answers to this <a href="http://stackoverflow.com/questions/926574/why-does-defining-getitem-on-a-class-make-it-iterable-in-python">question</a>, we can see that __iter__ will be called before __getitem__ if it exists, so simply define B as:</p>
<pre><code>class B:
def __getitem__(self, k):
return... | 2 | 2009-05-29T15:48:07Z | [
"python",
"operator-overloading",
"iteration"
] |
How can I make a class in python support __getitem__, but not allow iteration? | 926,688 | <p>I want to define a class that supports <code>__getitem__</code>, but does not allow iteration.
for example:</p>
<pre><code>class B:
def __getitem__(self, k):
return k
cb = B()
for x in cb:
print x
</code></pre>
<p>What could I add to the class <code>B</code> to force the <code>for x in cb:</code> to ... | 1 | 2009-05-29T15:45:35Z | 926,832 | <p>I think a slightly better solution would be to raise a TypeError rather than a plain exception (this is what normally happens with a non-iterable class:</p>
<pre><code>class A(object):
# show what happens with a non-iterable class with no __getitem__
pass
class B(object):
def __getitem__(self, k):
... | 13 | 2009-05-29T16:11:20Z | [
"python",
"operator-overloading",
"iteration"
] |
Does python-memcache use consistent hashing? | 926,814 | <p>I'm using the python-memcache library, and I'm wondering if anyone knows if consistent hashing is used by that client as of 1.44.</p>
| 1 | 2009-05-29T16:07:57Z | 927,081 | <p>From a quick view into the source code: No it does not. It uses <code>server = hash_key % len(servers)</code> and round-robin if offline/full servers are encountered.</p>
| 2 | 2009-05-29T17:03:10Z | [
"python",
"memcached"
] |
Does python-memcache use consistent hashing? | 926,814 | <p>I'm using the python-memcache library, and I'm wondering if anyone knows if consistent hashing is used by that client as of 1.44.</p>
| 1 | 2009-05-29T16:07:57Z | 927,641 | <p>If you need something like that you might be interested in <a href="http://amix.dk/blog/viewEntry/19367" rel="nofollow">hash_ring</a></p>
| 3 | 2009-05-29T19:10:33Z | [
"python",
"memcached"
] |
Checking to See if a List Exists Within Another Lists? | 926,946 | <p>Okay I'm trying to go for a more pythonic method of doing things.</p>
<p>How can i do the following:</p>
<pre><code>required_values = ['A','B','C']
some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4}
for required_value in required_values:
if not required_value in some_map:
print 'It Doesnt Exists'
... | 2 | 2009-05-29T16:35:44Z | 926,977 | <pre><code>all(value in some_map for value in required_values)
</code></pre>
| 8 | 2009-05-29T16:42:12Z | [
"python",
"list"
] |
Checking to See if a List Exists Within Another Lists? | 926,946 | <p>Okay I'm trying to go for a more pythonic method of doing things.</p>
<p>How can i do the following:</p>
<pre><code>required_values = ['A','B','C']
some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4}
for required_value in required_values:
if not required_value in some_map:
print 'It Doesnt Exists'
... | 2 | 2009-05-29T16:35:44Z | 926,980 | <pre><code>return set(required_values).issubset(set(some_map.keys()))
</code></pre>
| 3 | 2009-05-29T16:42:39Z | [
"python",
"list"
] |
Checking to See if a List Exists Within Another Lists? | 926,946 | <p>Okay I'm trying to go for a more pythonic method of doing things.</p>
<p>How can i do the following:</p>
<pre><code>required_values = ['A','B','C']
some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4}
for required_value in required_values:
if not required_value in some_map:
print 'It Doesnt Exists'
... | 2 | 2009-05-29T16:35:44Z | 927,042 | <p>try a list comprehension:</p>
<p>return not bool([x for x in required_values if x not in some_map.keys()]) (bool conversion for clarity)</p>
<p>or return not [x for x in required_values if x not in some_map.keys()] (i think the more pythonic way)</p>
<p>The inside [] statement builds a list of all required value... | 0 | 2009-05-29T16:55:04Z | [
"python",
"list"
] |
Using mx:RemoteObject with web2py's @service.amfrpc decorator | 927,028 | <p>I am using web2py (v1.63) and Flex 3. web2py v1.61 introduced the @service decorators, which allow you to tag a controller function with @service.amfrpc. You can then call that function remotely using <code>http://..../app/default/call/amfrpc/[function]</code>. See <a href="http://www.web2py.com/examples/default/too... | 2 | 2009-05-29T16:52:51Z | 939,927 | <p>I have not found a way to use a RemoteObject with the @service.amfrpc decorator. However, I can use the older ActionScript code using a NetConnection (similar to what I posted originally) and pair that with a @service.amfrpc function on the web2py side. This seems to work fine. The one thing that you would want to c... | 1 | 2009-06-02T14:37:12Z | [
"python",
"flex",
"flex3",
"web2py",
"pyamf"
] |
Nokia N95 and PyS60 with the sensor and xprofile modules | 927,150 | <p>I've made a python script which should modify the profile of the phone based on the phone position. Runned under ScriptShell it works great.</p>
<p>The problem is that it hangs, both with the "sis" script runned upon "boot up", as well as without it.</p>
<p>So my question is what is wrong with the code, and also w... | 0 | 2009-05-29T17:18:52Z | 955,705 | <p>xprofile is not a standard library, make sure you add path to it. My guess is that when run as SIS, it doesn't find xprofile and hangs up. When releasing your SIS, either instruct that users install that separately or include inside your SIS.</p>
<p>Where would you have it installed, use that path. Here's python de... | 2 | 2009-06-05T13:00:15Z | [
"python",
"symbian",
"nokia",
"s60",
"pys60"
] |
Nokia N95 and PyS60 with the sensor and xprofile modules | 927,150 | <p>I've made a python script which should modify the profile of the phone based on the phone position. Runned under ScriptShell it works great.</p>
<p>The problem is that it hangs, both with the "sis" script runned upon "boot up", as well as without it.</p>
<p>So my question is what is wrong with the code, and also w... | 0 | 2009-05-29T17:18:52Z | 965,797 | <p>I often use something like that at the top of my scripts:</p>
<pre><code>import os.path, sys
PY_PATH = None
for p in ['c:\\Data\\Python', 'e:\\Data\\Python','c:\\Python','e:\\Python']:
if os.path.exists(p):
PY_PATH = p
break
if PY_PATH and PY_PATH not in sys.path: sys.path.append(PY_PATH)
</cod... | 3 | 2009-06-08T16:36:05Z | [
"python",
"symbian",
"nokia",
"s60",
"pys60"
] |
FIFO (named pipe) messaging obstacles | 927,233 | <p>I plan to use Unix named pipes (mkfifo) for simple multi-process messaging.
A message would be just a single line of text.</p>
<p>Would you discourage me from that? What obstacles should I expect?</p>
<p>I have noticed these limitations:</p>
<ol>
<li>A sender cannot continue until the message is received.</li>
<l... | 1 | 2009-05-29T17:35:45Z | 927,281 | <ol>
<li>Lack of portability - they are mainly a Unix thing. Sockets are more portable.</li>
<li>Harder to scale out to multiple systems (another sockets+)</li>
<li>On the other hand, I believe pipes are faster than sockets for processes on the same machine (less communication overhead).</li>
</ol>
<p>As to your limit... | 4 | 2009-05-29T17:53:36Z | [
"python",
"linux",
"unix",
"pipe",
"named-pipes"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.