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 save a configuration file / python file IO | 1,423,214 | <p>I have this python code for opening a .cfg file, writing to it and saving it:</p>
<pre><code>import ConfigParser
def get_lock_file():
cf = ConfigParser.ConfigParser()
cf.read("svn.lock")
return cf
def save_lock_file(configurationParser):
cf = configurationParser
con... | 0 | 2009-09-14T18:35:35Z | 1,423,287 | <p>Looks good to me.</p>
<p>If both places call <code>get_lock_file</code>, then <code>cf.set(...)</code>, and then <code>save_lock_file</code>, and no exceptions are raised, this should work.</p>
<p>If you have different threads or processes accessing the same file you could have a race condition:</p>
<ol>
<li>thre... | 1 | 2009-09-14T18:55:01Z | [
"python",
"file",
"file-io",
"configuration-files"
] |
How to save a configuration file / python file IO | 1,423,214 | <p>I have this python code for opening a .cfg file, writing to it and saving it:</p>
<pre><code>import ConfigParser
def get_lock_file():
cf = ConfigParser.ConfigParser()
cf.read("svn.lock")
return cf
def save_lock_file(configurationParser):
cf = configurationParser
con... | 0 | 2009-09-14T18:35:35Z | 1,423,303 | <p>Works for me.</p>
<pre>
C:\temp>type svn.lock
[some_prop_section]
Hello=World
C:\temp>python
ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> imp... | 1 | 2009-09-14T18:58:24Z | [
"python",
"file",
"file-io",
"configuration-files"
] |
How to save a configuration file / python file IO | 1,423,214 | <p>I have this python code for opening a .cfg file, writing to it and saving it:</p>
<pre><code>import ConfigParser
def get_lock_file():
cf = ConfigParser.ConfigParser()
cf.read("svn.lock")
return cf
def save_lock_file(configurationParser):
cf = configurationParser
con... | 0 | 2009-09-14T18:35:35Z | 1,426,555 | <p>Just to note that configuration file handling is simpler with ConfigObj.</p>
<p>To read and then write a config file:</p>
<pre><code>from configobj import ConfigObj
config = ConfigObj(filename)
value = config['entry']
config['entry'] = newvalue
config.write()
</code></pre>
| 12 | 2009-09-15T11:15:19Z | [
"python",
"file",
"file-io",
"configuration-files"
] |
talking between python tcp server and a c++ client | 1,423,251 | <p>I am having an issue trying to communicate between a python TCP server and a c++ TCP client.
After the first call, which works fine, the subsequent calls cause issues. </p>
<p>As far as WinSock is concerned, the send() function worked properly, it returns the proper length and WSAGetLastError() does not return anyt... | 2 | 2009-09-14T18:44:53Z | 1,423,334 | <p>What size of packets do you send? </p>
<p>If they are small - may be <a href="http://www.stuartcheshire.org/papers/NagleDelayedAck/" rel="nofollow">Nagle's Algorith & Delayed ACK Algorithm</a> is your headache? From what you described think Delayed ACK is involved...</p>
| 0 | 2009-09-14T19:05:44Z | [
"c++",
"python",
"networking",
"sockets",
"winsock"
] |
talking between python tcp server and a c++ client | 1,423,251 | <p>I am having an issue trying to communicate between a python TCP server and a c++ TCP client.
After the first call, which works fine, the subsequent calls cause issues. </p>
<p>As far as WinSock is concerned, the send() function worked properly, it returns the proper length and WSAGetLastError() does not return anyt... | 2 | 2009-09-14T18:44:53Z | 1,424,893 | <blockquote>
<p>client sends a PSH,ACK and then the
server sends a PSH,ACK and a
FIN,PSH,ACK</p>
</blockquote>
<p>There is a FIN, so could it be that the Python version of your server is closing the connection immediately after the initial read?</p>
<p>If you are not explicitly closing the server's socket, it's... | 2 | 2009-09-15T02:52:48Z | [
"c++",
"python",
"networking",
"sockets",
"winsock"
] |
Negative lookahead after newline? | 1,423,260 | <p>I have a CSV-like text file that has about 1000 lines. Between each record in the file is a long series of dashes. The records generally end with a \n, but sometimes there is an extra \n before the end of the record. Simplified example:</p>
<pre><code>"1x", "1y", "Hi there"
-------------------------------
"2x", "2y... | 2 | 2009-09-14T18:48:01Z | 1,423,288 | <p>You need to exclude the line breaks at the end of the separating lines. Try this:</p>
<pre><code>\n(?<!-\n)(?!-)
</code></pre>
<p>This regular expression uses a negative <a href="http://www.regular-expressions.info/lookaround.html#lookbehind" rel="nofollow">look-behind assertion</a> to exclude <code>\n</code> t... | 5 | 2009-09-14T18:55:20Z | [
"python",
"regex"
] |
Negative lookahead after newline? | 1,423,260 | <p>I have a CSV-like text file that has about 1000 lines. Between each record in the file is a long series of dashes. The records generally end with a \n, but sometimes there is an extra \n before the end of the record. Simplified example:</p>
<pre><code>"1x", "1y", "Hi there"
-------------------------------
"2x", "2y... | 2 | 2009-09-14T18:48:01Z | 1,423,323 | <pre><code>re.sub(r'(?<!-)\n(?!-)', ' ', text)
</code></pre>
<p>(Hyphen doesn't need escaping outside of a character class.)</p>
| 1 | 2009-09-14T19:03:04Z | [
"python",
"regex"
] |
Negative lookahead after newline? | 1,423,260 | <p>I have a CSV-like text file that has about 1000 lines. Between each record in the file is a long series of dashes. The records generally end with a \n, but sometimes there is an extra \n before the end of the record. Simplified example:</p>
<pre><code>"1x", "1y", "Hi there"
-------------------------------
"2x", "2y... | 2 | 2009-09-14T18:48:01Z | 1,423,344 | <p>This is a good place to use a generator function to skip the lines of <code>----</code>'s and yield something that the csv module can read.</p>
<pre><code>def readCleanLines( someFile ):
for line in someFile:
if line.strip() == len(line.strip())*'-':
continue
yield line
reader= csv.... | 7 | 2009-09-14T19:08:25Z | [
"python",
"regex"
] |
Negative lookahead after newline? | 1,423,260 | <p>I have a CSV-like text file that has about 1000 lines. Between each record in the file is a long series of dashes. The records generally end with a \n, but sometimes there is an extra \n before the end of the record. Simplified example:</p>
<pre><code>"1x", "1y", "Hi there"
-------------------------------
"2x", "2y... | 2 | 2009-09-14T18:48:01Z | 1,423,449 | <p>A RegEx isn't always the best tool for the job. How about running it through something like "Split" or "Tokenize" first? (I'm sure python has an equivalent) Then you have your records and can assume newlines are just continuations.</p>
| 0 | 2009-09-14T19:29:07Z | [
"python",
"regex"
] |
What is the best design for polling a modem for incoming data? | 1,423,308 | <p>I have a GSM modem connected to my computer, i want to receive text messages sent to it using a python program i have written, am just wondering what is the best technique to poll for data. </p>
<p>Should i write a program that has a infinite loop that continuously checks for incoming sms's i.e within the loop the ... | 8 | 2009-09-14T18:59:14Z | 1,423,366 | <p>I have written something similar before. There is a way using AT commands to tell the modem to signal you each time an SMS is received.</p>
<p>For reference, I was using a <a href="http://www.maestro-wireless.com/modules/product.php" rel="nofollow">Maestro 100 GSM Modem</a> in an embedded application.</p>
<p>First... | 3 | 2009-09-14T19:14:09Z | [
"python",
"modem",
"gsm",
"at-command"
] |
What is the best design for polling a modem for incoming data? | 1,423,308 | <p>I have a GSM modem connected to my computer, i want to receive text messages sent to it using a python program i have written, am just wondering what is the best technique to poll for data. </p>
<p>Should i write a program that has a infinite loop that continuously checks for incoming sms's i.e within the loop the ... | 8 | 2009-09-14T18:59:14Z | 1,424,253 | <p>I find I can't remember much of the AT command set related to SMS. Andre Miller's answer seems to ring a few bells. Anyway you should read the documentation very carefully, I'm sure there were a few gotchas.</p>
<p>My recommentation for polling is at least every 5 seconds - this is just for robustness and respons... | 0 | 2009-09-14T22:39:19Z | [
"python",
"modem",
"gsm",
"at-command"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,369 | <p>Assuming this is for Windows, see <a href="http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html" rel="nofollow">this recipe based on srvany</a></p>
| 1 | 2009-09-14T19:14:27Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,371 | <p>You might want to check out <a href="http://twistedmatrix.com/trac/">Twisted</a>.</p>
| 7 | 2009-09-14T19:14:29Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,375 | <p>If you are talking about linux, it is as easy as doing something like ./myscript.py &</p>
| 0 | 2009-09-14T19:15:19Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,388 | <p>on XP and later you can use the <strong>sc.exe</strong> program to use any .exe as service:</p>
<pre><code>>sc create
Creates a service entry in the registry and Service Database.
SYNTAX:
sc create [service name] [binPath= ] <option1> <option2>...
CREATE OPTIONS:
NOTE: The option name includes the eq... | 2 | 2009-09-14T19:18:59Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,498 | <p>You can make it a daemon. There is a PEP for a more complete solution, but I have found that this works well.</p>
<pre><code>import os, sys
def become_daemon(our_home_dir='.', out_log='/dev/null', err_log='/dev/null', pidfile='/var/tmp/daemon.pid'):
""" Make the current process a daemon. """
try:
... | 8 | 2009-09-14T19:40:18Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
Can I run a Python script as a service? | 1,423,345 | <p>Is it possible to run a Python script as a background service on a webserver? I want to do this for <a href="http://stackoverflow.com/questions/1422929/socket-communication">socket communication.</a></p>
| 12 | 2009-09-14T19:08:36Z | 1,423,556 | <p>There is the very helpful <a href="http://pypi.python.org/pypi/python-daemon/" rel="nofollow">Pypi package</a> which is the basis for my daemons written in Python.</p>
| 2 | 2009-09-14T19:52:26Z | [
"python",
"web-services",
"sockets",
"webserver"
] |
What is wrong with this python function from "Programming Collective Intelligence"? | 1,423,525 | <p>This is the function in question. It calculates the Pearson correlation coefficient for p1 and p2, which is supposed to be a number between -1 and 1.</p>
<p>When I use this with real user data, it sometimes returns a number greater than 1, like in this example:</p>
<pre><code>def sim_pearson(prefs,p1,p2):
si={... | 4 | 2009-09-14T19:46:12Z | 1,423,580 | <p>It looks like you may be unexpectedly using integer division. I made the following change and your function returned <code>1.0</code>:</p>
<pre><code>num=pSum-(1.0*sum1*sum2/n)
den=sqrt((sum1Sq-1.0*pow(sum1,2)/n)*(sum2Sq-1.0*pow(sum2,2)/n))
</code></pre>
<p>See <a href="http://docs.python.org/whatsnew/2.2.html#pep... | 8 | 2009-09-14T19:56:51Z | [
"python",
"algorithm",
"pearson"
] |
What is wrong with this python function from "Programming Collective Intelligence"? | 1,423,525 | <p>This is the function in question. It calculates the Pearson correlation coefficient for p1 and p2, which is supposed to be a number between -1 and 1.</p>
<p>When I use this with real user data, it sometimes returns a number greater than 1, like in this example:</p>
<pre><code>def sim_pearson(prefs,p1,p2):
si={... | 4 | 2009-09-14T19:46:12Z | 1,423,592 | <p>Well it took me a minute to read over the code but it seems if you change your input data to <strong>floats</strong> it will work</p>
| 2 | 2009-09-14T19:58:46Z | [
"python",
"algorithm",
"pearson"
] |
What is wrong with this python function from "Programming Collective Intelligence"? | 1,423,525 | <p>This is the function in question. It calculates the Pearson correlation coefficient for p1 and p2, which is supposed to be a number between -1 and 1.</p>
<p>When I use this with real user data, it sometimes returns a number greater than 1, like in this example:</p>
<pre><code>def sim_pearson(prefs,p1,p2):
si={... | 4 | 2009-09-14T19:46:12Z | 1,423,611 | <p>Integer division is confusing it. It works if you make <code>n</code> a float:</p>
<pre><code>n=float(len(si))
</code></pre>
| 2 | 2009-09-14T20:02:40Z | [
"python",
"algorithm",
"pearson"
] |
What is wrong with this python function from "Programming Collective Intelligence"? | 1,423,525 | <p>This is the function in question. It calculates the Pearson correlation coefficient for p1 and p2, which is supposed to be a number between -1 and 1.</p>
<p>When I use this with real user data, it sometimes returns a number greater than 1, like in this example:</p>
<pre><code>def sim_pearson(prefs,p1,p2):
si={... | 4 | 2009-09-14T19:46:12Z | 1,423,658 | <p>Well, I wasn't exactly able to find what's wrong with the logic in your function, so I just reimplemented it using the definition of Pearson coefficient:</p>
<pre><code>from math import sqrt
def sim_pearson(p1,p2):
keys = set(p1) | set(p2)
n = len(keys)
a1 = sum(p1[it] for it in keys) / n
a2 = sum... | 1 | 2009-09-14T20:12:23Z | [
"python",
"algorithm",
"pearson"
] |
Finding if a python datetime has no time information | 1,423,673 | <p>I want to trap values that are like this (in which there is not 'time info' on the datetime):</p>
<pre><code>datetime.datetime(2009, 4, 6, 0, 0)
</code></pre>
<p>Is there a better way to detect these values other than testing hour/minute/second?</p>
<pre><code>if value.hour == 0 and value.minute == 0 and value.se... | 1 | 2009-09-14T20:15:21Z | 1,423,713 | <p>I see nothing wrong with your method, but you could compare it to a 'zeroed' time object.</p>
<pre><code>someDateTime = datetime.datetime(2009, 4, 6, 0, 0)
someDateTime.time() == datetime.time(0)
</code></pre>
| 1 | 2009-09-14T20:24:56Z | [
"python",
"datetime"
] |
Finding if a python datetime has no time information | 1,423,673 | <p>I want to trap values that are like this (in which there is not 'time info' on the datetime):</p>
<pre><code>datetime.datetime(2009, 4, 6, 0, 0)
</code></pre>
<p>Is there a better way to detect these values other than testing hour/minute/second?</p>
<pre><code>if value.hour == 0 and value.minute == 0 and value.se... | 1 | 2009-09-14T20:15:21Z | 1,423,724 | <p>Another option:</p>
<pre><code>if not (value.hour or value.minute or value.second):
# do stuff
</code></pre>
| 0 | 2009-09-14T20:25:59Z | [
"python",
"datetime"
] |
Finding if a python datetime has no time information | 1,423,673 | <p>I want to trap values that are like this (in which there is not 'time info' on the datetime):</p>
<pre><code>datetime.datetime(2009, 4, 6, 0, 0)
</code></pre>
<p>Is there a better way to detect these values other than testing hour/minute/second?</p>
<pre><code>if value.hour == 0 and value.minute == 0 and value.se... | 1 | 2009-09-14T20:15:21Z | 1,423,730 | <p>You would actually need to check microsecond as well. Another option:</p>
<pre><code>NO_TIME = datetime.time(0) # can be stored as constant
if (value.time() == NO_TIME):
# do stuff
</code></pre>
| 1 | 2009-09-14T20:27:25Z | [
"python",
"datetime"
] |
Finding if a python datetime has no time information | 1,423,673 | <p>I want to trap values that are like this (in which there is not 'time info' on the datetime):</p>
<pre><code>datetime.datetime(2009, 4, 6, 0, 0)
</code></pre>
<p>Is there a better way to detect these values other than testing hour/minute/second?</p>
<pre><code>if value.hour == 0 and value.minute == 0 and value.se... | 1 | 2009-09-14T20:15:21Z | 1,423,732 | <p>don't neglect that HMS==0 for 1 in 86,400 fully completed time values! depending on what you're doing, that might not be negligible.</p>
| 3 | 2009-09-14T20:27:29Z | [
"python",
"datetime"
] |
Finding if a python datetime has no time information | 1,423,673 | <p>I want to trap values that are like this (in which there is not 'time info' on the datetime):</p>
<pre><code>datetime.datetime(2009, 4, 6, 0, 0)
</code></pre>
<p>Is there a better way to detect these values other than testing hour/minute/second?</p>
<pre><code>if value.hour == 0 and value.minute == 0 and value.se... | 1 | 2009-09-14T20:15:21Z | 1,423,736 | <p>The time method works here. Evaluates as boolean false if there's zero'd-out time info.</p>
<pre><code>if not value.time():
# do stuff
</code></pre>
| 10 | 2009-09-14T20:28:35Z | [
"python",
"datetime"
] |
Writing a connection string when password contains special characters | 1,423,804 | <p>I'm using SQLalchemy for a Python project, and I want to have a tidy connection string to access my database. So for example:</p>
<pre><code>engine = create_engine('postgres://user:pass@host/database')
</code></pre>
<p>The problem is my password contains a sequence of special characters that get interpreted as del... | 10 | 2009-09-14T20:41:50Z | 1,424,009 | <p>Backslashes aren't valid escape characters for URL component strings. You need to URL-encode the password portion of the connect string:</p>
<pre><code>from urllib import quote_plus as urlquote
from sqlalchemy.engine import create_engine
engine = create_engine('postgres://user:%s@host/database' % urlquote('badpass'... | 22 | 2009-09-14T21:26:51Z | [
"python",
"character-encoding",
"sqlalchemy",
"connection-string"
] |
hashlib / md5. Compatibility with python 2.4 | 1,423,861 | <p>python 2.6 reports that the md5 module is obsolete and hashlib should be used. If I change <code>import md5</code> to <code>import hashlib</code> I will solve for python 2.5 and python 2.6, but not for python 2.4, which has no hashlib module (leading to a ImportError, which I can catch).</p>
<p>Now, to fix it, I co... | 8 | 2009-09-14T20:51:42Z | 1,423,871 | <p>In general the following construct is just fine:</p>
<pre><code>try:
import module
except ImportError:
# Do something else.
</code></pre>
<p>In your particular case, perhaps:</p>
<pre><code>try:
from hashlib import md5
except ImportError:
from md5 import md5
</code></pre>
| 18 | 2009-09-14T20:54:25Z | [
"python",
"import",
"md5",
"backwards-compatibility",
"hashlib"
] |
hashlib / md5. Compatibility with python 2.4 | 1,423,861 | <p>python 2.6 reports that the md5 module is obsolete and hashlib should be used. If I change <code>import md5</code> to <code>import hashlib</code> I will solve for python 2.5 and python 2.6, but not for python 2.4, which has no hashlib module (leading to a ImportError, which I can catch).</p>
<p>Now, to fix it, I co... | 8 | 2009-09-14T20:51:42Z | 1,423,882 | <p>In the case where the modules have the same interface, as they do here, the solution you described is fine. You could also isolate the import into its own module like this:</p>
<pre><code>hash.py
----
try:
import hashlib.md5 as md5mod
except ImportError:
import md5 as md5mod
-----
prog.py
-----
from hash im... | 2 | 2009-09-14T20:57:09Z | [
"python",
"import",
"md5",
"backwards-compatibility",
"hashlib"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,423,938 | <p>Programs can modify what directories they check for libraries uwith <a href="http://perldoc.perl.org/lib.html" rel="nofollow"><code>use lib</code></a>. This lib directory can be relative to the current directory. Libraries from these directories will be used before system libraries, as they are placed at the begin... | 1 | 2009-09-14T21:06:32Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,423,955 | <p>I am not sure whether this is the same as that <code>virtualenv</code> thing you are talking about, but have a look for the <code>@INC</code> special variable in the <code>perlvar</code> manpage.</p>
| 1 | 2009-09-14T21:11:06Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,423,961 | <p>There's a tool called <a href="http://search.cpan.org/perldoc/local%3A%3Alib"><code>local::lib</code></a> that wraps up all of the work for you, much like <code>virtualenv</code>. It will:</p>
<ul>
<li>Set up <code>@INC</code> in the process where it's used.</li>
<li>Set <code>PERL5LIB</code> and other such things ... | 20 | 2009-09-14T21:12:15Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,423,992 | <p>What I do is start the CPAN shell (cpan) and install my own Perl 5.10 from it
(I believe the command is install perl-5.10). This will ask for various configuration
settings; I make sure to make it point to paths under /usr/local
(or some other installation location other than the default).</p>
<p>Then I put its re... | 0 | 2009-09-14T21:23:27Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,426,824 | <p>I've used <code>schroot</code> for this purpose. It is a bit heavier than virtualenv but you can be sure that nothing will leak in that shouldn't.</p>
<p><code>Schroot</code> manages a chroot environment for you, but mounts your home directory in the chroot so it appears like a normal shell session, just using the... | 1 | 2009-09-15T12:16:37Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 1,428,209 | <p>It looks like you just need to use the INSTALL_BASE configuration for Makefile.PL (or the --install_base option for Build.PL)? What exactly do you need the solution to do for you? It sounds like you just need to get the installed module in the right place. You've presented your problem as an <a href="http://www.perl... | 0 | 2009-09-15T16:27:12Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 24,569,961 | <p>Also checkout <a href="https://github.com/jizhang/perl-virtualenv" rel="nofollow">perl-virtualenv</a> , this seems to be wrapper around local::lib as suggested by Hobbs, but creates a bin/activate and bin/deactivate so you can use it just like the python tool.</p>
<p>I've been using it quite successfully for a mont... | 0 | 2014-07-04T08:32:17Z | [
"python",
"perl",
"virtualenv"
] |
How can I install specialized environments for different Perl applications? | 1,423,879 | <p>Is there anything equivalent or close in terms of functionality to Python's <a href="http://pypi.python.org/pypi/virtualenv#what-it-does">virtualenv</a>, but for Perl? </p>
<p>I've done some development in Python and a possibility of having non-system versions of modules installed in a separate environment without ... | 17 | 2009-09-14T20:56:34Z | 36,733,772 | <p>While investigating, I discovered this and some other pages (<a href="http://stackoverflow.com/questions/29950300/what-is-the-relationship-between-virtualenv-and-pyenv">this one is too old</a> and misses new technologies, <a href="https://www.reddit.com/r/perl/comments/3hry19/how_do_you_make_something_similar_to_a_p... | 0 | 2016-04-20T04:23:11Z | [
"python",
"perl",
"virtualenv"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 1,424,014 | <p>The first ten lowercase letters are <code>string.lowercase[:10]</code> (if you have imported the standard library module <code>string</code> previously, of course;-).</p>
<p>Other ways to "make a string of 10 characters": <code>'x'*10</code> (all the ten characters will be lowercase <code>x</code>s;-), <code>''.joi... | 8 | 2009-09-14T21:28:20Z | [
"python",
"string"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 1,424,016 | <p>To simply repeat the same letter 10 times:</p>
<pre><code>string_val = "x" * 10 # gives you "xxxxxxxxxx"
</code></pre>
<p>And if you want something more complex, like <code>n</code> random lowercase letters, it's still only one line of code (not counting the import statements and defining <code>n</code>):</p>
<p... | 130 | 2009-09-14T21:28:40Z | [
"python",
"string"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 1,424,017 | <p>If you can use repeated letters, you can use the <code>*</code> operator:</p>
<pre><code>>>> 'a'*5
'aaaaa'
</code></pre>
| 0 | 2009-09-14T21:29:46Z | [
"python",
"string"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 1,424,021 | <p>Why "one line"? You can fit anything onto one line.</p>
<p>Assuming you want them to start with 'a', and increment by one character each time (with wrapping > 26), here's a line:</p>
<pre><code>>>> mkstring = lambda(x): "".join(map(chr, (ord('a')+(y%26) for y in range(x))))
>>> mkstring(10)
'abcd... | 1 | 2009-09-14T21:30:22Z | [
"python",
"string"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 1,424,024 | <p>if you just want any letters:</p>
<pre><code> 'a'*10 # gives 'aaaaaaaaaa'
</code></pre>
<p>if you want consecutive letters (up to 26):</p>
<pre><code> ''.join(['%c' % x for x in range(97, 97+10)]) # gives 'abcdefghij'
</code></pre>
| 0 | 2009-09-14T21:31:14Z | [
"python",
"string"
] |
In Python, how do I create a string of n characters in one line of code? | 1,424,005 | <p>I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 letters:</p>
<pre><code>string_val = 'abcdefghij'
</code></pre>
| 53 | 2009-09-14T21:26:10Z | 21,192,936 | <p>This might be a little off the question, but for those interested in the randomness of the generated string, my answer would be:</p>
<pre><code>import os
import string
def _pwd_gen(size=16):
chars = string.letters
chars_len = len(chars)
return str().join(chars[int(ord(c) / 256. * chars_len)] for c in o... | 1 | 2014-01-17T18:12:25Z | [
"python",
"string"
] |
Komodo Edit - code-completion for Django? | 1,424,392 | <p>I've been using Komodo Edit for a small project in Django.</p>
<p>The code completion features seem to work pretty well for standard python modules, however, it doesn't know anything about Django modules. Is there any way to configure Komodo Edit to use Django modules for autocomplete as well?</p>
| 2 | 2009-09-14T23:26:17Z | 1,424,422 | <p>By sure Django is on your python path and Komodo should pick it up. Alternatively you can add the location of Django to where Komodo looks for its autocomplete.</p>
| 4 | 2009-09-14T23:36:21Z | [
"python",
"django",
"ide",
"code-completion",
"komodo"
] |
Komodo Edit - code-completion for Django? | 1,424,392 | <p>I've been using Komodo Edit for a small project in Django.</p>
<p>The code completion features seem to work pretty well for standard python modules, however, it doesn't know anything about Django modules. Is there any way to configure Komodo Edit to use Django modules for autocomplete as well?</p>
| 2 | 2009-09-14T23:26:17Z | 1,424,443 | <blockquote>
<p>o to Edit > Preferences. Expand the
"Languages" group by clicking the [+]
symbol. Click "Python". Click the
little "Add..." button under
"Additional Python Import
Directories". Add the directory ABOVE
your project and you should have
intellisense enabled.</p>
</blockquote>
<p>This ha... | 8 | 2009-09-14T23:43:24Z | [
"python",
"django",
"ide",
"code-completion",
"komodo"
] |
Komodo Edit - code-completion for Django? | 1,424,392 | <p>I've been using Komodo Edit for a small project in Django.</p>
<p>The code completion features seem to work pretty well for standard python modules, however, it doesn't know anything about Django modules. Is there any way to configure Komodo Edit to use Django modules for autocomplete as well?</p>
| 2 | 2009-09-14T23:26:17Z | 1,424,499 | <p>Hmmm. It's installed by default so my answer probably isn't the right solution. :-)</p>
<p>But here goes...</p>
<p>You can install a Django extension in Komodo edit. I haven't tested it myself but you can test it.</p>
<blockquote>
<p>Tools -> Add-ons -> Extensions</p>
</blockquote>
<p>It's name is "Django Lang... | 2 | 2009-09-15T00:09:27Z | [
"python",
"django",
"ide",
"code-completion",
"komodo"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 1,424,502 | <p>If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open... | 0 | 2009-09-15T00:10:32Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 1,424,507 | <p>If you open a module, that sets the default working directory.</p>
<p>Start IDLE.</p>
<p>File -> Open to open your file. And set the current working directory.</p>
| 1 | 2009-09-15T00:12:10Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 1,424,618 | <p>In my case, the default directory is set to the directory from which I launched IDLE. For instance, if I launched IDLE from a directory called 'tmp' in my home directory, the default save path is set to <code>~/tmp</code>. So start your IDLE like this:</p>
<pre><code>~/tmp $ idle
[...]
</code></pre>
| 0 | 2009-09-15T00:56:02Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 1,424,722 | <p>On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from th... | 1 | 2009-09-15T01:45:37Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 1,425,092 | <p>On OS X, if you launch <code>IDLE.app</code> (by double-clicking or using <code>open(1)</code>, for example), the default directory is hardwired to <code>~/Documents</code>. If you want to change the default permanently, you'll need to edit the file <code>idlemain.py</code> within the IDLE.app application bundle; d... | 6 | 2009-09-15T04:13:58Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 5,161,261 | <p>It seems like you can get idle into the directory you want if you run any module from that directory. </p>
<p>I had previously tried opening idlemain.py through the path browser. I was able to open and edit the file, but it seemed like I wasn't able to save my modifications.</p>
<p>I'm just glad to hear other peop... | 2 | 2011-03-01T22:37:14Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 20,500,218 | <p>I actually just discovered the easiest answer, if you use the shortcut link labeled "IDLE (Python GUI)". This is in Windows Vista, so I don't know if it'll work in other OS's.</p>
<p>1) Right-click "Properties".</p>
<p>2) Select "Shortcut" tab.</p>
<p>3) In "Start In", write file path (e.g. "C:\Users...").</p>
<... | 2 | 2013-12-10T16:44:46Z | [
"python",
"python-idle"
] |
Default save path for Python IDLE? | 1,424,398 | <p>Does anyone know where or how to set the default path/directory on saving python scripts prior to running? </p>
<p>On a Mac it wants to save them in the top level <code>~/Documents directory</code>. I would like to specify a real location. Any ideas?</p>
| 6 | 2009-09-14T23:28:28Z | 35,376,000 | <p>For OS X:</p>
<p>Open a new finder window,then head over to applications.
Locate your Python application. (For my mac,it's Python 3.5)</p>
<p>Double click on it.
Right click on the IDLE icon,show package contents.
Then go into the contents folder,then resources.</p>
<p><strong>Now,this is the important part:</str... | 1 | 2016-02-13T04:14:35Z | [
"python",
"python-idle"
] |
How do scripting languages use sockets? | 1,424,511 | <p>Python, Perl and PHP, all support <a href="http://en.wikipedia.org/wiki/Stream%5Fsocket" rel="nofollow">TCP stream sockets</a>. But exactly how do I use sockets in a script file that is run by a webserver (eg Apache), assuming I only have FTP access and not root access to the machine?</p>
<ol>
<li><p>When a client ... | 1 | 2009-09-15T00:14:40Z | 1,424,517 | <p>Scripting languages utilize sockets exactly the same way as compiled languages.</p>
<p>1) The script typically opens and uses the socket. It's not "run" or "invoked" by the socket, but directly controls it via libraries (typically calling into the native C API for the OS).</p>
<p>2) Yes.</p>
<p>3) Not necessaril... | 6 | 2009-09-15T00:17:44Z | [
"php",
"python",
"perl",
"sockets",
"scripting"
] |
How do scripting languages use sockets? | 1,424,511 | <p>Python, Perl and PHP, all support <a href="http://en.wikipedia.org/wiki/Stream%5Fsocket" rel="nofollow">TCP stream sockets</a>. But exactly how do I use sockets in a script file that is run by a webserver (eg Apache), assuming I only have FTP access and not root access to the machine?</p>
<ol>
<li><p>When a client ... | 1 | 2009-09-15T00:14:40Z | 1,424,526 | <p>The only way I can make sense of what you're asking is if you use <a href="http://en.wikipedia.org/wiki/Inetd" rel="nofollow">inetd</a> or a similar meta-server, which is configured to invoke your "service a single client" program for a specific listening port, forwarding your "single client servicer" program's stdi... | 1 | 2009-09-15T00:21:29Z | [
"php",
"python",
"perl",
"sockets",
"scripting"
] |
How do scripting languages use sockets? | 1,424,511 | <p>Python, Perl and PHP, all support <a href="http://en.wikipedia.org/wiki/Stream%5Fsocket" rel="nofollow">TCP stream sockets</a>. But exactly how do I use sockets in a script file that is run by a webserver (eg Apache), assuming I only have FTP access and not root access to the machine?</p>
<ol>
<li><p>When a client ... | 1 | 2009-09-15T00:14:40Z | 1,424,574 | <p>As a prior answer notes, scripting languages have operate in this regard in exactly the same way as compiled programs. Where they differ (potentially) is in the API that they use. The operating system (Windows or Unix-based) offers an API (e.g., <a href="http://en.wikipedia.org/wiki/Bsd%5Fsockets" rel="nofollow">BS... | 2 | 2009-09-15T00:40:24Z | [
"php",
"python",
"perl",
"sockets",
"scripting"
] |
How do scripting languages use sockets? | 1,424,511 | <p>Python, Perl and PHP, all support <a href="http://en.wikipedia.org/wiki/Stream%5Fsocket" rel="nofollow">TCP stream sockets</a>. But exactly how do I use sockets in a script file that is run by a webserver (eg Apache), assuming I only have FTP access and not root access to the machine?</p>
<ol>
<li><p>When a client ... | 1 | 2009-09-15T00:14:40Z | 1,426,746 | <blockquote>
<p>When a client connects to a specific
port, how does the script file get
invoked?</p>
</blockquote>
<p>The script should be already invoked in order to receive any connects from any client. You will need script to be hanging on there forever (infinie loop) and setup Apache not to kill it on timeou... | 1 | 2009-09-15T12:03:04Z | [
"php",
"python",
"perl",
"sockets",
"scripting"
] |
exposing or hiding objects of dependencies? | 1,424,534 | <p>Common scenario: I have a library that uses other libraries. For example, a math library (let's call it foo) that uses numpy.</p>
<p>Functions of foo can either:</p>
<ul>
<li>return a numpy object (either pure or an inherited reimplementation)</li>
<li>return a list</li>
<li>return a foo-implemented object that be... | 1 | 2009-09-15T00:24:27Z | 1,424,582 | <p>The main question I would think about is how much of your library would return numpy objects? If its pervasive I would go with directly returning a numpy as your so tied to numpy you might as well make it explicit. Plus it will probably make it easier to use other numpy based libraries. If on the other hand you o... | 2 | 2009-09-15T00:43:54Z | [
"python",
"design"
] |
exposing or hiding objects of dependencies? | 1,424,534 | <p>Common scenario: I have a library that uses other libraries. For example, a math library (let's call it foo) that uses numpy.</p>
<p>Functions of foo can either:</p>
<ul>
<li>return a numpy object (either pure or an inherited reimplementation)</li>
<li>return a list</li>
<li>return a foo-implemented object that be... | 1 | 2009-09-15T00:24:27Z | 1,424,903 | <p>Since you're talking about return values, that's not really about "internal objects" -- you should just document the interfaces your returned objects will support (it's OK if that's a subset of <code>numpy.array</code> or whatever;-). I recommend against returning a reference to your internal mutable attributes and ... | 3 | 2009-09-15T02:56:41Z | [
"python",
"design"
] |
Easy, Robust IPC between Python and PHP | 1,424,593 | <p>I have a python program which starts up a PHP script using the <code>subprocess.Popen()</code> function. The PHP script needs to communicate back-and-forth with Python, and I am trying to find an easy but robust way to manage the message sending/receiving.</p>
<p>I have already written a working protocol using basi... | 0 | 2009-09-15T00:47:39Z | 1,424,687 | <p>You could look at shared memory or named pipes, but I think there are two more likely options, assuming at least one of these languages is being used for a webapp:</p>
<p>A. Use your database's atomicity. In python, begin a transaction, put a message into a table, and end the transaction. From php, begin a transa... | 0 | 2009-09-15T01:33:18Z | [
"php",
"python",
"ipc"
] |
Easy, Robust IPC between Python and PHP | 1,424,593 | <p>I have a python program which starts up a PHP script using the <code>subprocess.Popen()</code> function. The PHP script needs to communicate back-and-forth with Python, and I am trying to find an easy but robust way to manage the message sending/receiving.</p>
<p>I have already written a working protocol using basi... | 0 | 2009-09-15T00:47:39Z | 1,424,691 | <p>It sounds like you want a generic RPC framework.</p>
<p>You should take a look at:</p>
<ul>
<li>Thrift <a href="http://incubator.apache.org/thrift/" rel="nofollow">http://incubator.apache.org/thrift/</a></li>
<li>XML RPC <a href="http://docs.python.org/library/xmlrpclib.html" rel="nofollow">http://docs.python.org/... | 2 | 2009-09-15T01:35:20Z | [
"php",
"python",
"ipc"
] |
Pad python floats | 1,424,638 | <p>I want to pad some percentage values so that there are always 3 units before the decimal place. With ints I could use '%03d' - is there an equivalent for floats? </p>
<p>'%.3f' works for after the decimal place but '%03f' does nothing.</p>
| 12 | 2009-09-15T01:07:56Z | 1,424,656 | <p>'%03.1f' works (1 could be any number, or empty string):</p>
<pre><code>>>> "%06.2f"%3.3
'003.30'
>>> "%04.f"%3.2
'0003'
</code></pre>
<p>Note that the field width includes the decimal and fractional digits.</p>
| 28 | 2009-09-15T01:18:13Z | [
"python",
"floating-point",
"zero",
"pad"
] |
Pad python floats | 1,424,638 | <p>I want to pad some percentage values so that there are always 3 units before the decimal place. With ints I could use '%03d' - is there an equivalent for floats? </p>
<p>'%.3f' works for after the decimal place but '%03f' does nothing.</p>
| 12 | 2009-09-15T01:07:56Z | 1,424,666 | <p>You could use zfill as well,.</p>
<pre><code>str(3.3).zfill(5)
'003.3'
</code></pre>
| 6 | 2009-09-15T01:21:24Z | [
"python",
"floating-point",
"zero",
"pad"
] |
Turn off Pygame alpha | 1,424,734 | <p>I have a computer game I'm working on, and I'm wanting to give the user an option to turn off alpha compositing for speed purposes. Rather than doing checks everywhere, does Pygame have a global option to say "Don't use alpha" such that it would just ignore all my calls to set_alpha and the likes? </p>
| 1 | 2009-09-15T01:49:17Z | 1,429,443 | <p>Considering the pygame docs I would say <em>"no, there is no global way to disable alpha"</em>.<br />
However there are at least two <em>'local'</em> ways to do it: </p>
<ul>
<li><p>First would be to subclass pygame.Surface and provide your own implementation of set_alpha
which in turn could honor your global alp... | 1 | 2009-09-15T20:29:25Z | [
"python",
"pygame",
"alphablending"
] |
Turn off Pygame alpha | 1,424,734 | <p>I have a computer game I'm working on, and I'm wanting to give the user an option to turn off alpha compositing for speed purposes. Rather than doing checks everywhere, does Pygame have a global option to say "Don't use alpha" such that it would just ignore all my calls to set_alpha and the likes? </p>
| 1 | 2009-09-15T01:49:17Z | 15,567,788 | <p>I have read that the convert()-function disables image's alpha.
What I know is: </p>
<p>Using the convert()-function speeds up blitting the image for screen-big images on my computer to around 150 FPS with a colour depth of 16 bit.</p>
<pre><code>image = image.convert()#video system has to be initialed
</code></pr... | 0 | 2013-03-22T10:15:10Z | [
"python",
"pygame",
"alphablending"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,425,056 | <p>I believe xmpp implementation is one which is being use by a lot of big companies but the common thing is to use a comet server as well.</p>
<p>a lot of implementation in python for thoses you can google around.</p>
| 1 | 2009-09-15T03:57:08Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,425,061 | <p>How about <a href="http://orbited.org" rel="nofollow">Orbited</a>, it's very good and being used by <a href="http://echowaves.com" rel="nofollow">Echowaves</a></p>
| 3 | 2009-09-15T03:58:23Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,425,072 | <p>I'm using Orbited right now, it's great!</p>
<p>If you are doing chat or subscription type stuff use <code>stompservice</code> and orbited.</p>
<p>If you are doing 1 to 1 client mapping use <code>TCPSocket</code>.</p>
<p>I can give you some code examples if you want.</p>
| 3 | 2009-09-15T04:05:21Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,425,078 | <p>Comet is the protocol you want. What Comet implementation is best, is a harder call.</p>
<p>If you're OK with Java (or, I guess, Jython), or .NET (where IronPython's a possibility), I suspect (<em>not</em> having extensively tried them all!-) that <a href="http://www.stream-hub.com/" rel="nofollow">stream hub</a> m... | 3 | 2009-09-15T04:07:12Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,425,133 | <p>What about <a href="http://www.ape-project.org/" rel="nofollow">Ajax Push Engine</a>? </p>
| 2 | 2009-09-15T04:36:15Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 1,507,086 | <p>Have you tried <a href="http://www.stream-hub.com/" rel="nofollow">StreamHub Push Server</a>?</p>
| 0 | 2009-10-01T23:49:12Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 2,037,689 | <p>I'm personally biased, but I like <a href="http://www.frozenmountain.com/websync" rel="nofollow">WebSync, for IIS/.NET</a>. It integrates with IIS, so no other server software necessary, just a dll to add to your project.</p>
| 2 | 2010-01-10T16:51:04Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Implementing Server Push | 1,425,048 | <p>Read about Server push <a href="http://en.wikipedia.org/wiki/Push%5Ftechnology">here</a>.<br />
I want to push data to client from my web application in real time.<br />
I was looking at TCP sockets as one of the options.<br />
For HTTP I found a variety of frameworks for Java, PHP, Python and others over <a href="h... | 6 | 2009-09-15T03:54:17Z | 3,756,542 | <p>Ok, I'm using ASP.NET with <a href="http://pokein.com" rel="nofollow">PokeIn</a> comet ajax library on my project. Also, I tried <a href="https://atmosphere.dev.java.net/" rel="nofollow">Atmosphere</a> under JAVA.. My last choice was PokeIn.. Because, only server push support is not solving the problems. You will n... | 3 | 2010-09-21T00:42:01Z | [
"java",
"php",
"python",
"ruby",
"server-push"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 1,425,312 | <p>I have a database with all of this data and some access tools. I made mine from the census tiger data. I imagine it'd basically be an export of my database to sqlite and a bit of code translation.</p>
| 0 | 2009-09-15T05:38:49Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 1,425,330 | <p>I would stay away from implementing your own solution from scratch. This is a pretty big undertaking and there are already tools out there to do this. If you're looking for an open source approach (read: free), take a look at this blog post: <a href="http://www.macgeekery.com/hacks/software/using%5Fpostgis%5Frever... | 4 | 2009-09-15T05:45:16Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 1,425,334 | <p>I suggest using a variant of your first idea: Use a <a href="http://en.wikipedia.org/wiki/Spatial%5Findex">spatial index</a>. A spatial index is a data structure built from rectangles, mapping lat/long to the payload. In this case you will probably map rectangles to state-province pairs. An <a href="http://en.wikipe... | 6 | 2009-09-15T05:46:24Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 1,425,355 | <p>If you can get hold of state boundaries as polygons (for example, via OpenStreetMap), determining the current state is just a point-in-polygon test. </p>
<p>If you need address data, an offline solution would be to use Microsoft Mappoint. </p>
| 1 | 2009-09-15T05:53:00Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 1,591,032 | <p>You can get data for the entire united states from <a href="http://www.openstreetmap.org/" rel="nofollow">open street map</a> You could then extract the data you need such as city or state locations into what ever format works best for your application. Note although data quality is good it isn't guaranteed to be co... | 1 | 2009-10-19T20:43:17Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Reverse Geocoding Without Web Access | 1,425,149 | <p>I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another.<... | 7 | 2009-09-15T04:42:17Z | 24,887,665 | <p>I created an offline reverse geocoding module for countries: <a href="https://bitbucket.org/richardpenman/reverse_geocode" rel="nofollow">https://bitbucket.org/richardpenman/reverse_geocode</a></p>
<pre><code>>>> import reverse_geocode
>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>&g... | 2 | 2014-07-22T12:38:55Z | [
"python",
"gps",
"geocoding",
"reverse-geocoding"
] |
Symmetrically adressable matrix | 1,425,162 | <p>I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to f... | 1 | 2009-09-15T04:48:36Z | 1,425,181 | <p>You only need to store the lower triangle of the matrix. Typically this is done with one n(n+1)/2 length list. You'll need to overload the <code>__getitem__</code> method to interpret what the entry means.</p>
| 1 | 2009-09-15T04:55:10Z | [
"python",
"data-structures",
"matrix"
] |
Symmetrically adressable matrix | 1,425,162 | <p>I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to f... | 1 | 2009-09-15T04:48:36Z | 1,425,298 | <p>Golub and Van Loan's "Matrix Computations" book outlines a feasible addressing scheme:</p>
<p>You pack the data in to a vector and access as follows, assuming i >= j:</p>
<pre><code>a_ij = A.vec((j-1)n - j(j-1)/2 + i)
</code></pre>
| 3 | 2009-09-15T05:34:22Z | [
"python",
"data-structures",
"matrix"
] |
Symmetrically adressable matrix | 1,425,162 | <p>I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to f... | 1 | 2009-09-15T04:48:36Z | 1,425,305 | <p>You're probably better off using a full square numpy matrix. Yes, it wastes half the memory storing redundant values, but rolling your own symmetric matrix in Python will waste even more memory and CPU by storing and processing the integers as Python objects. </p>
| 2 | 2009-09-15T05:36:33Z | [
"python",
"data-structures",
"matrix"
] |
Symmetrically adressable matrix | 1,425,162 | <p>I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to f... | 1 | 2009-09-15T04:48:36Z | 1,430,312 | <p>A simpler and cleaner way is to just use a dictionary with sorted tuples as keys. The tuples correspond with your matrix index. Override <code>__getitem__</code> and <code>__setitem__</code> to access the dictionary by sorted tuples; here's an example class:</p>
<pre><code>class Matrix(dict):
def __getitem__(se... | 1 | 2009-09-16T00:33:48Z | [
"python",
"data-structures",
"matrix"
] |
PHP equivalent for a python decorator? | 1,425,303 | <p>I want to be able to wrap a PHP function by another function, but leaving its original name/parameter list intact.</p>
<p>For instance:</p>
<pre><code>function A() {
print "inside A()\n";
}
function Wrap_A() {
print "Calling A()\n";
A();
print "Finished calling A()\n";
}
// <--- Do some magic ... | 7 | 2009-09-15T05:36:03Z | 1,425,364 | <p>maybe youâre looking for <a href="http://php.net/call%5Fuser%5Ffunc%5Farray" rel="nofollow"><code>call_user_func_array</code></a>:</p>
<pre><code>function wrapA() {
$args = func_get_args();
return call_user_func_array('A', $args);
}
</code></pre>
<p>since PHP 5.3 you could even say:</p>
<pre><code>return ca... | 1 | 2009-09-15T05:54:06Z | [
"php",
"python",
"function",
"decorator",
"wrapper"
] |
PHP equivalent for a python decorator? | 1,425,303 | <p>I want to be able to wrap a PHP function by another function, but leaving its original name/parameter list intact.</p>
<p>For instance:</p>
<pre><code>function A() {
print "inside A()\n";
}
function Wrap_A() {
print "Calling A()\n";
A();
print "Finished calling A()\n";
}
// <--- Do some magic ... | 7 | 2009-09-15T05:36:03Z | 1,425,417 | <p>You can't do this with functions in PHP. In other dynamic languages, such as Perl and Ruby, you can redefine previously defined functions, but PHP throws a fatal error when you attempt to do so.</p>
<p>In 5.3, you can create an <a href="http://us2.php.net/manual/en/functions.anonymous.php" rel="nofollow">anonymous... | 1 | 2009-09-15T06:11:10Z | [
"php",
"python",
"function",
"decorator",
"wrapper"
] |
PHP equivalent for a python decorator? | 1,425,303 | <p>I want to be able to wrap a PHP function by another function, but leaving its original name/parameter list intact.</p>
<p>For instance:</p>
<pre><code>function A() {
print "inside A()\n";
}
function Wrap_A() {
print "Calling A()\n";
A();
print "Finished calling A()\n";
}
// <--- Do some magic ... | 7 | 2009-09-15T05:36:03Z | 1,425,420 | <p>Apparently <a href="http://php.net/runkit">runkit</a> might <a href="http://php.net/manual/en/function.runkit-function-redefine.php">help you</a>.</p>
<p>Also, you can always do this the OO way. Put the original fun in a class, and the decorator into an extended class. Instantiate and go.</p>
| 6 | 2009-09-15T06:12:14Z | [
"php",
"python",
"function",
"decorator",
"wrapper"
] |
PHP equivalent for a python decorator? | 1,425,303 | <p>I want to be able to wrap a PHP function by another function, but leaving its original name/parameter list intact.</p>
<p>For instance:</p>
<pre><code>function A() {
print "inside A()\n";
}
function Wrap_A() {
print "Calling A()\n";
A();
print "Finished calling A()\n";
}
// <--- Do some magic ... | 7 | 2009-09-15T05:36:03Z | 34,095,650 | <p>Here is my method of mimicking decorators from python in php.</p>
<pre><code>function call_decorator ($decorator, $function, $args, $kwargs) {
// Call the decorator and pass the function to it
$decorator($function, $args, $kwargs);
}
function testing ($args, $kwargs) {
echo PHP_EOL . 'test 1234' . PHP... | 1 | 2015-12-04T19:04:29Z | [
"php",
"python",
"function",
"decorator",
"wrapper"
] |
Reverse engineer SQLAlchemy declarative class definition from existing MySQL database? | 1,425,412 | <p>I have a pre-existing mysql database containing around 50 tables.</p>
<p>Rather than hand code a declarative style SqlAlchemy class (<a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-class-and-mapper-all-at-once-declaratively">as shown here</a>) for each table, is there a tool/script/comman... | 20 | 2009-09-15T06:09:40Z | 1,425,452 | <p><a href="http://www.sqlalchemy.org/trac/wiki/SqlSoup" rel="nofollow">SqlSoup</a> can perform introspective mapping of an existing SQL schema.</p>
| 4 | 2009-09-15T06:24:43Z | [
"python",
"mysql",
"sqlalchemy"
] |
Reverse engineer SQLAlchemy declarative class definition from existing MySQL database? | 1,425,412 | <p>I have a pre-existing mysql database containing around 50 tables.</p>
<p>Rather than hand code a declarative style SqlAlchemy class (<a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-class-and-mapper-all-at-once-declaratively">as shown here</a>) for each table, is there a tool/script/comman... | 20 | 2009-09-15T06:09:40Z | 1,426,387 | <p>use <a href="http://code.google.com/p/sqlautocode/">sqlautocode</a>:</p>
<p>It is a flexible tool to autogenerate a model from an existing database.</p>
<p>This is a slightly different approach to <a href="http://www.sqlalchemy.org/trac/wiki/SqlSoup">SqlSoup</a>, which lets you use tables without explicitly defini... | 27 | 2009-09-15T10:42:34Z | [
"python",
"mysql",
"sqlalchemy"
] |
Reverse engineer SQLAlchemy declarative class definition from existing MySQL database? | 1,425,412 | <p>I have a pre-existing mysql database containing around 50 tables.</p>
<p>Rather than hand code a declarative style SqlAlchemy class (<a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-class-and-mapper-all-at-once-declaratively">as shown here</a>) for each table, is there a tool/script/comman... | 20 | 2009-09-15T06:09:40Z | 1,429,686 | <p>Keep in mind declarative can be used with reflected tables. So if startup time weren't a huge issue you could do this:</p>
<pre><code>engine = create_engine('mysql://...')
meta = MetaData()
meta.reflect(bind=engine)
for table in meta.tables.values():
print """
class %s(Base):
__table__ = Table(%r, Base.met... | 6 | 2009-09-15T21:20:53Z | [
"python",
"mysql",
"sqlalchemy"
] |
Reverse engineer SQLAlchemy declarative class definition from existing MySQL database? | 1,425,412 | <p>I have a pre-existing mysql database containing around 50 tables.</p>
<p>Rather than hand code a declarative style SqlAlchemy class (<a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-class-and-mapper-all-at-once-declaratively">as shown here</a>) for each table, is there a tool/script/comman... | 20 | 2009-09-15T06:09:40Z | 28,328,981 | <p>Now (in 2015) you probably would want to use <a href="https://pypi.python.org/pypi/sqlacodegen" rel="nofollow">https://pypi.python.org/pypi/sqlacodegen</a> instead!</p>
| 4 | 2015-02-04T18:43:36Z | [
"python",
"mysql",
"sqlalchemy"
] |
Method assignment and objects | 1,425,414 | <p>i've got a problem with python:
I want to assign a method to an object form another class, but in this method use its own attributes. Since i have many container with different use methods in my project (not in that example) i dont want to use inheritance, thad would force me to create a custom class for each instan... | 3 | 2009-09-15T06:09:52Z | 1,425,472 | <p>Looks like you are trying to use inheritance? The tree inherits from the container?</p>
| 1 | 2009-09-15T06:34:44Z | [
"python"
] |
Method assignment and objects | 1,425,414 | <p>i've got a problem with python:
I want to assign a method to an object form another class, but in this method use its own attributes. Since i have many container with different use methods in my project (not in that example) i dont want to use inheritance, thad would force me to create a custom class for each instan... | 3 | 2009-09-15T06:09:52Z | 1,425,475 | <p>Here you go. You should know that self.test is already bound since by the time you are in __init__ the instance has already been created and its methods are bound. Therefore you must access the unbound member by using the im_func member, and binding it with MethodType.</p>
<pre><code>import types
class container()... | 2 | 2009-09-15T06:35:42Z | [
"python"
] |
Method assignment and objects | 1,425,414 | <p>i've got a problem with python:
I want to assign a method to an object form another class, but in this method use its own attributes. Since i have many container with different use methods in my project (not in that example) i dont want to use inheritance, thad would force me to create a custom class for each instan... | 3 | 2009-09-15T06:09:52Z | 1,425,478 | <p>Use tree.test instead of self.test. The method attributes of an instance are bound to that instance.</p>
| 1 | 2009-09-15T06:35:52Z | [
"python"
] |
Method assignment and objects | 1,425,414 | <p>i've got a problem with python:
I want to assign a method to an object form another class, but in this method use its own attributes. Since i have many container with different use methods in my project (not in that example) i dont want to use inheritance, thad would force me to create a custom class for each instan... | 3 | 2009-09-15T06:09:52Z | 1,426,466 | <p>Do not move methods around dynamically.</p>
<p>Just Use Delegation. Avoid Magic.</p>
<p>Pass the "Tree" object to the Container. It saves trying to move methods around.</p>
<pre><code>class Container( object ):
def use( self, context ):
print context.info
context.test()
class Tree( object ... | 1 | 2009-09-15T10:58:52Z | [
"python"
] |
Convert hex to binary | 1,425,493 | <p>I have ABC123EFFF.</p>
<p>I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).</p>
<p>How?</p>
| 49 | 2009-09-15T06:41:37Z | 1,425,500 | <pre><code>import binascii
binary_string = binascii.unhexlify(hex_string)
</code></pre>
<p>Read</p>
<p><a href="http://docs.python.org/library/binascii.html#binascii.unhexlify">binascii.unhexlify</a></p>
<p>Return the binary data represented by the hexadecimal string specified as the parameter.</p>
| 35 | 2009-09-15T06:45:15Z | [
"python",
"string",
"binary",
"hex",
"string-formatting"
] |
Convert hex to binary | 1,425,493 | <p>I have ABC123EFFF.</p>
<p>I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).</p>
<p>How?</p>
| 49 | 2009-09-15T06:41:37Z | 1,425,506 | <p>Replace each hex digit with the corresponding 4 binary digits:</p>
<pre><code>1 - 0001
2 - 0010
...
a - 1010
b - 1011
...
f - 1111
</code></pre>
| 0 | 2009-09-15T06:46:10Z | [
"python",
"string",
"binary",
"hex",
"string-formatting"
] |
Convert hex to binary | 1,425,493 | <p>I have ABC123EFFF.</p>
<p>I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).</p>
<p>How?</p>
| 49 | 2009-09-15T06:41:37Z | 1,425,558 | <pre><code>bin(int("abc123efff", 16))[2:]
</code></pre>
| 26 | 2009-09-15T06:59:24Z | [
"python",
"string",
"binary",
"hex",
"string-formatting"
] |
Convert hex to binary | 1,425,493 | <p>I have ABC123EFFF.</p>
<p>I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).</p>
<p>How?</p>
| 49 | 2009-09-15T06:41:37Z | 1,427,846 | <p>Here's a fairly raw way to do it using bit fiddling to generate the binary strings.</p>
<p>The key bit to understand is:</p>
<pre><code>(n & (1 << i)) and 1</code></pre>
<p>Which will generate either a 0 or 1 if the i'th bit of n is set.</p>
<pre><code>
import binascii
def byte_to_binary(n):
return ''... | 9 | 2009-09-15T15:22:44Z | [
"python",
"string",
"binary",
"hex",
"string-formatting"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.