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
Use distribute/setuptools to create symlink (or run script)?
2,159,211
<p>As part of my project's setup process, I need to symlink one of the packages to a specified directory so an init.d script can find it. Is there any way to add this as a post-processing command to <code>setup()</code>? I would even settle for creating another file that creates the link and pass it to <code>setup()</c...
9
2010-01-29T00:57:31Z
26,490,820
<p>I know this post is several years old but I wanted to provide an update that post-processing code is possible in setup.py. Long story short, you have to override the install function of setuptools but from then on you can add whatever code you want, such as copying symlinks that MANIFEST.in refuses to copy. Taken fr...
2
2014-10-21T15:45:38Z
[ "python", "symlink", "setuptools", "distribute" ]
Strange Python set and hash behaviour - how does this work?
2,159,232
<p>I have a class called <code>GraphEdge</code> which I would like to be uniquely defined within a set (the built-in <code>set</code> type) by its <code>tail</code> and <code>head</code> members, which are set via <code>__init__</code>.</p> <p>If I do not define <code>__hash__</code>, I see the following behaviour:</p...
4
2010-01-29T01:02:43Z
2,159,241
<p>You have a hash collision. On hash collision, the set uses the == operator to check on whether or not they are truly equal to each other.</p>
13
2010-01-29T01:06:43Z
[ "python", "hash", "set" ]
Strange Python set and hash behaviour - how does this work?
2,159,232
<p>I have a class called <code>GraphEdge</code> which I would like to be uniquely defined within a set (the built-in <code>set</code> type) by its <code>tail</code> and <code>head</code> members, which are set via <code>__init__</code>.</p> <p>If I do not define <code>__hash__</code>, I see the following behaviour:</p...
4
2010-01-29T01:02:43Z
2,159,257
<p>It's important to understand how hash and == work together, because both are used by sets. For two values x and y, the important rule is that:</p> <pre><code>x == y ==&gt; hash(x) == hash(y) </code></pre> <p>(x equals y implies that x and y's hashes are equal). But, the inverse is not true: two unequal values ca...
7
2010-01-29T01:12:05Z
[ "python", "hash", "set" ]
Strange Python set and hash behaviour - how does this work?
2,159,232
<p>I have a class called <code>GraphEdge</code> which I would like to be uniquely defined within a set (the built-in <code>set</code> type) by its <code>tail</code> and <code>head</code> members, which are set via <code>__init__</code>.</p> <p>If I do not define <code>__hash__</code>, I see the following behaviour:</p...
4
2010-01-29T01:02:43Z
2,159,259
<p>You should always define both <code>__eq__()</code> and <code>__hash__()</code> if you need at least one of them. If the hashes of two objects are equal, an extra <code>__eq__()</code> check is done to verify uniqueness.</p>
6
2010-01-29T01:12:34Z
[ "python", "hash", "set" ]
javax.script.ScriptEngine fails at runtime
2,159,273
<p>Any ideas? public class Main {</p> <pre><code>public static void main(String[] args) throws ScriptException { ScriptEngine engine = new ScriptEngineManager().getEngineByName("python"); engine.put("hello_str", ""); engine.eval("for i in range(10):"); engine.eval(" hello_str += str(i)"); Object ...
2
2010-01-29T01:15:04Z
2,159,299
<p>Looks like you are trying to evaluate an incomplete statement in the lines:</p> <pre><code>engine.eval("for i in range(10):"); engine.eval(" hello_str += str(i)"); </code></pre> <p>Here, I assume <code>eval()</code> is trying to evaluate these one-by-one, and finding nothing after the <code>for</code> is errorin...
2
2010-01-29T01:24:21Z
[ "java", "python", "scriptengine" ]
pygame audio playback speed
2,159,365
<p>quick question. </p> <p>I'm running pygame under linux just to play some audio files. I've got some .wav files and I'm having problems playing them back at the right speed.</p> <pre><code>import pygame.mixer, sys, time #plays too fast pygame.mixer.init(44100) pygame.mixer.music.load(sys.argv[1]) pygame.mixer.musi...
1
2010-01-29T01:46:27Z
2,159,401
<p>Open your audio file in a free audio tool like <a href="http://audacity.sourceforge.net" rel="nofollow">Audacity</a>. It will tell you the sampling rate of your media. It will also allow you to convert to a different sampling rate so all your sounds can be the same.</p>
2
2010-01-29T01:55:18Z
[ "python", "pygame" ]
pygame audio playback speed
2,159,365
<p>quick question. </p> <p>I'm running pygame under linux just to play some audio files. I've got some .wav files and I'm having problems playing them back at the right speed.</p> <pre><code>import pygame.mixer, sys, time #plays too fast pygame.mixer.init(44100) pygame.mixer.music.load(sys.argv[1]) pygame.mixer.musi...
1
2010-01-29T01:46:27Z
2,164,987
<p>I figured it out... There is a wave module <a href="http://docs.python.org/library/wave.html" rel="nofollow">http://docs.python.org/library/wave.html</a> and it can read the sample rate for wav files.</p>
1
2010-01-29T20:37:11Z
[ "python", "pygame" ]
Running a PHP script inside a Python WSGI enviroment
2,159,637
<p>I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show.</p> <p>I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed.</p> <p>It's in the directory with the images u...
0
2010-01-29T03:06:40Z
2,159,645
<p>Maybe read this thread, and port your PHP script to Python:</p> <p><a href="http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion">http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion</a></p>
3
2010-01-29T03:08:54Z
[ "php", "python", "django", "apache", "wsgi" ]
Running a PHP script inside a Python WSGI enviroment
2,159,637
<p>I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show.</p> <p>I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed.</p> <p>It's in the directory with the images u...
0
2010-01-29T03:06:40Z
2,159,848
<p>If you have not configured Apache so that it knows that .php files under the '/media' directory should be processed by PHP somehow, they will not be. So, the mod_wsgi configuration is fine, the problem is likely your PHP configuration.</p> <p>How are you configuring PHP? Are you using mod_php, or PHP via fastcgi? H...
1
2010-01-29T04:17:40Z
[ "php", "python", "django", "apache", "wsgi" ]
Running a PHP script inside a Python WSGI enviroment
2,159,637
<p>I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show.</p> <p>I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed.</p> <p>It's in the directory with the images u...
0
2010-01-29T03:06:40Z
2,159,864
<p>The <code>WSGIScriptAlias</code> directive there swallows up URLs meant for <code>Alias</code>. Swap the order.</p>
1
2010-01-29T04:24:13Z
[ "php", "python", "django", "apache", "wsgi" ]
Running a PHP script inside a Python WSGI enviroment
2,159,637
<p>I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show.</p> <p>I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed.</p> <p>It's in the directory with the images u...
0
2010-01-29T03:06:40Z
2,256,467
<p>So it turns out the problem was two things, making it hard to find.</p> <p>Thanks Ignacio Vazquez-Abrams, I had my lines the wrong way around.</p> <p>Once that was solved, PHP would not serve my file because it was in a dir that was symlinked from outside the <code>allowed path(s)</code>. I resolved this by turnin...
1
2010-02-13T04:27:40Z
[ "php", "python", "django", "apache", "wsgi" ]
lxml has essentially nothing
2,159,690
<p>The <code>lxml</code> package for Python seems to absolutely broken on my system. I am not sure of the problem, as all of the files are in place, it seems. My suspicion is that the problem is in <code>__init__.py</code>, but I don't have enough practice with the system to make an accurate diagnosis or fix the proble...
1
2010-01-29T03:21:15Z
2,159,705
<p>I think all the lxml code is in subpackages. Try</p> <pre><code>from lxml import etree </code></pre>
1
2010-01-29T03:26:23Z
[ "python", "package", "lxml" ]
lxml has essentially nothing
2,159,690
<p>The <code>lxml</code> package for Python seems to absolutely broken on my system. I am not sure of the problem, as all of the files are in place, it seems. My suspicion is that the problem is in <code>__init__.py</code>, but I don't have enough practice with the system to make an accurate diagnosis or fix the proble...
1
2010-01-29T03:21:15Z
2,159,707
<p>It's perfectly normal for a <code>__init__.py</code> file to have nothing in it: <a href="http://docs.python.org/tutorial/modules.html#packages" rel="nofollow">http://docs.python.org/tutorial/modules.html#packages</a></p> <p>The file is just there to let Python know that it's a package and not just a directory with...
1
2010-01-29T03:26:43Z
[ "python", "package", "lxml" ]
lxml has essentially nothing
2,159,690
<p>The <code>lxml</code> package for Python seems to absolutely broken on my system. I am not sure of the problem, as all of the files are in place, it seems. My suspicion is that the problem is in <code>__init__.py</code>, but I don't have enough practice with the system to make an accurate diagnosis or fix the proble...
1
2010-01-29T03:21:15Z
2,159,710
<p>No, you're just doing it wrong! Try, e.g., <code>from lxml import etree</code>, and you should be able to use <code>etree</code> fully. <code>import lxml</code> -- importing the <strong>package</strong>! -- does <strong>not</strong> give you implicit access to any of the package's <strong>modules</strong>!-)</p>
10
2010-01-29T03:27:03Z
[ "python", "package", "lxml" ]
installing mechanize with easy_install
2,159,733
<p>I just got easy_install downloaded but i'm having problems installing mechanize, should I be addressing site-packages at any point. In the first try below, i got an error. in the second try below, i got command not found which is wierd since I know for sure that it downloaded.</p> <pre><code>names-computer:~ names$...
6
2010-01-29T03:36:06Z
2,159,775
<p><code>mechanize-0.1.9-py2.5.egg</code> is just a zipped file. Furthermore, you don't need to download the egg manually. <code>easy_install</code> will automatically pull down the code for you and install it.</p> <p>You can install easy_install with <a href="http://peak.telecommunity.com/dist/ez_setup.py" rel="nofol...
1
2010-01-29T03:48:34Z
[ "python", "mechanize", "easy-install" ]
installing mechanize with easy_install
2,159,733
<p>I just got easy_install downloaded but i'm having problems installing mechanize, should I be addressing site-packages at any point. In the first try below, i got an error. in the second try below, i got command not found which is wierd since I know for sure that it downloaded.</p> <pre><code>names-computer:~ names$...
6
2010-01-29T03:36:06Z
2,159,788
<p>On OS X, Python interpreter instances are typically installed as so-called Framework builds which means that there is a <code>bin</code> directory within the framework which is typically (but not always) the installation destination for python scripts, such as <code>easy_install</code>. If you are not using the App...
3
2010-01-29T03:56:51Z
[ "python", "mechanize", "easy-install" ]
installing mechanize with easy_install
2,159,733
<p>I just got easy_install downloaded but i'm having problems installing mechanize, should I be addressing site-packages at any point. In the first try below, i got an error. in the second try below, i got command not found which is wierd since I know for sure that it downloaded.</p> <pre><code>names-computer:~ names$...
6
2010-01-29T03:36:06Z
2,160,384
<p>You don't need to download mechanize to install it with easy_install. You just go:</p> <pre><code>/path/to/easy_install mechanize </code></pre> <p>Your problem is that you don't actually call easy_install. </p> <pre><code>bash: easy_install: command not found </code></pre> <p>That only works if easy_install is i...
2
2010-01-29T06:54:03Z
[ "python", "mechanize", "easy-install" ]
installing mechanize with easy_install
2,159,733
<p>I just got easy_install downloaded but i'm having problems installing mechanize, should I be addressing site-packages at any point. In the first try below, i got an error. in the second try below, i got command not found which is wierd since I know for sure that it downloaded.</p> <pre><code>names-computer:~ names$...
6
2010-01-29T03:36:06Z
9,389,250
<pre><code>apt-get install python-setuptools </code></pre> <p>This command will install <code>easy_install</code> on ubuntu.</p>
10
2012-02-22T04:50:36Z
[ "python", "mechanize", "easy-install" ]
Why Python on Windows can't read an image in binary mode?
2,159,794
<p>I want to read a image in binary mode so that I could save it into my database, like this:</p> <pre><code>img = open("Last_Dawn.jpg") t = img.read() save_to_db(t) </code></pre> <p>This is working on Mac. But on Windows, what img.read() is incorrect. It's just a little out of the whole set.</p> <p>So my first ques...
1
2010-01-29T03:58:26Z
2,159,802
<p>You need to open in binary mode:</p> <pre><code>img = open("Last_Dawn.jpg", 'rb') </code></pre>
6
2010-01-29T04:00:06Z
[ "python", "image", "binary" ]
Why Python on Windows can't read an image in binary mode?
2,159,794
<p>I want to read a image in binary mode so that I could save it into my database, like this:</p> <pre><code>img = open("Last_Dawn.jpg") t = img.read() save_to_db(t) </code></pre> <p>This is working on Mac. But on Windows, what img.read() is incorrect. It's just a little out of the whole set.</p> <p>So my first ques...
1
2010-01-29T03:58:26Z
2,159,805
<pre><code>open(filename, 'rb') </code></pre>
2
2010-01-29T04:00:07Z
[ "python", "image", "binary" ]
Why Python on Windows can't read an image in binary mode?
2,159,794
<p>I want to read a image in binary mode so that I could save it into my database, like this:</p> <pre><code>img = open("Last_Dawn.jpg") t = img.read() save_to_db(t) </code></pre> <p>This is working on Mac. But on Windows, what img.read() is incorrect. It's just a little out of the whole set.</p> <p>So my first ques...
1
2010-01-29T03:58:26Z
2,159,810
<p>You need to tell Python to open the file in binary mode:</p> <pre><code>img = open('whatever.whatever', 'rb') </code></pre> <p>See the documentation for the open function here: <a href="http://docs.python.org/library/functions.html#open" rel="nofollow">http://docs.python.org/library/functions.html#open</a></p>
4
2010-01-29T04:00:57Z
[ "python", "image", "binary" ]
Why Python on Windows can't read an image in binary mode?
2,159,794
<p>I want to read a image in binary mode so that I could save it into my database, like this:</p> <pre><code>img = open("Last_Dawn.jpg") t = img.read() save_to_db(t) </code></pre> <p>This is working on Mac. But on Windows, what img.read() is incorrect. It's just a little out of the whole set.</p> <p>So my first ques...
1
2010-01-29T03:58:26Z
2,159,811
<p>Can't say for sure but I do know that the ISO C standard doesn't distinguish between the binary and non-binary modes when calling <code>fopen</code> and yet Windows <em>does</em>.</p> <p>It's likely that the Python code just uses <code>fopen("Last_Dawn.jpg","r")</code> under the covers (since it's written in C) and...
2
2010-01-29T04:02:09Z
[ "python", "image", "binary" ]
Problem In Running easy_install.exe under Windows
2,159,809
<p>I am running Python under windows.</p> <p>I face no problem in installing pysqlite package.</p> <pre><code>C:\&gt;c:\Python26\Scripts\easy_install.exe pysqlite Searching for pysqlite Reading http://pypi.python.org/simple/pysqlite/ ........ Download error: [Errno 11001] getaddrinfo failed -- Some packages may not b...
1
2010-01-29T04:00:53Z
2,159,830
<p>The psycopg PyPi posting does not contain a pre-built w32 installer that easy_install can use nor could it find a way to build from source.</p> <p>Here are some <a href="http://stickpeople.com/projects/python/win-psycopg/" rel="nofollow">pre-built versions of the psycopg module</a>.</p>
0
2010-01-29T04:12:00Z
[ "python" ]
Problem In Running easy_install.exe under Windows
2,159,809
<p>I am running Python under windows.</p> <p>I face no problem in installing pysqlite package.</p> <pre><code>C:\&gt;c:\Python26\Scripts\easy_install.exe pysqlite Searching for pysqlite Reading http://pypi.python.org/simple/pysqlite/ ........ Download error: [Errno 11001] getaddrinfo failed -- Some packages may not b...
1
2010-01-29T04:00:53Z
2,160,367
<p>easy_install only knows how to install modules distributed with the Python standard distribution and packaging solution called distutils. Psycopg is not. Psycopg is instead installed with the so called CMMI dance: configure/make/make install. Doing that on Windows is tricky, hence, you need to download a precompiled...
0
2010-01-29T06:50:20Z
[ "python" ]
SQLAlchemy sqlalchemy.sql.expression.select vs. sqlalchemy.sql.expression.Select
2,159,874
<p>So I'm brand new to SQLAlchemy, and I'm trying to use the SQL Expression API to create a SELECT statement that specifies the exact columns to return. I found both a <a href="http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.Select" rel="nofollow" title="The Class: sqlalch...
1
2010-01-29T04:27:21Z
2,160,649
<p>I think it's pretty much the same. The documentation says for <code>select</code> (the function):</p> <pre><code>The returned object is an instance of Select. </code></pre> <p>As you can pass the select function the same parameters that <code>Select.__init__()</code> accepts, I don't really see a difference. At fi...
0
2010-01-29T08:09:14Z
[ "python", "sqlalchemy", "sql" ]
SQLAlchemy sqlalchemy.sql.expression.select vs. sqlalchemy.sql.expression.Select
2,159,874
<p>So I'm brand new to SQLAlchemy, and I'm trying to use the SQL Expression API to create a SELECT statement that specifies the exact columns to return. I found both a <a href="http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.Select" rel="nofollow" title="The Class: sqlalch...
1
2010-01-29T04:27:21Z
2,161,451
<p><a href="http://svn.sqlalchemy.org/sqlalchemy/trunk/lib/sqlalchemy/sql/expression.py" rel="nofollow">Use the source</a>.</p> <p>Here's the implementation of the <code>select</code> function, from the source code:</p> <pre><code>def select(columns=None, whereclause=None, from_obj=[], **kwargs): """Returns a ``S...
3
2010-01-29T11:06:19Z
[ "python", "sqlalchemy", "sql" ]
SQLAlchemy sqlalchemy.sql.expression.select vs. sqlalchemy.sql.expression.Select
2,159,874
<p>So I'm brand new to SQLAlchemy, and I'm trying to use the SQL Expression API to create a SELECT statement that specifies the exact columns to return. I found both a <a href="http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.Select" rel="nofollow" title="The Class: sqlalch...
1
2010-01-29T04:27:21Z
2,180,484
<p>the expression package provides Python functions to do everything. These functions in some cases return a class instance verbatim from the function's arguments and other times compose an object from several components. It was originally the idea that the functions would be doing a lot more composition than they ...
1
2010-02-01T22:19:04Z
[ "python", "sqlalchemy", "sql" ]
How do I pass compressed data using the Task Queue Python API in App Engine?
2,160,011
<p>I'm trying to use compressed data with my Tasks in the Task Queue like so:</p> <pre><code>t = taskqueue.Task(url='/tasks/queue', params={'param': zlib.compress(some_string)} </code></pre> <p>However when I try to decompress it in the queue handler like so</p> <pre><code>message = self.request.g...
1
2010-01-29T05:11:54Z
2,160,075
<p>Read <a href="http://code.google.com/appengine/docs/python/taskqueue/tasks.html" rel="nofollow">the docs</a>... (my emphasis!):</p> <blockquote> <p>params Dictionary of parameters to use for this Task. Values in the dictionary may be iterable to indicate repeated parameters. May not be specified for a POS...
2
2010-01-29T05:29:56Z
[ "python", "google-app-engine", "zlib", "task-queue" ]
How do I pass compressed data using the Task Queue Python API in App Engine?
2,160,011
<p>I'm trying to use compressed data with my Tasks in the Task Queue like so:</p> <pre><code>t = taskqueue.Task(url='/tasks/queue', params={'param': zlib.compress(some_string)} </code></pre> <p>However when I try to decompress it in the queue handler like so</p> <pre><code>message = self.request.g...
1
2010-01-29T05:11:54Z
2,161,244
<p>Instead of using params, use payload, which includes your data in the body of the request, unencoded. Then you can use <code>zlib.decompress(self.request.body)</code> to retrieve the data.</p>
5
2010-01-29T10:24:36Z
[ "python", "google-app-engine", "zlib", "task-queue" ]
m2crypto custom certificate verification
2,160,158
<p>I need to build an encrypted connection between two peers, and I need to authenticate both. Both peers already share a fingerprint (SHA256 hash) of the other peer public key. I'm not using X509 or OpenPGP keys/certs as they are too big and bulky for my needs and they don't fit in the security model.</p> <p>I'm tryi...
1
2010-01-29T05:52:01Z
2,160,849
<p>The answer is in the question: use proper x509 certificates, and validate/verify symmetrically. "Is this secure?" - no, because you have to ask.</p> <p>Your solution may work, but the fact you are asking for advice on "Is this secure?" tells me that you should probably use stuff straight from the box.</p>
-2
2010-01-29T08:58:48Z
[ "python", "m2crypto", "x509" ]
m2crypto custom certificate verification
2,160,158
<p>I need to build an encrypted connection between two peers, and I need to authenticate both. Both peers already share a fingerprint (SHA256 hash) of the other peer public key. I'm not using X509 or OpenPGP keys/certs as they are too big and bulky for my needs and they don't fit in the security model.</p> <p>I'm tryi...
1
2010-01-29T05:52:01Z
2,164,003
<p>It seems your approach should work, but there is already a builtin fingerprint checker you might be able to use. See here: <a href="http://stackoverflow.com/questions/2150048/what-to-put-for-a-commonname-when-making-an-openssl-key#2150499">http://stackoverflow.com/questions/2150048/what-to-put-for-a-commonname-when-...
0
2010-01-29T18:00:14Z
[ "python", "m2crypto", "x509" ]
Adding an edge/node with a color attribute
2,160,161
<p>I a using the <code>networkx</code> package of Python. The documentation says we can do <code>H.add_edge(1,2,color='blue')</code> but the output shows an edge with the default (black) color. When I do <code>H.add_node(12,color='green')</code> I get a new node with same default red color.</p>
0
2010-01-29T05:52:18Z
2,160,257
<p>Peter, according to the documentation, to change the color with which nodes/edges are <strong>drawn</strong>, you have to provide the <code>node_color</code> argument to the <em>drawing function</em>. I.e. from <a href="http://networkx.lanl.gov/examples/drawing/house_with_colors.html" rel="nofollow">this example</a>...
3
2010-01-29T06:19:47Z
[ "python", "networkx" ]
imports while starting an interactive shell
2,160,190
<p>When I start the interactive django shell through manage.py, by executing </p> <pre><code>python -v manage.py shell </code></pre> <p>from the project directory, I see a lot of modules of format django.package.module getting imported in the verbose output but still I have to import them to use it in the shell. </p>...
1
2010-01-29T06:00:10Z
2,160,200
<p>Python loads the <a href="http://docs.python.org/library/site.html" rel="nofollow"><code>site</code></a> module implicitly when starting up, which may in turn import other modules for its own use. You can pass <code>-S</code> to disable this behavior.</p>
0
2010-01-29T06:02:22Z
[ "python", "django", "shell", "import" ]
imports while starting an interactive shell
2,160,190
<p>When I start the interactive django shell through manage.py, by executing </p> <pre><code>python -v manage.py shell </code></pre> <p>from the project directory, I see a lot of modules of format django.package.module getting imported in the verbose output but still I have to import them to use it in the shell. </p>...
1
2010-01-29T06:00:10Z
2,160,266
<p>They are getting imported (look at sys.modules) and references to the module are created in whichever modules have imported it.</p> <p>When you do an import in your shell, if the module has already been imported, you will just get a copy of the reference to it in sys.modules </p>
0
2010-01-29T06:21:52Z
[ "python", "django", "shell", "import" ]
imports while starting an interactive shell
2,160,190
<p>When I start the interactive django shell through manage.py, by executing </p> <pre><code>python -v manage.py shell </code></pre> <p>from the project directory, I see a lot of modules of format django.package.module getting imported in the verbose output but still I have to import them to use it in the shell. </p>...
1
2010-01-29T06:00:10Z
2,160,276
<p><code>-v</code> traces the <strong>first</strong> import of a module -- the one that actually <strong>loads</strong> the module (executes its code, and so may take a bit of time) and sticks it into <code>sys.modules</code>.</p> <p>That has <strong>nothing</strong> to do whether your interactive session (module <cod...
1
2010-01-29T06:24:32Z
[ "python", "django", "shell", "import" ]
Problem Install and Run psycopg2 + Windows + Apache2 + mod_wsgi
2,160,256
<p>1) I try to setup a new web environment to host python + psycopg2 code. Here are my steps :</p> <p>2) Download <a href="http://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py26-3.0.so" rel="nofollow">http://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py26-3.0.so</a></p> <p>3) Copy mod_wsgi-win32-ap22py26-3....
1
2010-01-29T06:19:46Z
2,160,643
<p>I am able to solve the problem, by moving python script outside htdocs</p> <pre><code>WSGIScriptAlias /wsgi "C:/wsgi/" &lt;Directory "C:/wsgi"&gt; AllowOverride None Options None Order deny,allow Allow from all &lt;/Directory&gt; </code></pre>
1
2010-01-29T08:08:12Z
[ "python" ]
Access request in django custom template tags
2,160,261
<p>My code in myapp_extras.py:</p> <pre><code>from django import template register = template.Library() @register.inclusion_tag('new/userinfo.html') def address(): address = request.session['address'] return {'address':address} </code></pre> <p>in 'settings.py':</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS =...
57
2010-01-29T06:21:16Z
2,160,298
<p><code>request</code> is not a variable in that scope. You will have to get it from the context first. <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags">Pass <code>takes_context</code> to the decorator and add <code>context</code> to the tag arguments</a>.</p> <p>Like this:</p...
128
2010-01-29T06:30:35Z
[ "python", "django", "django-templates", "django-custom-tags" ]
Access request in django custom template tags
2,160,261
<p>My code in myapp_extras.py:</p> <pre><code>from django import template register = template.Library() @register.inclusion_tag('new/userinfo.html') def address(): address = request.session['address'] return {'address':address} </code></pre> <p>in 'settings.py':</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS =...
57
2010-01-29T06:21:16Z
2,943,973
<p>I've tried solution from above (from Ignacio Vazquez-Abrams) and it actually didn't work until I've found out that context processors works only with <code>RequestContext</code> wrapper class.</p> <p>So in main view method you should add the following line:</p> <pre><code>from django.template import RequestContext...
11
2010-05-31T13:54:22Z
[ "python", "django", "django-templates", "django-custom-tags" ]
Access request in django custom template tags
2,160,261
<p>My code in myapp_extras.py:</p> <pre><code>from django import template register = template.Library() @register.inclusion_tag('new/userinfo.html') def address(): address = request.session['address'] return {'address':address} </code></pre> <p>in 'settings.py':</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS =...
57
2010-01-29T06:21:16Z
8,669,417
<p>I've done this way:</p> <pre><code>from django import template register = template.Library() def do_test_request(parser,token): try: tag_name = token.split_contents() # Not really useful except ValueError: raise template.TemplateSyntaxError("%r error" % token.contents.split()[0]) return...
7
2011-12-29T15:01:33Z
[ "python", "django", "django-templates", "django-custom-tags" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
2,160,632
<p>Just change 99 to 100</p> <pre><code>for i in range(100): j = i + 3 print i, " j: ", j </code></pre> <p>Or</p> <pre><code>for i,j in [(i, i+3) for i in range(100)]: </code></pre>
8
2010-01-29T08:06:16Z
[ "c++", "python", "for-loop" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
2,160,634
<p>Since <code>j</code> is always dependent on the value of <code>i</code> you may as well replace all instances of <code>j</code> with <code>i + 3</code>.</p>
5
2010-01-29T08:06:24Z
[ "c++", "python", "for-loop" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
2,160,642
<p>These are identical except for the upper bound in the loop (98 vs 99). What is the question?</p> <p>On one line (but please don't do this):</p> <pre><code>for i,j in [(i, i+3) for i in range(100)]: </code></pre>
6
2010-01-29T08:08:08Z
[ "c++", "python", "for-loop" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
2,160,702
<p>I dont get it, it <em>is</em> exactly one python <code>for loop</code> there. What is the question? Do you want the <code>j</code> declaration inside the loop declaration like in c++? Check Prasson'S answer for the closest python equivalent. But why have a j variable in the first place? <code>j=i+3</code> seems to a...
3
2010-01-29T08:24:46Z
[ "c++", "python", "for-loop" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
2,160,722
<pre><code>for (i,j) in zip(range(100), range(3, 100+3)): </code></pre>
1
2010-01-29T08:29:27Z
[ "c++", "python", "for-loop" ]
Convert C++ to Python (For Loop multiple assignment)
2,160,616
<p>Convert to python:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i &lt; 100; ++i, j= i+3) cout &lt;&lt; i &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; getchar(); return 0; } </code></pre> <p>I try:</p> <pre><code>for i...
2
2010-01-29T08:02:05Z
9,161,406
<pre><code>for i in range(100): j = i + 3 print i, "j:", j raw_input() </code></pre> <p>C++: <a href="http://ideone.com/7Kdmk" rel="nofollow">http://ideone.com/7Kdmk</a></p> <p>Python: <a href="http://ideone.com/nATEP" rel="nofollow">http://ideone.com/nATEP</a></p>
0
2012-02-06T14:13:37Z
[ "c++", "python", "for-loop" ]
Single linked list in Python, how to write pop and push
2,160,994
<p>I am trying to code a class that makes use of Push and Pop from a stack (with single linked list). I am not sure how to write the push and pop functions. Please help me, I really need a simple example written in Python with the following functions.</p> <pre><code>Push Pop ifEmpty </code></pre>
1
2010-01-29T09:30:13Z
2,161,070
<p>From <a href="http://docs.python.org/tutorial/datastructures.html#using-lists-as-stacks">the docs</a> that Dyno Fu linked to:</p> <blockquote> <p>The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an i...
8
2010-01-29T09:46:22Z
[ "python", "stack" ]
Single linked list in Python, how to write pop and push
2,160,994
<p>I am trying to code a class that makes use of Push and Pop from a stack (with single linked list). I am not sure how to write the push and pop functions. Please help me, I really need a simple example written in Python with the following functions.</p> <pre><code>Push Pop ifEmpty </code></pre>
1
2010-01-29T09:30:13Z
2,161,135
<p>And here is the simplest stack class:</p> <pre><code>class stack(list): def push(self,item): self.append(item) def isEmpty(self): return not self &gt;&gt;&gt; a = stack() &gt;&gt;&gt; a.push(1) &gt;&gt; a.isEmpty() False &gt;&gt;&gt; a.pop() 1 &gt;&gt;&gt; a.isEmpty() True </code></pre>
3
2010-01-29T10:00:05Z
[ "python", "stack" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
2,162,068
<p>I don't believe that there's a direct equivalent, so Romain Francois's suggestion (in your link) is probably the best. You might also want to consider the following:</p> <ol> <li>Have a look at <a href="http://pylit.berlios.de/">PyLit</a> and <a href="http://gael-varoquaux.info/computers/pyreport/">PyReport</a> wh...
16
2010-01-29T13:06:34Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
2,174,842
<p>You could try <a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/sagetex.html" rel="nofollow">SageTeX</a> which implements Sweave-Like functionality for the <a href="http://www.sagemath.org" rel="nofollow">SAGE</a> mathematics platform. I haven't played around with it as much as I would like to, but SAG...
2
2010-02-01T05:32:43Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
2,230,883
<p>I have also thought about the same thing many times. After reading your questions and looking into your link I made small modifications to the custom python Sweave driver, that you link to. I modified it to also keep the source code and produce the output as well the same way that Sweave does for R.</p> <p>I poste...
2
2010-02-09T16:59:46Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
2,368,659
<p>I have written a Python implementation of Sweave called Pweave that implements basic functionality and some options of Sweave for Python code embedded in reST or Latex document. You can get it here: <a href="http://mpastell.com/pweave">http://mpastell.com/pweave</a> and see the original blog post here: <a href="htt...
20
2010-03-03T04:01:04Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
2,376,349
<p>You might consider noweb, which is language independent and is the basis for Sweave. I've used it for Python and it works well. </p> <p><a href="http://www.cs.tufts.edu/~nr/noweb/" rel="nofollow">http://www.cs.tufts.edu/~nr/noweb/</a></p>
4
2010-03-04T01:39:36Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
4,801,972
<p>I've restructured Matti's Pweave a bit, so that it is possible to define arbitrary "chunk-processors" as plugin-modules. This makes it easy to extend for several chunk-based text-preprocessing applications. The restructured version is available at <a href="https://bitbucket.org/edgimar/pweave/src" rel="nofollow">h...
3
2011-01-26T06:45:22Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
8,069,844
<p><a href="http://www.dexy.it/">Dexy</a> is a very similar product to Sweave. One advantage of Dexy is that it is not exclusive to one single language. You could create a Dexy document that included R code, Python code, or about anything else. </p>
14
2011-11-09T18:39:44Z
[ "python", "sweave", "literate-programming" ]
Sweave for python
2,161,152
<p>I've recently started using <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. </p> <p>I've found references to <a href="http://romainfrancois.blog.free.fr/index.php?post/2009/01/21/Python-and-S...
24
2010-01-29T10:03:56Z
14,471,700
<p>This is a bit late, but for future reference you might consider my <a href="https://github.com/gpoore/pythontex">PythonTeX</a> package for LaTeX. PythonTeX allows you enter Python code in a LaTeX document, run it, and bring back the output. But unlike Sweave, the document you actually edit is a valid .tex document ...
7
2013-01-23T02:55:58Z
[ "python", "sweave", "literate-programming" ]
How to Send/Receive SMS using AT commands?
2,161,197
<p>Can anyone help me to send and receive SMS using AT commands in Python?</p> <p>In case it matters, I'm using Fedora 8.</p> <p>Which phone will be better with Linux (Nokia, Sony Ericson, Samsung,.....)? Will all phones support sending and receiving SMS using AT commands?</p>
8
2010-01-29T10:13:38Z
2,161,275
<p>Talking to the phone is easy. You just need to open the appropriate <code>/dev/ttyACM*</code> device and talk to it. Which phone is trickier. Any phone that supports "tethering" and the full AT command set for SMS messages should be fine.</p>
1
2010-01-29T10:31:41Z
[ "python", "sms", "at-command" ]
How to Send/Receive SMS using AT commands?
2,161,197
<p>Can anyone help me to send and receive SMS using AT commands in Python?</p> <p>In case it matters, I'm using Fedora 8.</p> <p>Which phone will be better with Linux (Nokia, Sony Ericson, Samsung,.....)? Will all phones support sending and receiving SMS using AT commands?</p>
8
2010-01-29T10:13:38Z
6,862,740
<p>Here's some example code that should get you started (in Python 3000):</p> <pre><code>import time import serial recipient = "+1234567890" message = "Hello, World!" phone = serial.Serial("/dev/ttyACM0", 460800, timeout=5) try: time.sleep(0.5) phone.write(b'ATZ\r') time.sleep(0.5) phone.write(b'AT+...
4
2011-07-28T16:58:15Z
[ "python", "sms", "at-command" ]
How to Send/Receive SMS using AT commands?
2,161,197
<p>Can anyone help me to send and receive SMS using AT commands in Python?</p> <p>In case it matters, I'm using Fedora 8.</p> <p>Which phone will be better with Linux (Nokia, Sony Ericson, Samsung,.....)? Will all phones support sending and receiving SMS using AT commands?</p>
8
2010-01-29T10:13:38Z
19,498,417
<p>to see send sms using At command this will help.</p> <pre><code> import serial import time class TextMessage: def __init__(self, recipient="+2348065777685", message="TextMessage.content not set."): self.recipient = recipient self.content = message def setRecipien...
3
2013-10-21T15:18:22Z
[ "python", "sms", "at-command" ]
Multiple consumers & producers connected to a message queue, Is that possible in AMQP?
2,161,206
<p>I'd like to create a farm of processes that are able to OCR text. I've thought about using a single queue of messages which is read by multiple OCR processes.</p> <p>I would like to ensure that:</p> <ul> <li>each message in queue is eventually processed</li> <li>the work is more or less equally distributed</li> <l...
4
2010-01-29T10:16:09Z
2,161,354
<p>Yes, that's possible. Server cluster for a real-time MMO game I'm working on operate this way. We use ActiveMQ, but I think all this possible with RabbitMQ as well.</p> <p>All items that you mentioned you get out of the box, except last one.</p> <ul> <li><em>each message in queue is eventually processed</em> - thi...
3
2010-01-29T10:48:49Z
[ "python", "message-queue", "rabbitmq", "amqp", "py-amqplib" ]
Multiple consumers & producers connected to a message queue, Is that possible in AMQP?
2,161,206
<p>I'd like to create a farm of processes that are able to OCR text. I've thought about using a single queue of messages which is read by multiple OCR processes.</p> <p>I would like to ensure that:</p> <ul> <li>each message in queue is eventually processed</li> <li>the work is more or less equally distributed</li> <l...
4
2010-01-29T10:16:09Z
2,279,984
<p>Yes, as @nailxx points out. The AMQP programming model is slightly different from JMS in that you only have <em>queues</em>, which can be shared between workers, or used <em>privately</em> by a single worker. You can also easily set up RabbitMQ to do <em>PubSub</em> use cases or what in JMS are called <em>topics</e...
5
2010-02-17T10:50:00Z
[ "python", "message-queue", "rabbitmq", "amqp", "py-amqplib" ]
Send AT-command through bluetooth from python application
2,161,365
<p>how can i send AT-command through bluetooth from a python application?</p> <p>OS:fedora 8</p> <p>Any one please healp me with the code?</p> <p>which package i need to import?</p> <p>from where can i download it? </p>
0
2010-01-29T10:49:55Z
2,163,908
<p>To get a connection over bluetooth to your IP modem, you want to use the bluetooth rfcomm driver:</p> <pre><code>michael@challenger:~&gt; cat /etc/bluetooth/rfcomm.conf rfcomm0 { # Automatically bind the device at startup bind yes; # Bluetooth address of the device device 00:1C:CC:...
1
2010-01-29T17:45:30Z
[ "python", "sms", "fedora", "at-command" ]
Send AT-command through bluetooth from python application
2,161,365
<p>how can i send AT-command through bluetooth from a python application?</p> <p>OS:fedora 8</p> <p>Any one please healp me with the code?</p> <p>which package i need to import?</p> <p>from where can i download it? </p>
0
2010-01-29T10:49:55Z
2,415,867
<p>I think this is better....... </p> <pre><code>import bluetooth sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM) sockfd.connect(('00:24:7E:9E:55:0D', 1)) # BT Address sockfd.send('ATZ\r') time.sleep(1) sockfd.send(chr(26)) sockfd.close() </code></pre>
1
2010-03-10T09:51:44Z
[ "python", "sms", "fedora", "at-command" ]
How to redirect stdout for a subprocess?
2,161,409
<pre><code>def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + "MyLog.txt","w") #new path for each file if parm: proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None) else: MyReset(proc) #reset the process(proc) to its default...
6
2010-01-29T10:57:37Z
2,161,456
<p>You can't. Once the process is started, its stdout is nothing you can change from the outside. You need to get inside that process' space to muck with its file descriptors.</p> <p>If you have a way (in <code>MyReset()</code> I guess) to talk to the running process, perhaps you can engineer a way to pass a new filen...
4
2010-01-29T11:07:25Z
[ "python", "subprocess", "stdout" ]
How to redirect stdout for a subprocess?
2,161,409
<pre><code>def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + "MyLog.txt","w") #new path for each file if parm: proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None) else: MyReset(proc) #reset the process(proc) to its default...
6
2010-01-29T10:57:37Z
2,162,770
<p>Like unwind said, you cannot change the file descriptor that the child process is writing its output to.</p> <p>What you can do, is read the output from the child process in your python script and then write it back to whatever file you want to. E.g.:</p> <pre><code>proc = subprocess.Popen(path, 0, None, subproces...
6
2010-01-29T15:04:50Z
[ "python", "subprocess", "stdout" ]
How to redirect stdout for a subprocess?
2,161,409
<pre><code>def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + "MyLog.txt","w") #new path for each file if parm: proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None) else: MyReset(proc) #reset the process(proc) to its default...
6
2010-01-29T10:57:37Z
4,543,075
<p>There are subtle problems/bugs in python related to subprocess.PIPE: <a href="http://bugs.python.org/issue1652" rel="nofollow">http://bugs.python.org/issue1652</a></p> <p>Apparently this was fixed in python3+, but not in python 2.7 and older. For that you need to use: code.google.com/p/python-subprocess32/</p>
1
2010-12-28T01:26:07Z
[ "python", "subprocess", "stdout" ]
JSON python to javascript
2,161,457
<p>I want to transfer some data <strong>from python to javascript</strong>. I use Django at python side and jQuery at javascript side.</p> <p>The object I serialize at python side is a dictionary. </p> <p>Besides simple objects like lists and variables, this dictionary contains instances of SomeClass. To serialize th...
1
2010-01-29T11:08:10Z
2,161,483
<ol> <li>Eval the JSON string into an object</li> <li>Run through the values of the object and identify values with magicParameter='SomeClass'</li> <li>Run those values through a converter</li> <li>Assign the result back to where the value initially was in the result object</li> </ol>
0
2010-01-29T11:14:55Z
[ "javascript", "jquery", "python", "django", "json" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,531
<p>Use the regex <code>(\d+)([a-zA-Z]+)</code>.</p> <pre><code>import re a = ["10people", "5cars"] [re.match('^(\\d+)([a-zA-Z]+)$', x).groups() for x in a] </code></pre> <p>Result: </p> <pre><code>[('10', 'people'), ('5', 'cars')] </code></pre>
8
2010-01-29T11:24:19Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,544
<pre><code>&gt;&gt;&gt; re.findall("\d+|[a-zA-Z]+","10people") ['10', 'people'] &gt;&gt;&gt; re.findall("\d+|[a-zA-Z]+","10people5cars") ['10', 'people', '5', 'cars'] </code></pre>
3
2010-01-29T11:26:10Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,547
<pre><code>&gt;&gt;&gt; re.findall('(\d+|[a-zA-Z]+)', '12fgsdfg234jhfq35rjg') ['12', 'fgsdfg', '234', 'jhfq', '35', 'rjg'] </code></pre>
8
2010-01-29T11:27:07Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,549
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = '10cars' &gt;&gt;&gt; m = re.match(r'(\d+)([a-z]+)', s) &gt;&gt;&gt; print m.group(1) 10 &gt;&gt;&gt; print m.group(2) cars </code></pre>
0
2010-01-29T11:27:33Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,810
<p>If you are like me and goes long loops around to avoid regexpes justbecause they are ugly, here is a non-regex approach:</p> <pre><code>data = "5people10cars" numbers = "".join(ch if ch.isdigit() else "\n" for ch in data).split() names = "".join(ch if not ch.isdigit() else "\n" for ch in data).split() final = zip...
0
2010-01-29T12:21:26Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,161,870
<p>In general, a split on <code>/(?&lt;=[0-9])(?=[a-z])|(?&lt;=[a-z])(?=[0-9])/i</code> separates a string that way.</p>
2
2010-01-29T12:33:43Z
[ "python", "regex" ]
Regex to separate Numeric from Alpha
2,161,519
<p>I have a bunch of strings:</p> <pre><code>"10people" "5cars" .. </code></pre> <p>How would I split this to?</p> <pre><code>['10','people'] ['5','cars'] </code></pre> <p>It can be any amount of numbers and text.</p> <p>I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it ...
4
2010-01-29T11:21:52Z
2,166,116
<p>Piggybacking on jsbueno's idea, using str.translate, followed by split:</p> <pre><code>import string allchars = ''.join(chr(i) for i in range(32,256)) digExtractTrans = string.maketrans(allchars, ''.join(ch if ch.isdigit() else ' ' for ch in allchars)) alpExtractTrans = string.maketrans(allchars, ''.join(ch if ch....
0
2010-01-29T23:58:58Z
[ "python", "regex" ]
HTML parser for GAE
2,161,560
<p>Generally I use <a href="http://codespeak.net/lxml/">lxml</a> for my HTML parsing needs, but that isn't available on Google App Engine. The obvious alternative is <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, but I find it chokes too easily on malformed HTML. Currently I am testing <a hr...
5
2010-01-29T11:29:20Z
2,161,864
<p>From the <a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html">BeautifulSoup documentation</a>:</p> <blockquote> <p>Version 3.1.0 of Beautiful Soup does significantly worse on real-world HTML than version 3.0.8 does</p> </blockquote> <p>So, it might help you to use this earlier version. That i...
5
2010-01-29T12:32:26Z
[ "python", "google-app-engine", "html-parsing", "lxml" ]
HTML parser for GAE
2,161,560
<p>Generally I use <a href="http://codespeak.net/lxml/">lxml</a> for my HTML parsing needs, but that isn't available on Google App Engine. The obvious alternative is <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, but I find it chokes too easily on malformed HTML. Currently I am testing <a hr...
5
2010-01-29T11:29:20Z
2,181,364
<p>No longer a problem - lxml is supported: <a href="https://developers.google.com/appengine/docs/python/tools/libraries27" rel="nofollow">https://developers.google.com/appengine/docs/python/tools/libraries27</a></p>
5
2010-02-02T01:31:38Z
[ "python", "google-app-engine", "html-parsing", "lxml" ]
Executing multiple commands using Popen.stdin
2,161,575
<p>I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command ...
15
2010-01-29T11:33:34Z
2,163,109
<p>It sounds like your application is treating input from a pipe in a strange way. This means it won't get all of the commands you send until you close the pipe.</p> <p>So the approach I would suggest is just to do this:</p> <pre><code>process.stdin.write("command1\n") process.stdin.write("command2\n") process.stdin...
-1
2010-01-29T15:52:51Z
[ "python", "popen" ]
Executing multiple commands using Popen.stdin
2,161,575
<p>I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command ...
15
2010-01-29T11:33:34Z
7,537,987
<p>Your code in the question should work as is. If it doesn't then either your actual code is different (e.g., you might use <a href="http://pexpect.readthedocs.org/en/latest/FAQ.html#whynotpipe" rel="nofollow"><code>stdout=PIPE</code> that may change the child buffering behavior</a>) or it might indicate a bug in the ...
0
2011-09-24T08:48:36Z
[ "python", "popen" ]
Executing multiple commands using Popen.stdin
2,161,575
<p>I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command ...
15
2010-01-29T11:33:34Z
7,614,453
<p>If I understand your problem correctly, you want to interact (i.e. send commands and read the responses) with a console application.</p> <p>If so, you may want to check an Expect-like library, like pexpect for Python: <a href="http://pexpect.sourceforge.net" rel="nofollow">http://pexpect.sourceforge.net</a></p> <p...
1
2011-09-30T18:20:39Z
[ "python", "popen" ]
Executing multiple commands using Popen.stdin
2,161,575
<p>I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command ...
15
2010-01-29T11:33:34Z
8,502,713
<p>The real issue here is whether the application is buffering its output, and if it is whether there's anything you can do to stop it. Presumably when the user generates a command and clicks a button on your GUI you want to see the output from that command before you require the user to enter the next.</p> <p>Unfortu...
0
2011-12-14T10:10:39Z
[ "python", "popen" ]
Django and Postgres transaction rollback
2,161,723
<p>I have a piece of code that works in a background process which looks like</p> <pre><code>from django.db import transaction try: &lt;some code&gt; transaction.commit() except Exception, e: print e transaction.rollback() </code></pre> <p>In a test, I break <code>&lt;some_code&gt;</code> with d...
5
2010-01-29T12:02:54Z
2,164,322
<p>I wrote this decorator based on the transaction middleware <a href="http://code.djangoproject.com/browser/django/trunk/django/middleware/transaction.py" rel="nofollow">source</a>. Hope it helps, works perfectly for me.</p> <pre><code>def djangoDBManaged(func): def f(*args, **kwargs): django.db.transacti...
2
2010-01-29T18:46:56Z
[ "python", "django", "postgresql", "transactions" ]
Django and Postgres transaction rollback
2,161,723
<p>I have a piece of code that works in a background process which looks like</p> <pre><code>from django.db import transaction try: &lt;some code&gt; transaction.commit() except Exception, e: print e transaction.rollback() </code></pre> <p>In a test, I break <code>&lt;some_code&gt;</code> with d...
5
2010-01-29T12:02:54Z
2,164,797
<p>Default TestCase does not know anything about transactions, you need to use <a href="http://docs.djangoproject.com/en/dev/topics/testing/#django.test.TransactionTestCase">TransactionalTestCase</a> in this case.</p>
6
2010-01-29T20:04:16Z
[ "python", "django", "postgresql", "transactions" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,161,764
<p>For your first question, iterate the list and use a dictionary to keep track of an elements existsence. </p> <p>For your second question, just use the set operator.</p>
4
2010-01-29T12:10:59Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,161,791
<p>To count the number of appearances:</p> <pre><code>from collections import defaultdict appearances = defaultdict(int) for curr in a: appearances[curr] += 1 </code></pre> <p>To remove duplicates:</p> <pre><code>a = set(a) </code></pre>
31
2010-01-29T12:16:03Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,161,792
<p>Counting the frequency of elements is probably best done with a dictionary:</p> <pre><code>b = {} for item in a: b[item] = b.get(item, 0) + 1 </code></pre> <p>To remove the duplicates, use a set:</p> <pre><code>a = list(set(a)) </code></pre>
13
2010-01-29T12:16:19Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,161,798
<pre><code>seta = set(a) b = [a.count(el) for el in seta] a = list(seta) #Only if you really want it. </code></pre>
5
2010-01-29T12:18:15Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,161,801
<p>Since the list is ordered you can do this:</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] from itertools import groupby [len(list(group)) for key, group in groupby(a)] </code></pre> <p>Output:</p> <pre><code>[4, 4, 2, 1, 2] </code></pre>
47
2010-01-29T12:18:39Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,162,035
<p>In Python 2.7+, you could use <a href="http://docs.python.org/3.1/whatsnew/2.7.html#new-improved-and-deprecated-modules">collections.Counter</a> to count items</p> <pre><code>&gt;&gt;&gt; a = [1,1,1,1,2,2,2,2,3,3,4,5,5] &gt;&gt;&gt; &gt;&gt;&gt; from collections import Counter &gt;&gt;&gt; c=Counter(a) &gt;&gt;&gt;...
9
2010-01-29T13:00:53Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
2,162,045
<p>In Python 2.7, you can use <a href="https://docs.python.org/2/library/collections.html#collections.Counter"><code>collections.Counter</code></a>:</p> <pre><code>import collections a = [1,1,1,1,2,2,2,2,3,3,4,5,5] counter=collections.Counter(a) print(counter) # Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1}) print(counter.va...
216
2010-01-29T13:02:41Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
9,744,274
<p>Python 2.7+ introduces Dictionary Comprehension. Building the dictionary from the list will get you the count as well as get rid of duplicates.</p> <pre><code>&gt;&gt;&gt; a = [1,1,1,1,2,2,2,2,3,3,4,5,5] &gt;&gt;&gt; d = {x:a.count(x) for x in a} &gt;&gt;&gt; d {1: 4, 2: 4, 3: 2, 4: 1, 5: 2} &gt;&gt;&gt; a, b = d.k...
54
2012-03-16T20:44:01Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
31,145,928
<p>This answer is more explicit</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,3,4,4] d = {} for item in a: if item in d: d[item] = d.get(item)+1 else: d[item] = 1 for k,v in d.items(): print(str(k)+':'+str(v)) # output #1:4 #2:4 #3:3 #4:2 #remove dups d = set(a) print(d) #{1, 2, 3, 4} </code>...
4
2015-06-30T18:39:12Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
31,337,304
<pre><code>#!usr/bin/python def frq(words): freq = {} for w in words: if w in freq: freq[w] = freq.get(w)+1 else: freq[w] =1 return freq fp = open("poem","r") list = fp.read() fp.close() input = list.split() print input d = frq(input) print "f...
0
2015-07-10T09:31:01Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
34,379,128
<p>Yet another solution with another algorithm without using collections:</p> <pre><code>def countFreq(A): n=len(A) count=[0]*n # Create a new list initialized with '0' for i in range(n): count[A[i]]+= 1 # increase occurrence for value A[i] return [x for x in count if...
1
2015-12-20T08:17:38Z
[ "python", "counter", "frequency", "counting" ]
How to count the frequency of the elements in a list?
2,161,752
<p>I'm a python newbie, so please bear with me.</p> <p>I need to find the frequency of elements in a list</p> <pre><code>a = [1,1,1,1,2,2,2,2,3,3,4,5,5] </code></pre> <p>output-></p> <pre><code>b = [4,4,2,1,2] </code></pre> <p>Also I want to remove the duplicates from a</p> <pre><code>a = [1,2,3,4,5] </code></pre...
77
2010-01-29T12:08:20Z
35,105,509
<p>I would simply use scipy.stats.itemfreq in the following manner:</p> <pre><code>from scipy.stats import itemfreq a = [1,1,1,1,2,2,2,2,3,3,4,5,5] freq = itemfreq(a) a = freq[:,0] b = freq[:,1] </code></pre> <p>you may check the documentation here: <a href="http://docs.scipy.org/doc/scipy-0.16.0/reference/generat...
0
2016-01-30T18:35:39Z
[ "python", "counter", "frequency", "counting" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
2,161,965
<p>The <a href="http://docs.python.org/library/subprocess.html"><code>subprocess</code></a> module lets you call other programs:</p> <pre><code>import subprocess plot = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE) plot.communicate("plot '%s' with lines, '%s' with points;" % (eout,nout)) </code></pre>
19
2010-01-29T12:48:52Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
2,162,092
<p>A simple approach might be to just write a third file containing your gnuplot commands and then tell Python to execute gnuplot with that file. Say you write </p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>to a file called tmp.gp. Then you can use</p> <pre><code>from os imp...
6
2010-01-29T13:11:02Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
5,002,645
<p>Subprocess is explained very clearly on Doug Hellemann's <a href="http://www.doughellmann.com/PyMOTW/subprocess/">Python Module of the Week</a></p> <p>This works well:</p> <pre><code>import subprocess proc = subprocess.Popen(['gnuplot','-p'], shell=True, stdin=subp...
11
2011-02-15T10:43:21Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
5,755,861
<p>I was trying to do something similar, but additionally I wanted to feed data from within python and output the graph <em>file</em> as a variable (so neither the data nor the graph are actual files). This is what I came up with:</p> <pre><code>#! /usr/bin/env python import subprocess from sys import stdout, stderr ...
4
2011-04-22T13:23:42Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
6,356,788
<p>Here's a class that provides an interface to wgnuplot.exe:</p> <pre><code>from ctypes import * import time import sys import os # # some win32 constants # WM_CHAR = 0X0102 WM_CLOSE = 16 SW_HIDE = 0 STARTF_USESHOWWINDOW = 1 WORD = c_ushort DWORD = c_ulong LPBYTE = POINTER(c_ubyte) LPTSTR = POINTE...
2
2011-06-15T11:09:46Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
18,098,355
<p>I am a bit late, but since it took me some time to make it work, maybe it's worth putting a note. The programs are working with Python 3.3.2 on Windows.</p> <p>Notice that bytes are used everywhere, not strings (e.g. b"plot x", not simply "plot x"), but in case it's a problem, simply do something like:</p> <pre><c...
1
2013-08-07T08:27:25Z
[ "python", "gnuplot" ]
Calling gnuplot from python
2,161,932
<p>I've a python script that after some computing will generate two data files formatted as gnuplot input.</p> <p>How do I 'call' gnuplot from python ?</p> <p>I want to send the following python string as input to gnuplot:</p> <pre><code>"plot '%s' with lines, '%s' with points;" % (eout,nout) </code></pre> <p>where...
14
2010-01-29T12:44:00Z
21,633,082
<p>I went with Ben's suggestion as I was computing charts from a celery job and found that it would lockup when reading from stdout. I redesigned it like so using StringIO to create the file destined for stdin and subprocess.communicate to get the result immediately via stdout, no read required.</p> <pre><code> from s...
2
2014-02-07T16:35:58Z
[ "python", "gnuplot" ]