title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python, a smarter way of string to integer conversion | 2,499,966 | <p>Hello
I have written this code to convert string in such format "0(532) 222 22 22" to integer such as 05322222222 .</p>
<pre><code>class Phone():
def __init__(self,input):
self.phone = input
def __str__(self):
return self.phone
#convert to integer.
def to_int(self):
return i... | 1 | 2010-03-23T12:53:27Z | 2,504,996 | <p>How about just using regular expressions?</p>
<p>Example:</p>
<pre><code>>>> import re
>>> num = '0(532) 222 22 22'
>>> re.sub('[\D]', '', num) # Match all non-digits ([\D]), replace them with empty string, where found in the `num` variable.
'05322222222'
</code></pre>
<p>The suggestion... | 1 | 2010-03-24T02:38:57Z | [
"python",
"string",
"integer",
"type-conversion"
] |
Python, a smarter way of string to integer conversion | 2,499,966 | <p>Hello
I have written this code to convert string in such format "0(532) 222 22 22" to integer such as 05322222222 .</p>
<pre><code>class Phone():
def __init__(self,input):
self.phone = input
def __str__(self):
return self.phone
#convert to integer.
def to_int(self):
return i... | 1 | 2010-03-23T12:53:27Z | 2,518,736 | <p>SilentGhost: <code>dis.dis</code> <em>does</em> demonstrate underlying conceptual / executional complexity. after all, the OP complained about the original replacement chain being too âclumsyâ, not too âslowâ. </p>
<p>i recommend against using regular expressions where not inevitable; they just add conceptu... | -1 | 2010-03-25T19:30:21Z | [
"python",
"string",
"integer",
"type-conversion"
] |
What are some strategies to add spell checking to a Google App Engine program? | 2,500,093 | <p>I'm working on a Google App Engine program that will require some basic spell checking features. Normally iSpell or it's cousins would be options, but I'm not sure that will work in GEA. Are there other strategies/tools that would work in that environment? </p>
| 0 | 2010-03-23T13:12:54Z | 2,500,894 | <p>A very minimal, pure-Python spell checker can be found here: <a href="http://norvig.com/spell-correct.html" rel="nofollow">http://norvig.com/spell-correct.html</a></p>
<p>The <code>big.txt</code> file Norvig uses to train his spell checker is too large to upload to App Engine at 6.2 megabytes, but the <code>NWORDS<... | 1 | 2010-03-23T14:58:35Z | [
"python",
"google-app-engine",
"spell-checking"
] |
What are some strategies to add spell checking to a Google App Engine program? | 2,500,093 | <p>I'm working on a Google App Engine program that will require some basic spell checking features. Normally iSpell or it's cousins would be options, but I'm not sure that will work in GEA. Are there other strategies/tools that would work in that environment? </p>
| 0 | 2010-03-23T13:12:54Z | 2,502,641 | <p>I personally would try to go down the route of using Google's API for spellcheck. I'm trying to find it now, but I believe their exposed web service includes a spell checker.</p>
<p>It's always tough finding good python libraries that are actually being maintained. On the other hand, I imagine Google's service sh... | 0 | 2010-03-23T18:38:44Z | [
"python",
"google-app-engine",
"spell-checking"
] |
in Python find number of same elements in 2 lists | 2,500,124 | <p>In Python if I have 2 lists say:</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
</code></pre>
<p>is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)</p>
<p>I know I could just do a nested loop but is there not a built in function like in php wi... | 4 | 2010-03-23T13:17:40Z | 2,500,136 | <p>You can use a set intersection for that :)</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
set(l1).intersection(l2)
set(['c', 'd'])
</code></pre>
| 9 | 2010-03-23T13:18:49Z | [
"python",
"arrays",
"array-intersect"
] |
in Python find number of same elements in 2 lists | 2,500,124 | <p>In Python if I have 2 lists say:</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
</code></pre>
<p>is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)</p>
<p>I know I could just do a nested loop but is there not a built in function like in php wi... | 4 | 2010-03-23T13:17:40Z | 2,500,142 | <pre><code>>>> l1 = ['a', 'b', 'c', 'd']
>>> l2 = ['c', 'd', 'e']
>>> set(l1) & set(l2)
set(['c', 'd'])
</code></pre>
| 6 | 2010-03-23T13:19:26Z | [
"python",
"arrays",
"array-intersect"
] |
in Python find number of same elements in 2 lists | 2,500,124 | <p>In Python if I have 2 lists say:</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
</code></pre>
<p>is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)</p>
<p>I know I could just do a nested loop but is there not a built in function like in php wi... | 4 | 2010-03-23T13:17:40Z | 2,500,158 | <p>If you only have unique elements, you can use the set data type and use intersection:</p>
<pre><code>s1, s2 = set(l1), set(l2)
num = len(s1.intersection(s2))
</code></pre>
| 5 | 2010-03-23T13:21:27Z | [
"python",
"arrays",
"array-intersect"
] |
in Python find number of same elements in 2 lists | 2,500,124 | <p>In Python if I have 2 lists say:</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
</code></pre>
<p>is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)</p>
<p>I know I could just do a nested loop but is there not a built in function like in php wi... | 4 | 2010-03-23T13:17:40Z | 2,500,227 | <p>Using sets:</p>
<pre><code>l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
def list_count_common(list_a, list_b):
result = len(list(set(list_a) & set(list_b))) ## this is the line that does what you want
return result
print list_count_common(l1, l2) ## prints 2
</code></pre>
| 1 | 2010-03-23T13:29:33Z | [
"python",
"arrays",
"array-intersect"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,396 | <p>Use sed.</p>
<pre><code>for file in *
do
sed -i '' '2s/ / /' "$file"
done
</code></pre>
<p>The <code>-i ''</code> flag means to edit in-place without a backup.</p>
<p>Or use ed!</p>
<pre><code>for file in *
do
printf "2s/ / /\nwq\n" |ed -s "$file"
done
</code></pre>
| 6 | 2010-03-23T13:52:30Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,416 | <p>Performing line-based changes to text files is often simplest to do in <code>sed</code>.</p>
<pre><code>sed -e '2s/ */ /g' infile.txt
</code></pre>
<p>will replace any runs of multiple spaces with a single space. This may be changing more than you want, though.</p>
<pre><code>sed -e '2s/^\([^ ]*\) /\1 /' infil... | 9 | 2010-03-23T13:55:44Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,427 | <p>I don't quite understand, but yes, <code>sed</code> is an option. I don't think any POSIX compliant version of <code>sed</code> has an in file option (-i), so a fully POSIX compliant solution would be.</p>
<pre><code>sed -e 's/^BBB /BBB /' <file> > <newfile>
</code></pre>
| 1 | 2010-03-23T13:56:44Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,456 | <p>This answer assumes you don't want to mess with any except the second line.</p>
<pre><code>#!/usr/bin/env python
import sys, os
for fname in sys.argv[1:]:
with open(fname, "r") as fin:
line1 = fin.readline()
line2 = fin.readline()
fixedLine2 = " ".join(line2.split()) + '\n'
if fi... | 1 | 2010-03-23T13:59:10Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,478 | <p>Use sed:</p>
<pre><code>sed -e 's/[[:space:]][[:space:]]/ /g' yourfile.txt >> newfile.txt
</code></pre>
<p>This will replace any two adjacent spaces with one. The use of [[:space:]] just makes it a little bit clearer</p>
| 1 | 2010-03-23T14:02:13Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,497 | <p>if the error always can occur at 2nd line, </p>
<pre><code>for file in file*
do
awk 'NR==2{$1=$1}1' file >temp
mv temp "$file"
done
</code></pre>
<p>or sed</p>
<pre><code>sed -i.bak '2s/ */ /' file* # do 2nd line
</code></pre>
<p>Or just pure bash scripting</p>
<pre><code>i=1
while read -r line
... | 4 | 2010-03-23T14:04:39Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,500,515 | <p>I am going to be different and go with AWK:</p>
<pre><code>awk '{print $1,$2,$3}' file.txt > file1.txt
</code></pre>
<p>This will handle any number of spaces between fields, and replace them with one space</p>
<p>To handle a specific line you can add line addresses:</p>
<pre><code>awk 'NR==2{print $1,$2,$3} N... | 2 | 2010-03-23T14:07:10Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,501,547 | <p>Since it seems every column is separated by one space, another approach not yet mentioned is to use tr to squeeze all multi spaces into single spaces:
<br>
tr -s " " < infile > outfile</p>
| 2 | 2010-03-23T16:08:35Z | [
"python",
"bash"
] |
Bash or python for changing spacing in files | 2,500,358 | <p>I have a set of 10000 files. In all of them, the second line, looks like:</p>
<pre><code>AAA 3.429 3.84
</code></pre>
<p>so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.</p>
<p>Randomly,... | 3 | 2010-03-23T13:47:52Z | 2,506,575 | <pre><code>sed -i -e '2s/ / /g' input.txt
</code></pre>
<p>-i: edit files in place</p>
| 0 | 2010-03-24T09:40:08Z | [
"python",
"bash"
] |
Fake serial communication under Linux | 2,500,420 | <p>I have an application where I want to simulate the connection between a device and a "modem". The device will be connected to a serial port and will talk to the software modem through that.</p>
<p>For testing purposes I want to be able to use a mock software device to test send and receive data.</p>
<p>Example Pyt... | 14 | 2010-03-23T13:55:58Z | 2,501,085 | <p>It's probably best to use <a href="http://pyserial.sourceforge.net/index.html">pyserial</a> to communicate with the serial port, and you can just create a mock version of the <code>serial.Serial</code> class which implements <code>read</code>, <code>readline</code>, <code>write</code> and any other methods you need.... | 6 | 2010-03-23T15:21:10Z | [
"python",
"linux",
"serial-port"
] |
Fake serial communication under Linux | 2,500,420 | <p>I have an application where I want to simulate the connection between a device and a "modem". The device will be connected to a serial port and will talk to the software modem through that.</p>
<p>For testing purposes I want to be able to use a mock software device to test send and receive data.</p>
<p>Example Pyt... | 14 | 2010-03-23T13:55:58Z | 2,504,486 | <p>You are on the right track with pseudo-terminals. To do this, your mock software device needs to first open a pseudo-terminal master - this is the file descriptor it will read from and write to, when it is talking to the serial software that you're testing. It then needs to grant access to and unlock the pseudo-te... | 5 | 2010-03-23T23:56:18Z | [
"python",
"linux",
"serial-port"
] |
Fake serial communication under Linux | 2,500,420 | <p>I have an application where I want to simulate the connection between a device and a "modem". The device will be connected to a serial port and will talk to the software modem through that.</p>
<p>For testing purposes I want to be able to use a mock software device to test send and receive data.</p>
<p>Example Pyt... | 14 | 2010-03-23T13:55:58Z | 9,229,751 | <p>Here's pythonic version of pts-emulated (caf's) serial communication:</p>
<pre><code>from serial import Serial
driver = MyDriver() # what I want to test
peer = serial.Serial()
driver.port.fd, peer.fd = posix.openpty()
driver.port._reconfigurePort()
peer.setTimeout(timeout=0.1)
peer._reconfigurePort()
driver.start... | 1 | 2012-02-10T15:01:20Z | [
"python",
"linux",
"serial-port"
] |
Discrete and Continuous Classifier on Sparse Data | 2,500,467 | <p>I'm trying to classify an example, which contains discrete and continuous features. Also, the example represents sparse data, so even though the system may have been trained on 100 features, the example may only have 12.</p>
<p>What would be the best classifier algorithm to use to accomplish this? I've been looking... | 3 | 2010-03-23T14:00:41Z | 2,501,850 | <p><a href="http://en.wikipedia.org/wiki/Support_vector_machine" rel="nofollow">Support vector machines</a>? <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/" rel="nofollow">libsvm</a> can be used from Python, and is quite speedy.</p>
<p>Handles sparse vector inputs, and won't mind if some of the features are contin... | 2 | 2010-03-23T16:47:59Z | [
"java",
"python",
"machine-learning",
"classification"
] |
Discrete and Continuous Classifier on Sparse Data | 2,500,467 | <p>I'm trying to classify an example, which contains discrete and continuous features. Also, the example represents sparse data, so even though the system may have been trained on 100 features, the example may only have 12.</p>
<p>What would be the best classifier algorithm to use to accomplish this? I've been looking... | 3 | 2010-03-23T14:00:41Z | 2,504,368 | <p><a href="http://www.cs.waikato.ac.nz/~ml/weka/" rel="nofollow">Weka</a> (Java) satisfies all you requirements:</p>
<ul>
<li>a large number of <a href="http://wiki.pentaho.com/display/DATAMINING/Classifiers" rel="nofollow">classification/regression</a> algorithms</li>
<li>support for discrete/continous (called nomin... | 2 | 2010-03-23T23:22:54Z | [
"java",
"python",
"machine-learning",
"classification"
] |
Discrete and Continuous Classifier on Sparse Data | 2,500,467 | <p>I'm trying to classify an example, which contains discrete and continuous features. Also, the example represents sparse data, so even though the system may have been trained on 100 features, the example may only have 12.</p>
<p>What would be the best classifier algorithm to use to accomplish this? I've been looking... | 3 | 2010-03-23T14:00:41Z | 8,699,207 | <p><a href="http://scikit-learn.org/0.9/index.html" rel="nofollow">scikit-learn</a>, a Python machine learning module supports <a href="http://scikit-learn.org/0.9/modules/sgd.html#stochastic-gradient-descent-for-sparse-data" rel="nofollow">Stochastic Gradient Descent</a> and <a href="http://scikit-learn.org/0.9/module... | 2 | 2012-01-02T09:28:53Z | [
"java",
"python",
"machine-learning",
"classification"
] |
Getting libstdc++-v3/python | 2,500,521 | <p>I am trying to download libstdc++-v3/python to enable pretty printing of stl containers. However, my provider returns: <strong>svn: Unknown hostname 'gcc.gnu.org'</strong> error. This is the command: </p>
<pre><code>svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
</code></pre>
<p><strong>Is there an al... | 5 | 2010-03-23T14:08:23Z | 2,500,691 | <p>try http:// instead of svn://
that would be :
svn co <a href="http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python">http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python</a></p>
| 7 | 2010-03-23T14:33:23Z | [
"c++",
"python",
"svn",
"download",
"gdb"
] |
Getting libstdc++-v3/python | 2,500,521 | <p>I am trying to download libstdc++-v3/python to enable pretty printing of stl containers. However, my provider returns: <strong>svn: Unknown hostname 'gcc.gnu.org'</strong> error. This is the command: </p>
<pre><code>svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
</code></pre>
<p><strong>Is there an al... | 5 | 2010-03-23T14:08:23Z | 36,378,878 | <p>I had the same problem it worked with </p>
<p><a href="https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/" rel="nofollow">https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/</a></p>
| 0 | 2016-04-02T21:23:28Z | [
"c++",
"python",
"svn",
"download",
"gdb"
] |
Spaceship objects | 2,500,584 | <p>I'm trying to make a program which creates a spaceship and I'm using the status() method to display the ship's name and fuel values. However, it doesn't seem to be working. I think I may have messed something up with the status() method. I'm also trying to make it so that I can change the fuel values, but I don't wa... | 3 | 2010-03-23T14:16:56Z | 2,500,621 | <p>In your <code>status</code> method <code>self</code> is not defined, because you made it a static method. It makes more sense to make it non-static, since every ship has its individual name. So just say</p>
<pre><code>def status(self):
print "Name: ", self.name
print "Fuel level: ", self.fuel
</code></pre>
... | 4 | 2010-03-23T14:21:46Z | [
"python",
"object",
"static-methods"
] |
Spaceship objects | 2,500,584 | <p>I'm trying to make a program which creates a spaceship and I'm using the status() method to display the ship's name and fuel values. However, it doesn't seem to be working. I think I may have messed something up with the status() method. I'm also trying to make it so that I can change the fuel values, but I don't wa... | 3 | 2010-03-23T14:16:56Z | 2,500,813 | <p>Each ship has its own fuel, so static isn't the way to go. If you don't want the parameter to look like a method, consider a property. It encapsulates the value-checking of the fuel as well.</p>
<pre><code>class Ship(object):
def __init__(self, name="Enterprise", fuel=0):
self.name = name
sel... | 4 | 2010-03-23T14:48:27Z | [
"python",
"object",
"static-methods"
] |
Defining the context of a word - Python | 2,500,732 | <p>I think this is an interesting question, at least for me.</p>
<hr>
<p>I have a <strong>list of words</strong>, let's say: </p>
<blockquote>
<p>photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet</p>
</blockquote>
<p>and I have a <strong>list of c... | 6 | 2010-03-23T14:37:30Z | 2,500,785 | <p>This sounds like it's more of a categorization/ontology problem than NLP. Try <a href="http://wordnet.princeton.edu/" rel="nofollow">WordNet</a> for a standard ontology.</p>
<p>I don't see any real NLP in your stated problem, but if you do need some semantic analysis or a parser try <a href="http://www.nltk.org/" r... | 3 | 2010-03-23T14:45:17Z | [
"python",
"django",
"dictionary",
"nlp"
] |
Defining the context of a word - Python | 2,500,732 | <p>I think this is an interesting question, at least for me.</p>
<hr>
<p>I have a <strong>list of words</strong>, let's say: </p>
<blockquote>
<p>photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet</p>
</blockquote>
<p>and I have a <strong>list of c... | 6 | 2010-03-23T14:37:30Z | 2,500,786 | <p>Where do these words come from? Do they come from real texts. If they are then it is a classic data mining problem. What you need to do is to your set of documents into the matrix where rows represent which document the word came from and the columns represent the words in the documents.</p>
<p>For example if yo... | 2 | 2010-03-23T14:45:26Z | [
"python",
"django",
"dictionary",
"nlp"
] |
Defining the context of a word - Python | 2,500,732 | <p>I think this is an interesting question, at least for me.</p>
<hr>
<p>I have a <strong>list of words</strong>, let's say: </p>
<blockquote>
<p>photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet</p>
</blockquote>
<p>and I have a <strong>list of c... | 6 | 2010-03-23T14:37:30Z | 2,501,089 | <p>I just found this a couple days ago: <a href="http://conceptnet.media.mit.edu/" rel="nofollow">ConceptNet</a></p>
<p>It's a commonsense ontology, so it might not be as specific as you would like, but it has a python API and you can download their entire database (currently around 1GB decompressed). Just keep in min... | 2 | 2010-03-23T15:21:59Z | [
"python",
"django",
"dictionary",
"nlp"
] |
Defining the context of a word - Python | 2,500,732 | <p>I think this is an interesting question, at least for me.</p>
<hr>
<p>I have a <strong>list of words</strong>, let's say: </p>
<blockquote>
<p>photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet</p>
</blockquote>
<p>and I have a <strong>list of c... | 6 | 2010-03-23T14:37:30Z | 2,509,806 | <p>The answer to your question obviously depends on the target taxonomy you are trying to map your terms into. Once you have decided on this you need to figure out how fine-grained the concepts should be. WordNet, as it has been suggested in other responses, will give you synsets, i.e. sets of terms which are more or l... | 1 | 2010-03-24T17:10:27Z | [
"python",
"django",
"dictionary",
"nlp"
] |
Globally accessible object across all Celery workers / memory cache in Django | 2,500,799 | <p>I have pretty standard Django+Rabbitmq+Celery setup with 1 Celery task and 5 workers.</p>
<p>Task uploads <b>the same</b> (I simplify a bit) big file (~100MB) asynchronously to a number of remote PCs.</p>
<p>All is working fine at the expense of using lots of memory, since every task/worker load that big file into... | 8 | 2010-03-23T14:47:05Z | 2,500,858 | <p>It seems to me that what you need is memcached backed for django. That way each task in Celery will have access to it.</p>
| 1 | 2010-03-23T14:53:59Z | [
"python",
"django",
"caching",
"global-variables",
"celery"
] |
Globally accessible object across all Celery workers / memory cache in Django | 2,500,799 | <p>I have pretty standard Django+Rabbitmq+Celery setup with 1 Celery task and 5 workers.</p>
<p>Task uploads <b>the same</b> (I simplify a bit) big file (~100MB) asynchronously to a number of remote PCs.</p>
<p>All is working fine at the expense of using lots of memory, since every task/worker load that big file into... | 8 | 2010-03-23T14:47:05Z | 4,036,004 | <p>Maybe you can use threads instead of processes for this particular task. Since threads all share the same memory, you only need one copy of the data in memory, but you still get parallel execution.
( this means not using Celery for this task )</p>
| 0 | 2010-10-27T17:37:25Z | [
"python",
"django",
"caching",
"global-variables",
"celery"
] |
Globally accessible object across all Celery workers / memory cache in Django | 2,500,799 | <p>I have pretty standard Django+Rabbitmq+Celery setup with 1 Celery task and 5 workers.</p>
<p>Task uploads <b>the same</b> (I simplify a bit) big file (~100MB) asynchronously to a number of remote PCs.</p>
<p>All is working fine at the expense of using lots of memory, since every task/worker load that big file into... | 8 | 2010-03-23T14:47:05Z | 4,283,877 | <p>Why not simply stream the upload(s) from disk instead of loading the whole file in memory ?</p>
| 2 | 2010-11-26T09:08:37Z | [
"python",
"django",
"caching",
"global-variables",
"celery"
] |
How to step through debug twisted? | 2,501,136 | <p>I'd like to be able to debug Punjab, a twisted python application, in Netbeans so that I can step through the code. How can I do that? Alternatively, how could I do it in a different debugger?</p>
| 4 | 2010-03-23T15:26:12Z | 2,501,863 | <p>Since you're trying to debug a twisted application, you have a few options:</p>
<ol>
<li><p>If you're running via twistd you can use the -b command-line options:</p>
<pre><code> -b, --debug run the application in the Python Debugger (implies
nodaemon), sending SIGUSR2 will dr... | 9 | 2010-03-23T16:49:34Z | [
"python",
"netbeans",
"debugging",
"twisted"
] |
'module' object has no attribute 'pcapObject' | 2,501,138 | <p>I have the following sample code which doesn't seem to want to run.</p>
<pre><code>import pcap
pc = pcap.pcapObject()
dev = sys.argv[1]
pc.open_live(dev, 1600, 0, 100)
pc.setfilter("udp port 53", 0, 0)
while 1:
pc.dispatch(1, p.pcap_dispatch)
</code></pre>
<p>I'm really not sure why. I'm using <a href="http:/... | 1 | 2010-03-23T15:26:22Z | 2,501,187 | <p>At least according to documentation from the project this line:</p>
<pre><code>pc = pcap.pcapObject()
</code></pre>
<p>Should really be:</p>
<pre><code>pc = pcap.pcap()
</code></pre>
| 2 | 2010-03-23T15:31:59Z | [
"python",
"packet",
"packet-capture",
"pcap"
] |
'module' object has no attribute 'pcapObject' | 2,501,138 | <p>I have the following sample code which doesn't seem to want to run.</p>
<pre><code>import pcap
pc = pcap.pcapObject()
dev = sys.argv[1]
pc.open_live(dev, 1600, 0, 100)
pc.setfilter("udp port 53", 0, 0)
while 1:
pc.dispatch(1, p.pcap_dispatch)
</code></pre>
<p>I'm really not sure why. I'm using <a href="http:/... | 1 | 2010-03-23T15:26:22Z | 2,501,206 | <p>I dont have python on this Computer, but when i look at the example, it should be</p>
<p>pc = pcap.pcap ()</p>
| 0 | 2010-03-23T15:34:02Z | [
"python",
"packet",
"packet-capture",
"pcap"
] |
Programmatically specifying Django model attributes | 2,501,173 | <p>I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a <code>Car</code> model class and want to add one <code>price</code> attribute ... | 5 | 2010-03-23T15:30:39Z | 2,501,247 | <blockquote>
<p>"I would like to add attributes to a Django models programmatically. At class creation time"</p>
</blockquote>
<p>Don't. "Programmatically" adding columns is silly and confusing. It seems fine to you -- the developer -- who deeply gets the nuances of Django.</p>
<p>For us, the maintainers, that co... | 3 | 2010-03-23T15:38:23Z | [
"python",
"django",
"django-models"
] |
Programmatically specifying Django model attributes | 2,501,173 | <p>I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a <code>Car</code> model class and want to add one <code>price</code> attribute ... | 5 | 2010-03-23T15:30:39Z | 2,501,254 | <p>You cannot do this at run time. It would change the database model and the database is changed via the command <code>syncdb</code> and somehow this feels really ugly.</p>
<p>Why not create a second model <code>Price</code> that holds the price for different currencies. Or if possible convert the price on the fly to... | 0 | 2010-03-23T15:39:04Z | [
"python",
"django",
"django-models"
] |
Programmatically specifying Django model attributes | 2,501,173 | <p>I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a <code>Car</code> model class and want to add one <code>price</code> attribute ... | 5 | 2010-03-23T15:30:39Z | 2,501,279 | <p>My solution is something which is bad from various reasons, but it works:</p>
<pre><code>from django.db import models
currencies = ["EUR", "USD"]
class Car(models.Model):
name = models.CharField(max_length=50)
for currency in currencies:
locals()['price_%s' % currency.lower()] = models.IntegerFi... | 3 | 2010-03-23T15:40:33Z | [
"python",
"django",
"django-models"
] |
Programmatically specifying Django model attributes | 2,501,173 | <p>I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a <code>Car</code> model class and want to add one <code>price</code> attribute ... | 5 | 2010-03-23T15:30:39Z | 2,501,419 | <p>The still not nice, but nicer than using <code>locals</code> solution is to use <code>Field.contribute_to_class</code>:</p>
<pre><code>for currency in currencies:
models.IntegerField().contribute_to_class(Car, 'price_%s' % currency.lower())
</code></pre>
<p><a href="http://code.google.com/p/django-mptt/source/... | 4 | 2010-03-23T15:54:33Z | [
"python",
"django",
"django-models"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,501,242 | <p>You can just import the file into the python interpreter. This will load the class in, and allow you to run the code.</p>
<p>For instance, create a file named "bgcolors.py" and copy and paste your code inside. Then using the python interpreter, you just type "import bgcolors" and you should be able to run it.</p>
... | 5 | 2010-03-23T15:38:10Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,501,343 | <p>You can use <a href="http://ipython.scipy.org/moin/">IPython</a> which is much better python repl. It has command for getting input from <a href="http://ipython.scipy.org/doc/rel-0.9.1/html/interactive/tutorial.html#source-code-handling-tips">external editor</a> by using %edit command. </p>
| 5 | 2010-03-23T15:48:44Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,501,350 | <p>The <a href="http://docs.python.org/library/idle.html" rel="nofollow">IDLE</a> interface does go to effort to preserve the proper indentation of pasted text. </p>
| 2 | 2010-03-23T15:49:07Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,501,465 | <p><a href="http://dreampie.sourceforge.net/" rel="nofollow">Dreampie</a> allows you to copy and paste code with proper indentation.</p>
| 3 | 2010-03-23T15:59:22Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,501,595 | <p>You can call execfile(filename). More or less the same as importing a module, except that it skips the module administration part and doesn't require you to add a folder to sys.path.</p>
<p>EDIT: To address the original question: copy-pasted code can be executed by calling exec(codestring).</p>
| 6 | 2010-03-23T16:13:14Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 2,503,794 | <p>You can usually easily and safely do copy-pasting with <a href="http://ipython.scipy.org/moin/">IPython</a>, through the commands <code>%cpaste</code> and <code>%paste</code>. This is very handy for testing code that you copy from web pages, for instance, or from your editor. IPython also has a <code>%run</code> c... | 21 | 2010-03-23T21:33:45Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 29,269,152 | <p>I had this problem recently and ultimately just needed to change my editor's indentation setting from tabs to spaces. (I was running the interpreter using the OSX Terminal.) Once I did this, copy & paste worked fine.</p>
| 0 | 2015-03-26T00:39:48Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 37,987,332 | <p>You can simply convert all tabs to spaces and remove <strong>ALL</strong> empty lines.
So you will be able to paste any code to python console (e.g.: python2.6)</p>
| 1 | 2016-06-23T09:19:53Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 39,394,562 | <p>There is an inbuilt method call "indent region & dedent region" and you can just use it. After you paste a lot of code at once you can select them all and adjust the whitespace.</p>
| 1 | 2016-09-08T15:12:18Z | [
"python"
] |
Copying and pasting code into the Python interpreter | 2,501,208 | <p>There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a fi... | 21 | 2010-03-23T15:34:15Z | 39,396,273 | <p>My answer is specifically about copy-pasting into the standard python shell (only tested on linux).</p>
<p>Depending on where the code comes from and how it is originally formatted <strong>the whitespace</strong> may or may not matter. In particular about your example snippet - copy-pasted from SO's code-formatted ... | 0 | 2016-09-08T16:41:54Z | [
"python"
] |
String comparison in Numpy | 2,501,362 | <p>In the following example</p>
<pre><code>In [8]: import numpy as np
In [9]: strings = np.array(['hello ', 'world '], dtype='|S10')
In [10]: strings == 'hello'
Out[10]: array([False, False], dtype=bool)
</code></pre>
<p>The comparison fails because of the whitespace. Is there a Numpy built-in function that d... | 3 | 2010-03-23T15:50:20Z | 2,501,540 | <p>Numpy provides vectorised string operations for arrays similar to Python's string methods. They are in the numpy.char module.</p>
<p><a href="http://docs.scipy.org/doc/numpy/reference/routines.char.html">http://docs.scipy.org/doc/numpy/reference/routines.char.html</a></p>
<pre><code>import numpy as np
strings = n... | 9 | 2010-03-23T16:07:48Z | [
"python",
"numpy"
] |
Google App Engine Datastore Faceted Search | 2,501,431 | <p>Has any one implemented Faceted Search using Google App Engine Datastore?</p>
| 7 | 2010-03-23T15:56:13Z | 4,813,222 | <p>the <a href="http://code.google.com/p/bigtablesearch/" rel="nofollow">bigtablesearch</a> project claims to support faceted search.</p>
<p>there are a number of other full text search projects for the app engine datastore, including
<a href="http://gae-full-text-search.appspot.com/" rel="nofollow">gae-search</a>,
<a... | 0 | 2011-01-27T06:01:17Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Google App Engine Datastore Faceted Search | 2,501,431 | <p>Has any one implemented Faceted Search using Google App Engine Datastore?</p>
| 7 | 2010-03-23T15:56:13Z | 28,278,084 | <p>A built-in faceted search is now being alpha-tested on GAE, see <a href="https://code.google.com/p/googleappengine/issues/detail?id=6695" rel="nofollow">https://code.google.com/p/googleappengine/issues/detail?id=6695</a></p>
| 1 | 2015-02-02T12:45:26Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
What do I use for a max-heap implementation in Python? | 2,501,457 | <p>Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?</p>
| 65 | 2010-03-23T15:58:02Z | 2,501,527 | <p>The easiest way is to invert the value of the keys and use heapq. For example, turn 1000.0 into -1000.0 and 5.0 into -5.0.</p>
| 63 | 2010-03-23T16:05:39Z | [
"python",
"data-structures",
"heap",
"recursive-datastructures"
] |
What do I use for a max-heap implementation in Python? | 2,501,457 | <p>Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?</p>
| 65 | 2010-03-23T15:58:02Z | 2,501,572 | <p>If you are inserting keys that are comparable but not int-like, you could potentially override the comparison operators on them (i.e. <= become > and > becomes <=). Otherwise, you can override heapq._siftup in the heapq module (it's all just Python code, in the end).</p>
| 3 | 2010-03-23T16:11:19Z | [
"python",
"data-structures",
"heap",
"recursive-datastructures"
] |
What do I use for a max-heap implementation in Python? | 2,501,457 | <p>Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?</p>
| 65 | 2010-03-23T15:58:02Z | 23,636,408 | <p>You can use </p>
<pre><code>import heapq
listForTree = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
heapq.heapify(listForTree) # for a min heap
heapq._heapify_max(listForTree) # for a maxheap!!
</code></pre>
| 48 | 2014-05-13T16:10:52Z | [
"python",
"data-structures",
"heap",
"recursive-datastructures"
] |
What do I use for a max-heap implementation in Python? | 2,501,457 | <p>Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?</p>
| 65 | 2010-03-23T15:58:02Z | 37,765,107 | <p>I have created a heap wrapper that inverts the values to create a max-heap, as well as a wrapper class for a min-heap to make the library more OOP-like. <a href="https://gist.github.com/CrazyPython/1233be4bb096bdd9cd3223d372d2f3ec" rel="nofollow">Here</a> is the gist. There are three classes; Heap (abstract class), ... | -3 | 2016-06-11T14:56:09Z | [
"python",
"data-structures",
"heap",
"recursive-datastructures"
] |
What do I use for a max-heap implementation in Python? | 2,501,457 | <p>Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?</p>
| 65 | 2010-03-23T15:58:02Z | 38,732,629 | <p>I implemented a max heap version of heapq and submitted it to PyPI. (Very slight change of heapq module CPython code.)</p>
<p><a href="https://pypi.python.org/pypi/heapq_max/" rel="nofollow">https://pypi.python.org/pypi/heapq_max/</a></p>
<p><a href="https://github.com/he-zhe/heapq_max" rel="nofollow">https://git... | -1 | 2016-08-03T00:44:40Z | [
"python",
"data-structures",
"heap",
"recursive-datastructures"
] |
What can be done in Cpython that can not be done in IronPython? | 2,501,492 | <p>What can be done in Cpython that can not be done in IronPython?</p>
| 5 | 2010-03-23T16:02:01Z | 2,501,635 | <p>If you are writing "100% pure Python", you can do everything that CPython can do in IronPython. The problem comes in when you want to use a third-party package. Many of them will have written their performance-intensive portions in C, and rely on the Python/C API (e.g. NumPy).</p>
<p>As a glue language for hookin... | 4 | 2010-03-23T16:17:09Z | [
"python",
"ironpython"
] |
add a decorate function to a class | 2,501,529 | <p>I have a decorated function (simplified version):</p>
<pre><code>class Memoize:
def __init__(self, function):
self.function = function
self.memoized = {}
def __call__(self, *args, **kwds):
hash = args
try:
return self.memoized[hash]
except KeyError:
... | 6 | 2010-03-23T16:05:54Z | 2,501,711 | <p>The problem is that you have defined your own callable class then tried to use it as a method. When you use a function as an attribute, accessing the function as an attribute calls it its <code>__get__</code> method to return something other than the function itselfâthe bound method. When you have your own class w... | 3 | 2010-03-23T16:26:42Z | [
"python",
"class",
"decorator",
"descriptor"
] |
Printing elements out of list | 2,501,675 | <p>I have a certain check to be done and if the check satisfies, I want the result to be printed. Below is the code:</p>
<pre><code>import string
import codecs
import sys
y=sys.argv[1]
list_1=[]
f=1.0
x=0.05
write_in = open ("new_file.txt", "w")
write_in_1 = open ("new_file_1.txt", "w")
ligand_file=open( y, "r" ) #Op... | 1 | 2010-03-23T16:20:40Z | 2,501,684 | <p>To convert a list of strings to a single string with spaces in between the lists's items, use <a href="http://docs.python.org/library/stdtypes.html#str.join"><code>' '.join(seq)</code></a>.</p>
<pre><code>>>> ' '.join(['1','2','3'])
'1 2 3'
</code></pre>
<p>You can replace <code>' '</code> with whatever s... | 9 | 2010-03-23T16:21:49Z | [
"python",
"list",
"printing"
] |
Printing elements out of list | 2,501,675 | <p>I have a certain check to be done and if the check satisfies, I want the result to be printed. Below is the code:</p>
<pre><code>import string
import codecs
import sys
y=sys.argv[1]
list_1=[]
f=1.0
x=0.05
write_in = open ("new_file.txt", "w")
write_in_1 = open ("new_file_1.txt", "w")
ligand_file=open( y, "r" ) #Op... | 1 | 2010-03-23T16:20:40Z | 2,502,022 | <p>Mark Rushakoff seems to have solved your immediate problem, but there are some other improvements that could be made to your code.</p>
<ul>
<li>Always use context managers (<code>with open(filename, mode) as f:</code>) for opening files rather than relying on <code>close</code> getting called manually.</li>
<li><p>... | 2 | 2010-03-23T17:12:38Z | [
"python",
"list",
"printing"
] |
Deleting python modules? | 2,501,746 | <p>Can you delete python modules? I've installed one that I would like to remove, and can't seem to figure out how.</p>
<p>Thanks</p>
| 9 | 2010-03-23T16:32:26Z | 2,501,798 | <p>This has already been asked <a href="http://stackoverflow.com/questions/1550226/python-setup-py-uninstall">here</a>.</p>
<p>Go into the "site-packages" directory of your python install and remove the files manually.</p>
| 3 | 2010-03-23T16:40:51Z | [
"python"
] |
Deleting python modules? | 2,501,746 | <p>Can you delete python modules? I've installed one that I would like to remove, and can't seem to figure out how.</p>
<p>Thanks</p>
| 9 | 2010-03-23T16:32:26Z | 2,501,894 | <p>To find where the module is, just do a:</p>
<pre><code> $ python
>> import module
>> print module.__file__
'/some/directory'
</code></pre>
<p>or if it is a package:</p>
<pre><code> >> import package
>> print package.__path__
</code></pre>
<p>and delete it.</p>
| 11 | 2010-03-23T16:54:38Z | [
"python"
] |
Deleting python modules? | 2,501,746 | <p>Can you delete python modules? I've installed one that I would like to remove, and can't seem to figure out how.</p>
<p>Thanks</p>
| 9 | 2010-03-23T16:32:26Z | 35,555,865 | <p>If you are using python under windows, the following command is what you need</p>
<pre><code>pip uninstall module
</code></pre>
<p>In some cases, you may have installed different versions of the module. For example, after I had the lxml3.4.4 installed via pip, I also installed lxml3.5.0 using its pre-built binary,... | 2 | 2016-02-22T14:14:05Z | [
"python"
] |
Reading UDP Packets | 2,501,882 | <p>I am having some trouble dissecting a UDP packet. I am receiving the packets and storing the data and sender-address in variables 'data' and 'addr' with: </p>
<p>data,addr = UDPSock.recvfrom(buf)</p>
<p>This parses the data as a string, that I am now unable to turn into bytes. I know the structure of the datagram ... | 3 | 2010-03-23T16:53:09Z | 2,502,055 | <p>An unsigned int32 is 4 bytes long, so you have to feed 4 bytes into <code>struct.unpack</code>.</p>
<p>Replace</p>
<pre><code>mybytes = data[16:19]
</code></pre>
<p>with</p>
<pre><code>mybytes = data[16:20]
</code></pre>
<p>(right number is the first byte not included, i.e. range(16,19) = [16,17,18]) and you sh... | 3 | 2010-03-23T17:16:09Z | [
"python",
"networking",
"udp"
] |
Trying to grab just absolute links from a webpage using BeautifulSoup | 2,502,120 | <p>I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <code><a href></code> that start with <code>http://</code>. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like.</p>
<pre><code>... | 4 | 2010-03-23T17:22:53Z | 2,502,134 | <p>Do you possibly have some <code><a></code> tags without <code>href</code> attributes? Internal link targets, perhaps?</p>
| 1 | 2010-03-23T17:25:14Z | [
"python",
"beautifulsoup"
] |
Trying to grab just absolute links from a webpage using BeautifulSoup | 2,502,120 | <p>I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <code><a href></code> that start with <code>http://</code>. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like.</p>
<pre><code>... | 4 | 2010-03-23T17:22:53Z | 2,502,180 | <p>Please give us an idea of what you're parsing here - as Andrew points out, it seems likely that there are some anchor tags without associated hrefs. </p>
<p>If you really want to ignore them, you could wrap it in a try block and afterwards catch with </p>
<p><code>except KeyError:
pass</code></p>
<p>But that... | 0 | 2010-03-23T17:32:14Z | [
"python",
"beautifulsoup"
] |
Trying to grab just absolute links from a webpage using BeautifulSoup | 2,502,120 | <p>I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <code><a href></code> that start with <code>http://</code>. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like.</p>
<pre><code>... | 4 | 2010-03-23T17:22:53Z | 2,502,223 | <pre><code>from BeautifulSoup import BeautifulSoup
import re
import urllib2
page = urllib2.urlopen("http://www.linkpages.com")
soup = BeautifulSoup(page)
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
print link
</code></pre>
| 6 | 2010-03-23T17:38:05Z | [
"python",
"beautifulsoup"
] |
Trying to grab just absolute links from a webpage using BeautifulSoup | 2,502,120 | <p>I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <code><a href></code> that start with <code>http://</code>. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like.</p>
<pre><code>... | 4 | 2010-03-23T17:22:53Z | 14,905,468 | <pre><code>f=open('Links.txt','w')
import urllib2
from bs4 import BeautifulSoup
url='http://www.redit.com'
page=urllib2.urlopen(url)
soup=BeautifulSoup(page)
atags=soup.find_all('a')
for item in atags:
for x in item.attrs:
if x=='href':
f.write(item.attrs[x]+',\n')
else:
con... | 0 | 2013-02-16T00:16:09Z | [
"python",
"beautifulsoup"
] |
Python 2.5 fails on a datetime.strptime format | 2,502,123 | <p>I have seen several questions with people asking about the same problem but none of the answers are helping me.</p>
<p>I'm receiving this error:</p>
<pre><code> pydev debugger: starting
Traceback (most recent call last):
>>>
File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <modu... | 0 | 2010-03-23T17:23:12Z | 2,502,132 | <p>you are using <code>%y</code> (which matches a 2 digit year).<br>
try with <code>%Y</code>, which matches a 4 digit year (like your 2010)</p>
| 3 | 2010-03-23T17:24:58Z | [
"python",
"strptime"
] |
Python 2.5 fails on a datetime.strptime format | 2,502,123 | <p>I have seen several questions with people asking about the same problem but none of the answers are helping me.</p>
<p>I'm receiving this error:</p>
<pre><code> pydev debugger: starting
Traceback (most recent call last):
>>>
File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <modu... | 0 | 2010-03-23T17:23:12Z | 2,502,142 | <p>Try using the a capital Y - '%Y' to match a 4-digit year.</p>
| 1 | 2010-03-23T17:26:34Z | [
"python",
"strptime"
] |
Reducing size of a character array in Numpy | 2,502,235 | <p>Given a character array:</p>
<pre><code>In [21]: x = np.array(['a ','bb ','cccc '])
</code></pre>
<p>One can remove the whitespace using:</p>
<pre><code>In [22]: np.char.strip(x)
Out[22]:
array(['a', 'bb', 'cccc'],
dtype='|S8')
</code></pre>
<p>but is there a way to also shrink the width of the ... | 0 | 2010-03-23T17:39:52Z | 2,502,893 | <p>Do you just want to change the data type?</p>
<pre><code>import numpy as NP
a = NP.array(["a", "bb", "ccc"])
a
# returns array(['a', 'bb', 'ccc'], dtype='|S3')
a = NP.array(a, dtype="|S8") # change dtype
# returns array(['a', 'bb', 'ccc'], dtype='|S8')
a = NP.array(a, dtype="|S3") # change it back
# returns a... | 1 | 2010-03-23T19:15:29Z | [
"python",
"numpy"
] |
Reducing size of a character array in Numpy | 2,502,235 | <p>Given a character array:</p>
<pre><code>In [21]: x = np.array(['a ','bb ','cccc '])
</code></pre>
<p>One can remove the whitespace using:</p>
<pre><code>In [22]: np.char.strip(x)
Out[22]:
array(['a', 'bb', 'cccc'],
dtype='|S8')
</code></pre>
<p>but is there a way to also shrink the width of the ... | 0 | 2010-03-23T17:39:52Z | 2,503,201 | <pre><code>>>> x = np.array(['a ','bb ','cccc '])
>>> x = np.array([s.strip() for s in x])
>>> x
array(['a', 'bb', 'cccc'],
dtype='|S4')
</code></pre>
| 0 | 2010-03-23T20:05:09Z | [
"python",
"numpy"
] |
missing elements from pcap? | 2,502,243 | <p>When I check the attributes available to the module pcap, I expect to see something like</p>
<blockquote>
<p>[ ...snip...</p>
<p>'dltvalue', 'findalldevs',
'lookupdev', 'lookupnet', 'ntoa',
'pcapObject', 'pcapObjectPtr']</p>
</blockquote>
<p>With note on pcapObject. However, all I get when running <cod... | 1 | 2010-03-23T17:40:37Z | 5,427,944 | <p>You want <a href="http://pylibpcap.sourceforge.net/" rel="nofollow">pylibpcap</a> but what you have installed is <a href="http://code.google.com/p/pypcap/" rel="nofollow">pypcap</a>, a different Python libpcap binding with an incompatible API.</p>
<p>There are three Python libpcap bindings used in the wild: pypcap ... | 1 | 2011-03-25T02:33:23Z | [
"python",
"packet-capture",
"pcap"
] |
missing elements from pcap? | 2,502,243 | <p>When I check the attributes available to the module pcap, I expect to see something like</p>
<blockquote>
<p>[ ...snip...</p>
<p>'dltvalue', 'findalldevs',
'lookupdev', 'lookupnet', 'ntoa',
'pcapObject', 'pcapObjectPtr']</p>
</blockquote>
<p>With note on pcapObject. However, all I get when running <cod... | 1 | 2010-03-23T17:40:37Z | 9,111,171 | <p>You could also try </p>
<p>sudo apt-get install libpcap-dev</p>
| 0 | 2012-02-02T11:00:48Z | [
"python",
"packet-capture",
"pcap"
] |
Profiling shared library/plugins written in C++ for Python? | 2,502,262 | <p>I've got a C++ library that lets me write plugins in C++ and then automatically exposes them
to python. I'm working on some networking stuff in a plugin and I'd like to profile it with something like gprof, but simply compiling with -pg and running the plugin via python doesn't generated the necessary profiling dat... | 0 | 2010-03-23T17:42:31Z | 2,502,368 | <p>I've found valgrind's <a href="http://valgrind.org/docs/manual/cg-manual.html" rel="nofollow">cachegrind</a> with <a href="http://kcachegrind.sourceforge.net/html/Home.html" rel="nofollow">KCachegrind</a> to be helpful in analysis of un-prepared (e.g. no gprof code embedded) binaries.</p>
| 1 | 2010-03-23T17:59:55Z | [
"c++",
"python",
"profile"
] |
Put an AuiManager inside a AuiNotebook page | 2,502,270 | <p>Is it possible ho put an AuiManager inside an AuiNotebook page?</p>
<p>Have tested with a small sample code, but I only get a 'Segmentation fault'.</p>
<p>Is this possible to begin with? The reason why I want this is to split a notebook page in two parts and get the caption field and the maximize field in the top ... | 1 | 2010-03-23T17:43:19Z | 2,504,487 | <p>wxAUIManager only works as a child of a wxFrame.</p>
<p><a href="http://docs.wxwidgets.org/trunk/classwx_aui_manager.html" rel="nofollow">http://docs.wxwidgets.org/trunk/classwx_aui_manager.html</a></p>
| 1 | 2010-03-23T23:56:31Z | [
"python",
"wxpython",
"wxwidgets"
] |
Is it possible to see the source code of the violating files in Hudson with Violations and Pylint? | 2,502,345 | <p>I'm using Hudson CI with a Python project. I've installed the Violations plugin and configured it to run the code against pylint. This works, but I only see a list of violations without linking to the source code. Is it possible to setup Violations and pylint to load and highlight the violating source files (somethi... | 3 | 2010-03-23T17:56:10Z | 2,502,582 | <p>Well, after some more debugging, I realized that the pylint output file referenced the source code files relative to where pylint was being run, which wasn't the same path that Hudson needed. Basically, Violations needed the paths relative to the Hudson workspace.</p>
| 2 | 2010-03-23T18:27:39Z | [
"python",
"hudson"
] |
Is it possible to see the source code of the violating files in Hudson with Violations and Pylint? | 2,502,345 | <p>I'm using Hudson CI with a Python project. I've installed the Violations plugin and configured it to run the code against pylint. This works, but I only see a list of violations without linking to the source code. Is it possible to setup Violations and pylint to load and highlight the violating source files (somethi... | 3 | 2010-03-23T17:56:10Z | 3,967,746 | <blockquote>
<p>Better yet, can Violations integrate with pep8.py?</p>
</blockquote>
<p>This should probably be a separate question but I'll answer it anyway: I adapted the <code>pylint</code> parser into a <code>pep8</code> parser for Hudson's Violations plugin. See this ticket for the patch:</p>
<p><a href="http:... | 0 | 2010-10-19T11:16:59Z | [
"python",
"hudson"
] |
Is it possible to see the source code of the violating files in Hudson with Violations and Pylint? | 2,502,345 | <p>I'm using Hudson CI with a Python project. I've installed the Violations plugin and configured it to run the code against pylint. This works, but I only see a list of violations without linking to the source code. Is it possible to setup Violations and pylint to load and highlight the violating source files (somethi... | 3 | 2010-03-23T17:56:10Z | 4,490,328 | <p>I ran into a similar problem with pylint and violations. For me, the problem was that pylint writes absolute file names to the results file, while the violations plugin expects paths relative to the workspace directory. Running this sed one-liner on the pylint output file fixed my problem:</p>
<p><code>sed -i s#.*w... | 1 | 2010-12-20T14:01:23Z | [
"python",
"hudson"
] |
Implementing pyglet breaks my once working framebuffer OpenGL code | 2,502,362 | <p>This question repeats my earlier one but my earlier one was a failure because I didn't copy some vital information correctly, so I have to redo it.</p>
<p>I'm getting an error with a call to an OpenGL function. Maybe pyglet isn't initialising OpenGL correctly? The error happens with a simple function that worked be... | -5 | 2010-03-23T17:58:38Z | 2,502,616 | <p>glBindFramebufferEXT expects pointer to a buffer. AFAIK, you have to use <a href="http://www.pyglet.org/doc/programming_guide/using_opengl.html" rel="nofollow">ctypes</a> in this case.</p>
<pre><code>from pyglet.gl import *
from ctypes import c_uint, byref
fb = c_uint()
glGenFramebuffersEXT(1, byref(fb))
glBindFra... | 1 | 2010-03-23T18:35:24Z | [
"python",
"opengl",
"framebuffer",
"pyglet",
"pyopengl"
] |
Display an image as a splash screen when running Windows batch file, vbscript/wscript or Python console script | 2,502,385 | <p>Any ideas how I can display an image file (bmp or png) centered on the screen as an application splash screen when running a Windows console script based on a batch file, vbscript/wscript or Python console script?</p>
<p>I'm not interested in a wxPython solution - that's too much overhead just to implement a cosmet... | 3 | 2010-03-23T18:02:05Z | 2,502,419 | <p>You can surely cook it up using the Win32 API and the <code>win32api</code> Python module.</p>
<p>How about <a href="http://code.activestate.com/recipes/120687-low-resource-win32-splashscreen/" rel="nofollow">this recipe</a>? Alternatively, <a href="http://www.codeguru.com/cpp/w-d/dislog/splashscreens/article.php/c... | 0 | 2010-03-23T18:07:37Z | [
"python",
"image",
"vbscript",
"batch-file",
"console-application"
] |
Display an image as a splash screen when running Windows batch file, vbscript/wscript or Python console script | 2,502,385 | <p>Any ideas how I can display an image file (bmp or png) centered on the screen as an application splash screen when running a Windows console script based on a batch file, vbscript/wscript or Python console script?</p>
<p>I'm not interested in a wxPython solution - that's too much overhead just to implement a cosmet... | 3 | 2010-03-23T18:02:05Z | 2,502,528 | <p>A low-tech, ugly approach? How about opening an image viewer with the bitmap and killing it after some time or when the initializations are done? ;-)</p>
<p>You certainly have no native way of doing this in a batch file. From VBScript you could use an <a href="http://en.wikipedia.org/wiki/HTML_Application" rel="nof... | 1 | 2010-03-23T18:19:44Z | [
"python",
"image",
"vbscript",
"batch-file",
"console-application"
] |
Display an image as a splash screen when running Windows batch file, vbscript/wscript or Python console script | 2,502,385 | <p>Any ideas how I can display an image file (bmp or png) centered on the screen as an application splash screen when running a Windows console script based on a batch file, vbscript/wscript or Python console script?</p>
<p>I'm not interested in a wxPython solution - that's too much overhead just to implement a cosmet... | 3 | 2010-03-23T18:02:05Z | 2,502,963 | <p>Try TK, it is included with python. Also, PyGtk is lighter than wxPython, but I ended up bitting the bullet and using wxPython for the same purpose recently, it is heavy, but it didn't have any affect on the script performance.</p>
| 0 | 2010-03-23T19:27:05Z | [
"python",
"image",
"vbscript",
"batch-file",
"console-application"
] |
Display an image as a splash screen when running Windows batch file, vbscript/wscript or Python console script | 2,502,385 | <p>Any ideas how I can display an image file (bmp or png) centered on the screen as an application splash screen when running a Windows console script based on a batch file, vbscript/wscript or Python console script?</p>
<p>I'm not interested in a wxPython solution - that's too much overhead just to implement a cosmet... | 3 | 2010-03-23T18:02:05Z | 7,102,018 | <p>I'll add a late reply to the mix. I think this is an interesting option worth looking at:</p>
<p><a href="http://www.quicksplash.net" rel="nofollow">http://www.quicksplash.net</a></p>
| 0 | 2011-08-18T03:22:56Z | [
"python",
"image",
"vbscript",
"batch-file",
"console-application"
] |
Python: HTTP Post a large file with streaming | 2,502,596 | <p>I'm uploading potentially large files to a web server. Currently I'm doing this:</p>
<pre><code>import urllib2
f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)
</code></pre>
<p>However, this reads t... | 13 | 2010-03-23T18:31:57Z | 2,502,655 | <p>Have you tried with <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a>?</p>
<pre><code>from mechanize import Browser
br = Browser()
br.open(url)
br.form.add_file(open('largefile.zip'), 'application/zip', 'largefile.zip')
br.submit()
</code></pre>
<p>or, if you don't want to use mult... | 3 | 2010-03-23T18:40:20Z | [
"python",
"http",
"urllib2"
] |
Python: HTTP Post a large file with streaming | 2,502,596 | <p>I'm uploading potentially large files to a web server. Currently I'm doing this:</p>
<pre><code>import urllib2
f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)
</code></pre>
<p>However, this reads t... | 13 | 2010-03-23T18:31:57Z | 2,502,998 | <p>Try pycurl. I don't have anything setup will accept a large file that <em>isn't</em> in a multipart/form-data POST, but here's a simple example that reads the file as needed.</p>
<pre><code>import os
import pycurl
class FileReader:
def __init__(self, fp):
self.fp = fp
def read_callback(self, size):... | 1 | 2010-03-23T19:33:20Z | [
"python",
"http",
"urllib2"
] |
Python: HTTP Post a large file with streaming | 2,502,596 | <p>I'm uploading potentially large files to a web server. Currently I'm doing this:</p>
<pre><code>import urllib2
f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)
</code></pre>
<p>However, this reads t... | 13 | 2010-03-23T18:31:57Z | 2,504,133 | <p>Reading through the mailing list thread linked to by systempuntoout, I found a clue towards the solution.</p>
<p>The <code>mmap</code> module allows you to open file that acts like a string. Parts of the file are loaded into memory on demand.</p>
<p>Here's the code I'm using now:</p>
<pre><code>import urllib2
imp... | 22 | 2010-03-23T22:40:46Z | [
"python",
"http",
"urllib2"
] |
Python: HTTP Post a large file with streaming | 2,502,596 | <p>I'm uploading potentially large files to a web server. Currently I'm doing this:</p>
<pre><code>import urllib2
f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)
</code></pre>
<p>However, this reads t... | 13 | 2010-03-23T18:31:57Z | 30,810,626 | <p>The documentation doesn't say you can do this, but the code in urllib2 (and httplib) accepts any object with a read() method as data. So using an open file seems to do the trick.</p>
<p>You'll need to set the Content-Length header yourself. If it's not set, urllib2 will call len() on the data, which file objects ... | 3 | 2015-06-12T19:16:16Z | [
"python",
"http",
"urllib2"
] |
Python: HTTP Post a large file with streaming | 2,502,596 | <p>I'm uploading potentially large files to a web server. Currently I'm doing this:</p>
<pre><code>import urllib2
f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)
</code></pre>
<p>However, this reads t... | 13 | 2010-03-23T18:31:57Z | 38,111,430 | <p>Using the <code>requests</code> library you can do</p>
<pre><code>with open('massive-body', 'rb') as f:
requests.post('http://some.url/streamed', data=f)
</code></pre>
<p>as mentioned <a href="http://docs.python-requests.org/en/latest/user/advanced/#streaming-uploads" rel="nofollow">here in their docs</a></p>
| 0 | 2016-06-29T23:01:36Z | [
"python",
"http",
"urllib2"
] |
Update element values using xml.dom.minidom | 2,502,758 | <p>I have an XML structure which looks similar to:</p>
<pre><code><Store>
<foo>
<book>
<isbn>123456</isbn>
</book>
<title>XYZ</title>
<checkout>no</checkout>
</foo>
<bar>
<book>
<isb... | 3 | 2010-03-23T18:55:00Z | 2,504,204 | <p>I'm not entirely sure what you mean by "checkout". This script will find the element and alter the value of that element. Perhaps you can adapt it to your specific needs.</p>
<pre><code>import xml.dom.minidom as DOM
# find the author as a child of the "Store"
def getAuthor(parent, author):
# by looking at the ... | 5 | 2010-03-23T22:53:32Z | [
"python",
"xml",
"minidom"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 2,502,872 | <p>This worked for me for redirecting stdout (stderr can be handled similarly):</p>
<pre><code>from subprocess import Popen, PIPE
pipe = Popen(path, stdout=PIPE)
text = pipe.communicate()[0]
</code></pre>
<p>If it doesn't work for you, please specify exactly the problem you're having.</p>
| 25 | 2010-03-23T19:12:58Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 2,502,881 | <p>Assuming that <code>pwd</code> is just an example, this is how you can do it:</p>
<pre><code>import subprocess
p = subprocess.Popen("pwd", stdout=subprocess.PIPE)
result = p.communicate()[0]
print result
</code></pre>
<p>See the <a href="http://docs.python.org/library/subprocess.html">subprocess documentation</a>... | 17 | 2010-03-23T19:14:00Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 2,502,883 | <p><strong>In Python 2.7 or Python 3</strong></p>
<p>Instead of making a <code>Popen</code> object directly, you can use the <a href="http://docs.python.org/2/library/subprocess.html#subprocess.check_output"><code>subprocess.check_output()</code> function</a> to store output of a command in a string:</p>
<pre><code>f... | 265 | 2010-03-23T19:14:14Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 2,502,887 | <pre><code> import os
list = os.popen('pwd').read()
</code></pre>
<p>In this case you will only have one element in the list.</p>
| 3 | 2010-03-23T19:14:41Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 16,266,707 | <p>subprocess.Popen: <a href="http://docs.python.org/2/library/subprocess.html#subprocess.Popen">http://docs.python.org/2/library/subprocess.html#subprocess.Popen</a></p>
<pre><code>import subprocess
command = "ntpq -p" # the shell command
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shel... | 10 | 2013-04-28T19:14:19Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 16,449,718 | <p>I wrote a little function based on the other answers here:</p>
<pre><code>def pexec(*args):
return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0].rstrip()
</code></pre>
<p>Usage:</p>
<pre><code>changeset = pexec('hg','id','--id')
branch = pexec('hg','id','--branch')
revnum = pexec('hg','id','... | 2 | 2013-05-08T20:34:08Z | [
"python",
"subprocess"
] |
Store output of subprocess.Popen call in a string | 2,502,833 | <p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p>
<pre><code>#!/usr/bin/python
import subprocess
p2 = subprocess.Popen("ntpq -p")
</code></pre>
<p>I've tried a few things including some of the suggestions here:</p>
<p><a href="http://stack... | 155 | 2010-03-23T19:05:01Z | 24,171,719 | <p>This works perfectly for me:</p>
<pre><code>import subprocess
try:
#prints results and merges stdout and std
result = subprocess.check_output("echo %USERNAME%", stderr=subprocess.STDOUT, shell=True)
print result
#causes error and merges stdout and stderr
result = subprocess.check_output("copy te... | 6 | 2014-06-11T20:10:51Z | [
"python",
"subprocess"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.