title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Why is there module search path instead of typing the directory name + typing the file name? | 1,177,513 | <p>Is there an advantage? What is it?</p>
| 2 | 2009-07-24T13:06:21Z | 1,177,526 | <p>So that everyone doesn't need to have <em>exactly</em> the same file structure on their hard drive? <code>import C:\Python\lib\module\</code> probably wouldn't work too well on my Mac...</p>
<p>Edit: Also, what the heck are you talking about with the working directory? You can <em>certainly</em> use modules outsi... | 6 | 2009-07-24T13:08:43Z | [
"python",
"import",
"module-search-path"
] |
Change current process environment's LD_LIBRARY_PATH | 1,178,094 | <p>Is it possible to change environment variables of current process? </p>
<p>More specifically in a python script I want to change <code>LD_LIBRARY_PATH</code> so that on import of a module 'x' which depends on some <code>xyz.so</code>, <code>xyz.so</code> is taken from my given path in LD_LIBRARY_PATH </p>
<p>is th... | 18 | 2009-07-24T14:33:06Z | 1,178,117 | <p>well, the environment variables are stored in the dictionary os.environ, so if you want to change , you can do</p>
<pre><code>os.environ["PATH"] = "/usr/bin"
</code></pre>
| -4 | 2009-07-24T14:37:50Z | [
"python",
"shared-libraries",
"environment-variables"
] |
Change current process environment's LD_LIBRARY_PATH | 1,178,094 | <p>Is it possible to change environment variables of current process? </p>
<p>More specifically in a python script I want to change <code>LD_LIBRARY_PATH</code> so that on import of a module 'x' which depends on some <code>xyz.so</code>, <code>xyz.so</code> is taken from my given path in LD_LIBRARY_PATH </p>
<p>is th... | 18 | 2009-07-24T14:33:06Z | 1,178,878 | <p>In my experience trying to change the way the loader works for a running Python is very tricky; probably OS/version dependent; may not work. One work-around that might help in some circumstances is to launch a sub-process that changes the environment parameter using a shell script and then launch a new Python using... | 0 | 2009-07-24T16:55:45Z | [
"python",
"shared-libraries",
"environment-variables"
] |
Change current process environment's LD_LIBRARY_PATH | 1,178,094 | <p>Is it possible to change environment variables of current process? </p>
<p>More specifically in a python script I want to change <code>LD_LIBRARY_PATH</code> so that on import of a module 'x' which depends on some <code>xyz.so</code>, <code>xyz.so</code> is taken from my given path in LD_LIBRARY_PATH </p>
<p>is th... | 18 | 2009-07-24T14:33:06Z | 1,186,194 | <p>The reason</p>
<pre><code>os.environ["LD_LIBRARY_PATH"] = ...
</code></pre>
<p>doesn't work is simple: this environment variable controls behavior of the dynamic loader (<code>ld-linux.so.2</code> on Linux, <code>ld.so.1</code> on Solaris), but the loader only looks at <code>LD_LIBRARY_PATH</code> once at process ... | 29 | 2009-07-27T02:33:05Z | [
"python",
"shared-libraries",
"environment-variables"
] |
Change current process environment's LD_LIBRARY_PATH | 1,178,094 | <p>Is it possible to change environment variables of current process? </p>
<p>More specifically in a python script I want to change <code>LD_LIBRARY_PATH</code> so that on import of a module 'x' which depends on some <code>xyz.so</code>, <code>xyz.so</code> is taken from my given path in LD_LIBRARY_PATH </p>
<p>is th... | 18 | 2009-07-24T14:33:06Z | 16,517,435 | <p>Based on the answer from Employed Russian, this is what works for me</p>
<pre><code>oracle_libs = os.environ['ORACLE_HOME']+"/lib/"
rerun = True
if not 'LD_LIBRARY_PATH' in os.environ:
os.environ['LD_LIBRARY_PATH'] = ":"+oracle_libs
elif not oracle_libs in os.environ.get('LD_LIBRARY_PATH'):
os.environ['LD_LIBR... | 7 | 2013-05-13T08:10:32Z | [
"python",
"shared-libraries",
"environment-variables"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,356 | <p>just do a split on the line by comment then get the first element
eg</p>
<pre><code>line.split(";")[0]
</code></pre>
| 10 | 2009-07-24T15:18:36Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,360 | <p>I'd recommend saying</p>
<pre><code>line.split(";")[0]
</code></pre>
<p>which will give you a string of all characters up to but not including the first ";" character. If no ";" character is present, then it will give you the entire line.</p>
| 67 | 2009-07-24T15:18:42Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,365 | <p>For Python 2.5 or greater, I would use the <a href="http://docs.python.org/library/stdtypes.html?highlight=partition#str.partition" rel="nofollow"><code>partition</code></a> method:</p>
<pre><code>rtr = line.partition(';')[0].rstrip() + '\n'
</code></pre>
| 4 | 2009-07-24T15:19:50Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,423 | <pre><code>file = open(r'c:\temp\test.txt', 'r')
for line in file: print
line.split(";")[0].strip()
</code></pre>
| 2 | 2009-07-24T15:27:49Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,529 | <p>Reading, splitting, stripping, and joining lines with newline all in one line of python:</p>
<pre><code>rtr = '\n'.join(line.split(';')[0].strip() for line in open(r'c:\temp\test.txt', 'r'))
</code></pre>
| 1 | 2009-07-24T15:46:47Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,178,634 | <p>I have not tested this with python but I use similar code else where.</p>
<pre><code>import re
content = open(r'c:\temp\test.txt', 'r').read()
content = re.sub(";.+", "\n")
</code></pre>
| -2 | 2009-07-24T16:06:21Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,179,125 | <p>So you'll want to split the line on the first semicolon, take everything before it, strip off any lingering whitespace, and append a newline character.</p>
<pre><code>rtr = line.split(";", 1)[0].rstrip() + '\n'
</code></pre>
<p><strong>Links to Documentation:</strong></p>
<ul>
<li><a href="http://docs.python.org/... | 2 | 2009-07-24T17:46:50Z | [
"python",
"string",
"python-2.4"
] |
In Python 2.4, how can I strip out characters after ';'? | 1,178,335 | <p>Let's say I'm parsing a file, which uses <code>;</code> as the comment character. I don't want to parse comments. So if I a line looks like this:</p>
<pre><code>example.com. 600 IN MX 8 s1b9.example.net ; hello!
</code></pre>
<p>Is there an easier/more-elegant way to strip chars out othe... | 18 | 2009-07-24T15:15:17Z | 1,183,356 | <p>Here is another way :</p>
<pre>
In [6]: line = "foo;bar"
In [7]: line[:line.find(";")] + "\n"
Out[7]: 'foo\n'
</pre>
| 0 | 2009-07-25T23:34:54Z | [
"python",
"string",
"python-2.4"
] |
How can I create bound methods with type()? | 1,178,337 | <p>I am dynamically generating a function and assigning it to a class. This is a simple/minimal example of what I am trying to achieve:</p>
<pre><code>def echo(obj):
print obj.hello
class Foo(object):
hello = "Hello World"
spam = type("Spam", (Foo, ), {"echo":echo})
spam.echo()
</code></pre>
<p>Results in t... | 1 | 2009-07-24T15:16:30Z | 1,178,371 | <p>So far, you only have created a class. You also need to create objects, i.e. instances of that class:</p>
<pre><code>Spam = type("Spam", (Foo, ), {"echo":echo})
spam = Spam()
spam.echo()
</code></pre>
<p>If you really want this to be a method on the class, rather than an instance method, wrap it with classmethod (... | 8 | 2009-07-24T15:21:28Z | [
"python"
] |
How to store arbitrary number of fields in django model? | 1,178,551 | <p>I'm new to python/django. I need to store an arbitrary number of fields in a django model. I'm wondering if django has something that takes care of this.</p>
<p>Typically, I would store some XML in a column to do this. Does django offer some classes that makes this easy to do whether it be XML or some other(better)... | 1 | 2009-07-24T15:51:28Z | 1,178,624 | <p>There are a lot of approaches to solve this problem, and depending on your situation any of them might work. You could certainly use a TextField to store XML or JSON or any other form of text. In combination with Python's pickle feature you can do some neater stuff.</p>
<p>You might look at the Django Pickle Field ... | 11 | 2009-07-24T16:03:44Z | [
"python",
"django",
"django-models"
] |
How to store arbitrary number of fields in django model? | 1,178,551 | <p>I'm new to python/django. I need to store an arbitrary number of fields in a django model. I'm wondering if django has something that takes care of this.</p>
<p>Typically, I would store some XML in a column to do this. Does django offer some classes that makes this easy to do whether it be XML or some other(better)... | 1 | 2009-07-24T15:51:28Z | 1,178,652 | <p>There is a XML field available:
<a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#xmlfield" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/fields/#xmlfield</a></p>
<p>But it would force you to do extra parsing on the resulting query.
(Which I think you'll have to do to some degree...)... | 0 | 2009-07-24T16:09:45Z | [
"python",
"django",
"django-models"
] |
Python: encryption as means to prevent data tampering | 1,178,789 | <p>Many of my company's clients use our data acquisition software in a research basis. Due to the nature of research in general, some of the clients ask that data is encrypted to prevent tampering -- there could be serious ramifications if their data was shown to be falsified.</p>
<p>Some of our <em>binary</em> softw... | 1 | 2009-07-24T16:39:15Z | 1,178,816 | <p>If you are embedding passwords somewhere, you are already hosed. You can't guarantee anything.</p>
<p>However, you could use public key/private key encryption to make sure the data hasn't been tampered with.</p>
<p>The way it works is this:</p>
<ol>
<li>You generate a public key / private key pair.</li>
<li>Keep... | 3 | 2009-07-24T16:45:37Z | [
"python",
"encryption",
"data-integrity",
"tampering"
] |
Python: encryption as means to prevent data tampering | 1,178,789 | <p>Many of my company's clients use our data acquisition software in a research basis. Due to the nature of research in general, some of the clients ask that data is encrypted to prevent tampering -- there could be serious ramifications if their data was shown to be falsified.</p>
<p>Some of our <em>binary</em> softw... | 1 | 2009-07-24T16:39:15Z | 1,178,819 | <p>As a general principle, you don't want to use encryption to protect against tampering, instead you want to use a digital signature. Encryption gives you <strong>confidentiality</strong>, but you are after <strong>integrity</strong>.</p>
<p>Compute a hash value over your data and either store the hash value in a pla... | 12 | 2009-07-24T16:46:22Z | [
"python",
"encryption",
"data-integrity",
"tampering"
] |
Python: encryption as means to prevent data tampering | 1,178,789 | <p>Many of my company's clients use our data acquisition software in a research basis. Due to the nature of research in general, some of the clients ask that data is encrypted to prevent tampering -- there could be serious ramifications if their data was shown to be falsified.</p>
<p>Some of our <em>binary</em> softw... | 1 | 2009-07-24T16:39:15Z | 1,188,900 | <p>Here's another issue. Presumably, your data acquisition software is collecting data from some external source (like some sort of measuring device), then doing whatever processsing is necessary on the raw data and storing the results. Regardless of what method you use in your program, another possible attack vector w... | 0 | 2009-07-27T15:37:28Z | [
"python",
"encryption",
"data-integrity",
"tampering"
] |
exit failed script run (python) | 1,178,989 | <p>I have seen several questions about exiting a script after a task is successfully completed, but is there a way to do the same for a script which has failed? I am writing a testing script which just checks that a camera is functioning correctly. If the first test fails it is more than likely that the following tests... | 4 | 2009-07-24T17:22:47Z | 1,179,002 | <p>Are you just looking for the <a href="http://docs.python.org/library/sys.html#sys.exit"><code>exit()</code></a> function?</p>
<pre><code>import sys
if 1 < 0:
print >> sys.stderr, "Something is seriously wrong."
sys.exit(1)
</code></pre>
<p>The (optional) parameter of <code>exit()</code> is the return... | 15 | 2009-07-24T17:25:19Z | [
"python",
"exception",
"exit"
] |
exit failed script run (python) | 1,178,989 | <p>I have seen several questions about exiting a script after a task is successfully completed, but is there a way to do the same for a script which has failed? I am writing a testing script which just checks that a camera is functioning correctly. If the first test fails it is more than likely that the following tests... | 4 | 2009-07-24T17:22:47Z | 1,179,014 | <p>You can use <a href="http://docs.python.org/library/sys.html#sys.exit" rel="nofollow"><code>sys.exit()</code></a> to exit. However, if any code higher up catches the <a href="http://docs.python.org/library/exceptions.html#exceptions.SystemExit" rel="nofollow"><code>SystemExit</code></a> exception, it won't exit.</p... | 3 | 2009-07-24T17:26:44Z | [
"python",
"exception",
"exit"
] |
exit failed script run (python) | 1,178,989 | <p>I have seen several questions about exiting a script after a task is successfully completed, but is there a way to do the same for a script which has failed? I am writing a testing script which just checks that a camera is functioning correctly. If the first test fails it is more than likely that the following tests... | 4 | 2009-07-24T17:22:47Z | 1,179,060 | <p>You can raise exceptions to identify error conditions. Your top-level code can catch those exceptions and handle them appropriately. You can use <a href="http://docs.python.org/library/sys.html#sys.exit" rel="nofollow">sys.exit</a> to exit. E.g., in Python 2.x:</p>
<pre><code>import sys
class CameraInitializati... | 1 | 2009-07-24T17:36:29Z | [
"python",
"exception",
"exit"
] |
exit failed script run (python) | 1,178,989 | <p>I have seen several questions about exiting a script after a task is successfully completed, but is there a way to do the same for a script which has failed? I am writing a testing script which just checks that a camera is functioning correctly. If the first test fails it is more than likely that the following tests... | 4 | 2009-07-24T17:22:47Z | 1,180,611 | <p>You want to check the return code from the c++ program you are running, and exit if it indicates failure. In the code below, /bin/false and /bin/true are programs that exit with error and success codes, respectively. Replace them with your own program.</p>
<pre><code>import os
import sys
status = os.system('/bin/t... | 0 | 2009-07-24T23:10:33Z | [
"python",
"exception",
"exit"
] |
Suggestions for python assert function | 1,179,096 | <p>I'm using assert multiple times throughout multiple scripts, I was wondering if anyone has any suggestions on a better way to achieve this instead of the functions I have created below.</p>
<pre><code>def assert_validation(expected, actual, type='', message=''):
if type == '==':
assert expected == act... | 1 | 2009-07-24T17:42:33Z | 1,179,195 | <p>Well this is certainly shorter... can you really not just use <code>assert expected == actual</code> or whatever in the scripts themselves?</p>
<pre><code>def assert_validation(expected, actual, type='', message='', trans=(lambda x: x)):
m = { '==': (lambda e, a: e == a),
'!=': (lambda e, a: e != a),
... | 11 | 2009-07-24T17:58:11Z | [
"python",
"assert"
] |
Overriding inherited behavior | 1,179,213 | <p>I am using Multi-table inheritance for an object, and I need to limit the choices of the parent object foreign key references to only the rules that apply the child system.</p>
<pre><code>from schedule.models import Event, Rule
class AirShowRule(Rule):
"""
Inheritance of the schedule.Rule
"""
rule_... | 0 | 2009-07-24T18:00:58Z | 1,180,532 | <p>I looked into the structure of the classes listed, and you should add this:</p>
<pre><code>class AirShow(Event):
... your stuff...
rule = models.ForeignKey(AirShowRule, null = True, blank = True,
verbose_name="VERBOSE NAME", help_text="HELP TEXT")
</code></pre>
<p>that should get ... | 1 | 2009-07-24T22:39:51Z | [
"python",
"django-models"
] |
Expat parsing in python 3 | 1,179,305 | <pre><code>import xml.parsers.expat
def start_element(name, attrs):
print('Start element:', name, attrs)
def end_element(name):
print('End element:', name)
def character_data(data):
print('Character data: %s' % data)
parser = xml.parsers.expat.ParserCreate()
parser.StartElementHandler = start_element
pa... | 4 | 2009-07-24T18:19:40Z | 1,179,454 | <p>you need to open that file as binary:</p>
<pre><code>parser.ParseFile(open('sample.xml', 'rb'))
</code></pre>
| 7 | 2009-07-24T18:47:07Z | [
"python",
"python-3.x",
"python-2.6"
] |
Expat parsing in python 3 | 1,179,305 | <pre><code>import xml.parsers.expat
def start_element(name, attrs):
print('Start element:', name, attrs)
def end_element(name):
print('End element:', name)
def character_data(data):
print('Character data: %s' % data)
parser = xml.parsers.expat.ParserCreate()
parser.StartElementHandler = start_element
pa... | 4 | 2009-07-24T18:19:40Z | 27,694,193 | <p>I ran into this problem while trying to use the <a href="https://github.com/martinblech/xmltodict" rel="nofollow">xmltodict</a> module with Python 3. Under Python 2.7 I had no problems but under Python 3 I got this same error. The solution is the same that was suggested by @SilentGhost:</p>
<pre><code>import xmltod... | 1 | 2014-12-29T18:39:17Z | [
"python",
"python-3.x",
"python-2.6"
] |
What does keyword CONSTRAINT do in this CREATE TABLE statement | 1,179,352 | <p>I'm learning how to use sqlite3 with python. The example in the text book I am following is a database where each Country record has a Region, Country, and Population. </p>
<p>The book says:</p>
<blockquote>
<p>The following snippet uses the CONSTRAINT keyword to specify
that no two entries in the table being
... | 3 | 2009-07-24T18:28:44Z | 1,179,367 | <p>Country_key is simply giving a name to the constraint. If you do not do this the name will be generated for you. This is useful when there are several constraints on the table and you need to drop one of them.</p>
<p>As an example for dropping the constraint:</p>
<pre><code>ALTER TABLE PopByCountry DROP CONSTRAI... | 5 | 2009-07-24T18:31:15Z | [
"python",
"sql"
] |
What does keyword CONSTRAINT do in this CREATE TABLE statement | 1,179,352 | <p>I'm learning how to use sqlite3 with python. The example in the text book I am following is a database where each Country record has a Region, Country, and Population. </p>
<p>The book says:</p>
<blockquote>
<p>The following snippet uses the CONSTRAINT keyword to specify
that no two entries in the table being
... | 3 | 2009-07-24T18:28:44Z | 1,179,387 | <p>If you omit CONSTRAINT Contry_Key from the statement, SQL server will generate a name for your PRIMARY KEY constraint for you (the PRIMARY KEY is a type of constraint).</p>
<p>By specifically putting CONSTRAINT in the query you are essentially specifying a name for your primary key constraint.</p>
| 1 | 2009-07-24T18:35:11Z | [
"python",
"sql"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 1,180,127 | <p>You may have better luck breaking the problem down into converting PDF into an editable format, writing your changes, then converting it back into PDF. I don't know of a library that lets you directly edit PDF but there are plenty of converters between DOC and PDF for example.</p>
| 0 | 2009-07-24T21:03:21Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 1,180,167 | <p>Have you tried <a href="http://pybrary.net/pyPdf/" rel="nofollow">pyPdf</a> ?</p>
<p>Sorry, it doesnât have the ability to modify a pageâs content.</p>
| 0 | 2009-07-24T21:13:14Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 1,180,176 | <p>If you're on Windows, this might work:</p>
<p><a href="http://www.colorpilot.com/pdfcreatorpilotmanual/How_to_create_or_edit_PDF_with_Python_4.html" rel="nofollow">PDF Creator Pilot</a></p>
<p>There's also a whitepaper of a PDF creation and editing framework in Python. It's a little dated, but maybe can give you ... | 1 | 2009-07-24T21:14:54Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 2,180,841 | <p>I know this is an older post, but I spent a long time trying to find a solution. I came across a decent one using only ReportLab and PyPDF so I thought I'd share:</p>
<ol>
<li>read your PDF using PdfFileReader(), we'll call this <em>input</em></li>
<li>create a new pdf containing your text to add using ReportLab, ... | 56 | 2010-02-01T23:28:31Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 17,538,003 | <p>Here is a complete answer that I found elsewhere:</p>
<pre><code>from pyPdf import PdfFileWriter, PdfFileReader
import StringIO
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
packet = StringIO.StringIO()
# create a new PDF with Reportlab
can = canvas.Canvas(packet, pagesize=letter)
... | 42 | 2013-07-09T00:16:42Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 22,196,937 | <p><a href="https://github.com/coherentgraphics/cpdf-binaries" rel="nofollow">cpdf</a> will do the job from the command-line. It isn't python, though (afaik):</p>
<pre><code>cpdf -add-text "Line of text" input.pdf -o output .pdf
</code></pre>
| 1 | 2014-03-05T11:51:36Z | [
"python",
"pdf"
] |
Add text to Existing PDF using Python | 1,180,115 | <p><br>
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.</p>
<p>Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.</p>
<p>Thanks in advance.<br>
Richard.</p... | 50 | 2009-07-24T20:58:31Z | 31,353,531 | <p><a href="https://github.com/pmaupin/pdfrw/" rel="nofollow">pdfrw</a> will let you read in pages from an existing PDF and draw them to a reportlab canvas (similar to drawing an image). There are examples for this in the pdfrw <a href="https://github.com/pmaupin/pdfrw/tree/master/examples/rl1" rel="nofollow">examples... | 1 | 2015-07-11T04:47:00Z | [
"python",
"pdf"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,254 | <pre><code>sorted(myLists[key], key=mylists[key].get, reverse=True)
</code></pre>
<p>should save you some time, though not a lot.</p>
| 0 | 2009-07-24T21:30:02Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,255 | <p>Honestly, the best way is to not use Python. If performance is a major concern for this, use a faster language.</p>
| -4 | 2009-07-24T21:30:13Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,274 | <p>What you really want is an ordered container, instead of an unordered one. That would implicitly sort the results as they're inserted. The standard data structure for this is a tree.</p>
<p>However, there doesn't seem to be one of these in Python. I can't explain that; this is a core, fundamental data type in an... | 4 | 2009-07-24T21:34:45Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,275 | <p>If you have a fixed number of fields, use tuples instead of dictionaries. Place the field you want to sort on in first position, and just use <code>mylist.sort()</code></p>
| 1 | 2009-07-24T21:34:58Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,281 | <p>I would look into using a different sorting algorithm. Something like a Merge Sort might work. Break the list up into smaller lists and sort them individually. Then loop.</p>
<p>Pseudo code:</p>
<pre><code>list1 = [] // sorted separately
list2 = [] // sorted separately
// Recombine sorted lists
result = []
whil... | 0 | 2009-07-24T21:37:14Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,286 | <p>You may find this related answer from Guido: <a href="http://neopythonic.blogspot.com/2008/10/sorting-million-32-bit-integers-in-2mb.html">Sorting a million 32-bit integers in 2MB of RAM using Python</a></p>
| 12 | 2009-07-24T21:38:22Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,313 | <p>Others have provided some excellent advices, try them out. </p>
<p>As a general advice, in situations like that you need to profile your code. Know exactly where most of the time is spent. Bottlenecks hide well, in places you least expect them to be.<br>
If there is a lot of number crunching involved then a JIT com... | 1 | 2009-07-24T21:43:50Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,367 | <p>Glenn Maynard is correct that a sorted mapping would be appropriate here. This is one for python: <a href="http://wiki.zope.org/ZODB/guide/node6.html#SECTION000630000000000000000" rel="nofollow">http://wiki.zope.org/ZODB/guide/node6.html#SECTION000630000000000000000</a></p>
| 0 | 2009-07-24T21:54:18Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,373 | <p>This seems to be pretty fast.</p>
<pre><code>raw= [ {'id':'id1', 'hits':200, 'misses':300, 'total':400},
{'id':'id2', 'hits':300, 'misses':100, 'total':500},
{'id':'id3', 'hits':100, 'misses':400, 'total':600}
]
hits= [ (r['hits'],r['id']) for r in raw ]
hits.sort()
misses = [ (r['misses'],r['id']) for r ... | 1 | 2009-07-24T21:55:14Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,503 | <p>Instead of trying to keep your list ordered, maybe you can get by with a heap queue. It lets you push any item, keeping the 'smallest' one at <code>h[0]</code>, and popping this item (and 'bubbling' the next smallest) is an <code>O(nlogn)</code> operation.</p>
<p>so, just ask yourself: </p>
<ul>
<li><p>do i need ... | 1 | 2009-07-24T22:32:29Z | [
"python"
] |
Best way to sort 1M records in Python | 1,180,240 | <p>I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following</p>
<pre><code>myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.i... | 7 | 2009-07-24T21:25:24Z | 1,180,755 | <p>I've done some quick profiling of both the original way and SLott's proposal. In neither case does it take 5-10 minutes per field. The actual sorting is not the problem. It looks like most of the time is spent in slinging data around and transforming it. Also, my memory usage is skyrocketing - my python is over 3... | 0 | 2009-07-25T00:09:35Z | [
"python"
] |
Static vs instance methods of str in Python | 1,180,303 | <p>So, I have learnt that strings have a center method.</p>
<pre><code>>>> 'a'.center(3)
' a '
</code></pre>
<p>Then I have noticed that I can do the same thing using the 'str' object which is a type, since</p>
<pre><code>>>> type(str)
<type 'type'>
</code></pre>
<p>Using this 'type' object ... | 4 | 2009-07-24T21:41:32Z | 1,180,322 | <p>That's simply how classes in Python work:</p>
<pre><code>class C:
def method(self, arg):
print "In C.method, with", arg
o = C()
o.method(1)
C.method(o, 1)
# Prints:
# In C.method, with 1
# In C.method, with 1
</code></pre>
<p>When you say <code>o.method(1)</code> you can think of it as a shorthand for... | 15 | 2009-07-24T21:45:16Z | [
"python",
"string"
] |
Static vs instance methods of str in Python | 1,180,303 | <p>So, I have learnt that strings have a center method.</p>
<pre><code>>>> 'a'.center(3)
' a '
</code></pre>
<p>Then I have noticed that I can do the same thing using the 'str' object which is a type, since</p>
<pre><code>>>> type(str)
<type 'type'>
</code></pre>
<p>Using this 'type' object ... | 4 | 2009-07-24T21:41:32Z | 1,180,356 | <p>To expand on RichieHindle's answer:</p>
<p>In Python, all methods on a class idiomatically take a "self" parameter. For example:</p>
<pre><code>def method(self, arg): pass
</code></pre>
<p>That "self" argument tells Python what instance of the class the method is being called on. When you call a method on a clas... | 4 | 2009-07-24T21:53:02Z | [
"python",
"string"
] |
Static vs instance methods of str in Python | 1,180,303 | <p>So, I have learnt that strings have a center method.</p>
<pre><code>>>> 'a'.center(3)
' a '
</code></pre>
<p>Then I have noticed that I can do the same thing using the 'str' object which is a type, since</p>
<pre><code>>>> type(str)
<type 'type'>
</code></pre>
<p>Using this 'type' object ... | 4 | 2009-07-24T21:41:32Z | 1,180,424 | <blockquote>
<p>There should be one-- and preferably only one --obvious way to do it.</p>
</blockquote>
<p>Philosophically speaking, there <em>is</em> only one obvious way to do it: 'a'.center(3). The fact that there is an unobvious way of calling any method (i.e. the well-explained-by-previous-commentors o.method(x... | 8 | 2009-07-24T22:07:39Z | [
"python",
"string"
] |
Static vs instance methods of str in Python | 1,180,303 | <p>So, I have learnt that strings have a center method.</p>
<pre><code>>>> 'a'.center(3)
' a '
</code></pre>
<p>Then I have noticed that I can do the same thing using the 'str' object which is a type, since</p>
<pre><code>>>> type(str)
<type 'type'>
</code></pre>
<p>Using this 'type' object ... | 4 | 2009-07-24T21:41:32Z | 1,181,460 | <p>Method descriptor is a normal class with <code>__get__</code>, <code>__set__</code> and <code>__del__</code> methods.</p>
<p>When, e.g., <code>__get__</code> is called, it is passed 2 or 3 arguments:</p>
<ul>
<li><code>self</code>, which is the descriptor class itself,</li>
<li><code>inst</code>, which is the call... | 1 | 2009-07-25T07:14:39Z | [
"python",
"string"
] |
Static vs instance methods of str in Python | 1,180,303 | <p>So, I have learnt that strings have a center method.</p>
<pre><code>>>> 'a'.center(3)
' a '
</code></pre>
<p>Then I have noticed that I can do the same thing using the 'str' object which is a type, since</p>
<pre><code>>>> type(str)
<type 'type'>
</code></pre>
<p>Using this 'type' object ... | 4 | 2009-07-24T21:41:32Z | 1,182,880 | <pre><code>'a'.center(3) == str.center('a',3)
</code></pre>
<p>There <em>is</em> only one way to do it.</p>
| 2 | 2009-07-25T19:44:33Z | [
"python",
"string"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 1,180,665 | <p>Right now, you can do what I do, which is kludgy but works perfectly well* (this usage assumes you're using virtualenvwrapper -- which you should be -- but you can easily substitute in the rather longer 'source' call you mentioned, if not):</p>
<pre><code>def task():
workon = 'workon myvenv && '
run... | 91 | 2009-07-24T23:32:09Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 3,403,558 | <p>I'm just using a simple wrapper function virtualenv() that can be called instead of run(). It doesn't use the cd context manager, so relative paths can be used.</p>
<pre><code>def virtualenv(command):
"""
Run a command in the virtualenv. This prefixes the command with the source
command.
Usage:
... | 17 | 2010-08-04T07:48:49Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 5,359,988 | <p>As an update to bitprophet's forecast: With Fabric 1.0 you can make use of prefix() and your own context managers.</p>
<pre><code>from __future__ import with_statement
from fabric.api import *
from contextlib import contextmanager as _contextmanager
env.hosts = ['servername']
env.user = 'deploy'
env.keyfile = ['$H... | 122 | 2011-03-19T04:06:46Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 18,397,479 | <p><code>virtualenvwrapper</code> can make this a little simpler</p>
<ol>
<li><p>Using @nh2's approach (this approach also works when using <code>local</code>, but only for virtualenvwrapper installations where <code>workon</code> is in <code>$PATH</code>, in other words -- Windows)</p>
<pre><code>from contextlib imp... | 7 | 2013-08-23T07:45:03Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 18,718,250 | <p>This is my approach on using <code>virtualenv</code> with local deployments.</p>
<p>Using fabric's <a href="http://docs.fabfile.org/en/1.7/api/core/context_managers.html?highlight=path#fabric.context_managers.path">path()</a> context manager you can run <code>pip</code> or <code>python</code> with binaries from vir... | 6 | 2013-09-10T11:51:45Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 24,461,747 | <p>Here is code for a decorator that will result in the use of Virtual Environment for any run/sudo calls:</p>
<pre><code># This is the bash code to update the $PATH as activate does
UPDATE_PYTHON_PATH = r'PATH="{}:$PATH"'.format(VIRTUAL_ENV_BIN_DIR)
def with_venv(func, *args, **kwargs):
"Use Virtual Environment fo... | 0 | 2014-06-27T22:38:03Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
Activate a virtualenv via fabric as deploy user | 1,180,411 | <p>I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.</p>
<pre><code>def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
... | 115 | 2009-07-24T22:03:57Z | 25,707,904 | <p>Thanks to all answers posted and I would like to add one more alternative for this. There is an module, <a href="https://pypi.python.org/pypi/fabric-virtualenv/" rel="nofollow">fabric-virtualenv</a>, which can provide the function as the same code:</p>
<pre><code>>>> from fabvenv import virtualenv
>>... | 3 | 2014-09-07T07:02:36Z | [
"python",
"virtualenv",
"fabric",
"automated-deploy"
] |
How to set LANG variable in Windows? | 1,180,590 | <p>I'm making an application that supports multi language. And I am using <code>gettext</code> and <code>locale</code> to solve this issue. </p>
<p>How to set LANG variable in Windows? In Linux and Unix-like systems it's just as simple as</p>
<p><code>$ LANG=en_US python appname.py</code></p>
<p>And it will automat... | 0 | 2009-07-24T23:01:14Z | 1,180,593 | <p>Windows locale support doesn't rely on LANG variable (or, indeed, any other environmental variable). It is whatever the user set it to in Control Panel.</p>
| 3 | 2009-07-24T23:02:38Z | [
"python",
"windows",
"locale"
] |
How to set LANG variable in Windows? | 1,180,590 | <p>I'm making an application that supports multi language. And I am using <code>gettext</code> and <code>locale</code> to solve this issue. </p>
<p>How to set LANG variable in Windows? In Linux and Unix-like systems it's just as simple as</p>
<p><code>$ LANG=en_US python appname.py</code></p>
<p>And it will automat... | 0 | 2009-07-24T23:01:14Z | 6,734,439 | <p>you can use a batch file like in here: <a href="http://www.geany.org/Documentation/FAQ#QQuestions11" rel="nofollow">http://www.geany.org/Documentation/FAQ#QQuestions11</a> </p>
<pre><code>set LANG=en_US
something.exe
</code></pre>
<p>or set it through the control panel / system / advanced system settings / advance... | 2 | 2011-07-18T14:25:52Z | [
"python",
"windows",
"locale"
] |
Python Popen difficulties: File not found | 1,180,592 | <p>I'm trying to use python to run a program.</p>
<pre><code>from subprocess import Popen
sa_proc = Popen(['C:\\sa\\sa.exe','--?'])
</code></pre>
<p>Running this small snippit gives the error:</p>
<blockquote>
<p>WindowsError: [Error 2] The system cannot find the file specified</p>
</blockquote>
<p>The program e... | 1 | 2009-07-24T23:02:08Z | 1,180,654 | <p>You may not have permission to execute C:\sa\sa.exe. Have you tried running the program manually?</p>
| 0 | 2009-07-24T23:28:47Z | [
"python",
"subprocess",
"popen"
] |
Python Popen difficulties: File not found | 1,180,592 | <p>I'm trying to use python to run a program.</p>
<pre><code>from subprocess import Popen
sa_proc = Popen(['C:\\sa\\sa.exe','--?'])
</code></pre>
<p>Running this small snippit gives the error:</p>
<blockquote>
<p>WindowsError: [Error 2] The system cannot find the file specified</p>
</blockquote>
<p>The program e... | 1 | 2009-07-24T23:02:08Z | 1,181,026 | <p>As <a href="http://docs.python.org/library/subprocess.html?highlight=subprocess#subprocess.Popen">the docs</a> say, "On Windows: the Popen class uses CreateProcess() to execute the child program, which operates on strings. If args is a sequence, it will be converted to a string using the list2cmdline() method.". Ma... | 5 | 2009-07-25T02:36:58Z | [
"python",
"subprocess",
"popen"
] |
Using subprocess.Popen for Process with Large Output | 1,180,606 | <p>I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:</p>
<pre><code>p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmes... | 20 | 2009-07-24T23:08:07Z | 1,180,632 | <p><em>A lot of output</em> is subjective so it's a little difficult to make a recommendation. If the amount of output is <em>really</em> large then you likely don't want to grab it all with a single read() call anyway. You may want to try writing the output to a file and then pull the data in incrementally like such... | 6 | 2009-07-24T23:18:34Z | [
"python",
"subprocess"
] |
Using subprocess.Popen for Process with Large Output | 1,180,606 | <p>I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:</p>
<pre><code>p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmes... | 20 | 2009-07-24T23:08:07Z | 1,180,641 | <p>You're doing blocking reads to two files; the first needs to complete before the second starts. If the application writes a lot to stderr, and nothing to stdout, then your process will sit waiting for data on stdout that isn't coming, while the program you're running sits there waiting for the stuff it wrote to std... | 13 | 2009-07-24T23:23:35Z | [
"python",
"subprocess"
] |
Using subprocess.Popen for Process with Large Output | 1,180,606 | <p>I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:</p>
<pre><code>p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmes... | 20 | 2009-07-24T23:08:07Z | 1,180,642 | <p>You could try communicate and see if that solves your problem. If not, I'd redirect the output to a temporary file.</p>
| 2 | 2009-07-24T23:24:10Z | [
"python",
"subprocess"
] |
Using subprocess.Popen for Process with Large Output | 1,180,606 | <p>I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:</p>
<pre><code>p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmes... | 20 | 2009-07-24T23:08:07Z | 1,182,810 | <p>Glenn Maynard is right in his comment about deadlocks. However, the best way of solving this problem is two create two threads, one for stdout and one for stderr, which read those respective streams until exhausted and do whatever you need with the output.</p>
<p>The suggestion of using temporary files may or may n... | 6 | 2009-07-25T19:14:53Z | [
"python",
"subprocess"
] |
Using subprocess.Popen for Process with Large Output | 1,180,606 | <p>I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:</p>
<pre><code>p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmes... | 20 | 2009-07-24T23:08:07Z | 24,943,368 | <p>I had the same problem. If you have to handle a large output, another good option could be to use a file for stdout and stderr, and pass those files per parameter.</p>
<p>Check the tempfile module in python: <a href="https://docs.python.org/2/library/tempfile.html" rel="nofollow">https://docs.python.org/2/library/t... | 0 | 2014-07-24T20:28:30Z | [
"python",
"subprocess"
] |
Python error: int argument required | 1,180,673 | <p>What am I doing wrong here?</p>
<pre><code> i = 0
cursor.execute("insert into core_room (order) values (%i)", (int(i))
</code></pre>
<p>Error:</p>
<pre><code> int argument required
</code></pre>
<p>The database field is an int(11), but I think the %i is generating the error.</p>
<p><strong>Update:</strong></p>... | 0 | 2009-07-24T23:35:04Z | 1,180,681 | <p>Two things. First, use <code>%s</code> and not <code>%i</code>. Second, parameters must be in a tuple - so you need <code>(i,)</code> (with comma after <code>i</code>).</p>
<p>Also, <code>ORDER</code> is a keyword, and should be escaped if you're using it as field name.</p>
| 4 | 2009-07-24T23:39:41Z | [
"python",
"mysql",
"mysql-error-1064"
] |
Python error: int argument required | 1,180,673 | <p>What am I doing wrong here?</p>
<pre><code> i = 0
cursor.execute("insert into core_room (order) values (%i)", (int(i))
</code></pre>
<p>Error:</p>
<pre><code> int argument required
</code></pre>
<p>The database field is an int(11), but I think the %i is generating the error.</p>
<p><strong>Update:</strong></p>... | 0 | 2009-07-24T23:35:04Z | 1,180,687 | <p>I believe the second argument to execute() is expected to be an iterable. IF this is the case you need to change:</p>
<pre><code>(int(i))
</code></pre>
<p>to:</p>
<pre><code>(int(i),)
</code></pre>
<p>to make it into a tuple.</p>
| 1 | 2009-07-24T23:40:22Z | [
"python",
"mysql",
"mysql-error-1064"
] |
Python error: int argument required | 1,180,673 | <p>What am I doing wrong here?</p>
<pre><code> i = 0
cursor.execute("insert into core_room (order) values (%i)", (int(i))
</code></pre>
<p>Error:</p>
<pre><code> int argument required
</code></pre>
<p>The database field is an int(11), but I think the %i is generating the error.</p>
<p><strong>Update:</strong></p>... | 0 | 2009-07-24T23:35:04Z | 1,180,690 | <p>You should be using <code>?</code> instead of <code>%i</code> probably. And you're missing a parenthesis.</p>
<pre><code>cursor.execute("insert into core_room (order) values (?)", (int(i),))
</code></pre>
| 1 | 2009-07-24T23:41:12Z | [
"python",
"mysql",
"mysql-error-1064"
] |
one liner for conditionally replacing dictionary values | 1,180,846 | <p>Is there a better way to express this using list comprehension? Or any other way of expressing this in one line?</p>
<p>I want to replace each value in the original dictionary with a corresponding value in the col dictionary, or leave it unchanged if its not in the col dictionary.</p>
<pre><code>col = {'1':3.5, '6... | 0 | 2009-07-25T01:00:20Z | 1,180,886 | <p>I believe <a href="http://docs.python.org/library/stdtypes.html#dict.update" rel="nofollow"><code>update</code></a> is what you want.</p>
<blockquote>
<p>update([other])</p>
<p>Update the dictionary with the key/value pairs from other, overwriting existing keys.
Return None.</p>
</blockquote>
<p><strong>C... | 2 | 2009-07-25T01:17:34Z | [
"python",
"refactoring",
"dictionary",
"list-comprehension"
] |
Composite pattern for GTD app | 1,180,876 | <p>This is a continuation of <a href="http://stackoverflow.com/questions/1175110/python-classes-for-simple-gtd-app" rel="nofollow" title="one of my previous questions">one of my previous questions</a></p>
<p>Here are my classes.</p>
<pre><code>#Project class
class Project:
def __init__(self, name, children=[... | 3 | 2009-07-25T01:10:46Z | 1,180,901 | <p>The problem is with your initialization of Projects:</p>
<pre><code> __init__(self, name, children=[]):
</code></pre>
<p>You only get one list, which is shared by all Projects you create without passing a value for children. See <a href="http://effbot.org/zone/default-values.htm">here</a> for an explanation. Yo... | 5 | 2009-07-25T01:29:29Z | [
"python",
"design",
"recursion",
"composite",
"gtd"
] |
Spoofing the origination IP address of an HTTP request | 1,180,878 | <p>This only needs to work on a single subnet and is not for malicious use. </p>
<p>I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performanc... | 19 | 2009-07-25T01:11:24Z | 1,180,884 | <p>You want to set the source address used for the connection. Googling "urllib2 source address" gives <a href="http://bugs.python.org/file9988/urllib2_util.py">http://bugs.python.org/file9988/urllib2_util.py</a>. I havn't tried it.</p>
<p>The system you're running on needs to be configured with the IPs you're testi... | 5 | 2009-07-25T01:15:44Z | [
"python",
"http",
"networking",
"sockets",
"urllib2"
] |
Spoofing the origination IP address of an HTTP request | 1,180,878 | <p>This only needs to work on a single subnet and is not for malicious use. </p>
<p>I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performanc... | 19 | 2009-07-25T01:11:24Z | 1,180,897 | <p>Quick note, as I just learned this yesterday:</p>
<p>I think you've implied you know this already, but any responses to an HTTP request go to the IP address that shows up in the header. So if you are wanting to see those responses, you need to have control of the router and have it set up so that the spoofed IPs ar... | 4 | 2009-07-25T01:27:55Z | [
"python",
"http",
"networking",
"sockets",
"urllib2"
] |
Spoofing the origination IP address of an HTTP request | 1,180,878 | <p>This only needs to work on a single subnet and is not for malicious use. </p>
<p>I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performanc... | 19 | 2009-07-25T01:11:24Z | 1,180,938 | <p>This is a misunderstanding of HTTP. The HTTP protocol is based on top of <a href="http://en.wikipedia.org/wiki/Transmission%5FControl%5FProtocol">TCP</a>. The TCP protocol relies on a 3 way handshake to initialize requests.</p>
<p><img src="http://upload.wikimedia.org/wikipedia/commons/archive/c/c7/20051221162333!3... | 40 | 2009-07-25T01:46:29Z | [
"python",
"http",
"networking",
"sockets",
"urllib2"
] |
Spoofing the origination IP address of an HTTP request | 1,180,878 | <p>This only needs to work on a single subnet and is not for malicious use. </p>
<p>I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performanc... | 19 | 2009-07-25T01:11:24Z | 1,181,059 | <p>You could just use IP aliasing on a Linux box and set up as many IP addresses as you want. The catch is that you can't predict what IP will get stamped in the the IP header unless you set it to another network and set an explicit route for that network. i.e. -</p>
<pre><code>current client address on eth0 = 192.168... | 1 | 2009-07-25T02:50:19Z | [
"python",
"http",
"networking",
"sockets",
"urllib2"
] |
Spoofing the origination IP address of an HTTP request | 1,180,878 | <p>This only needs to work on a single subnet and is not for malicious use. </p>
<p>I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performanc... | 19 | 2009-07-25T01:11:24Z | 1,186,102 | <p>I suggest seeing if you can configure your load balancer to make it's decision based on the X-Forwarded-For header, rather than the source IP of the packet containing the HTTP request. I know that most of the significant commercial load balancers have this capability.</p>
<p>If you can't do that, then I suggest th... | 1 | 2009-07-27T01:46:10Z | [
"python",
"http",
"networking",
"sockets",
"urllib2"
] |
How can you check if a key is currently pressed using Tkinter in Python? | 1,181,027 | <p>Is there any way to detect which keys are currently pressed using Tkinter? I don't want to have to use extra libraries if possible. I can already detect when keys are pressed, but I want to be able to check at any time what keys are pressed down at the moment.</p>
| 1 | 2009-07-25T02:38:56Z | 1,181,037 | <p>I think you need to keep track of events about keys getting pressed <em>and released</em> (maintaining your own set of "currently pressed" keys) -- I believe Tk doesn't keep track of that for you (and Tkinter really adds little on top of Tk, it's mostly a direct interface to it).</p>
| 3 | 2009-07-25T02:43:00Z | [
"python",
"tkinter",
"keylistener"
] |
How can I serve unbuffered CGI content from Apache 2? | 1,181,135 | <p>I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server r... | 6 | 2009-07-25T03:42:05Z | 1,181,176 | <p>According to <a href="http://search.cpan.org/~lds/CGI.pm-3.43/CGI/Push.pm" rel="nofollow">CGI::Push</a>,</p>
<blockquote>
<p>Apache web server from version 1.3b2
on does not need server push scripts
installed as NPH scripts: the -nph
parameter to do_push() may be set to a
false value to disable the extra
... | 1 | 2009-07-25T04:11:12Z | [
"python",
"perl",
"apache2",
"cgi"
] |
How can I serve unbuffered CGI content from Apache 2? | 1,181,135 | <p>I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server r... | 6 | 2009-07-25T03:42:05Z | 1,181,248 | <p>Flushing STDOUT can help. For example, the following Perl program should work as intended:</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
local $| = 1;
print "Content-type: text/plain\n\n";
for ( my $i = 1 ; $i <= 10 ; $i++ ) {
print "$i\n";
sleep(1);
}
print "Done.";
</code></pre>
| 1 | 2009-07-25T04:56:24Z | [
"python",
"perl",
"apache2",
"cgi"
] |
How can I serve unbuffered CGI content from Apache 2? | 1,181,135 | <p>I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server r... | 6 | 2009-07-25T03:42:05Z | 1,181,959 | <p>Randal Schwartz's article <a href="http://www.stonehenge.com/merlyn/LinuxMag/col39.html" rel="nofollow">Watching long processes through CGI</a> explains a different (and IMHO, better) way of watching a long running process.</p>
| 4 | 2009-07-25T11:56:47Z | [
"python",
"perl",
"apache2",
"cgi"
] |
How can I serve unbuffered CGI content from Apache 2? | 1,181,135 | <p>I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server r... | 6 | 2009-07-25T03:42:05Z | 4,176,941 | <p>You must put your push script into a special directory wich contain a special .htaccess
with this environnment specs:</p>
<pre><code>Options +ExecCGI
AddHandler cgi-script .cgi .sh .pl .py
SetEnvIfNoCase Content-Type \
"^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
SetEnv no-gzip dont-v... | 2 | 2010-11-14T09:37:25Z | [
"python",
"perl",
"apache2",
"cgi"
] |
Why isn't Django returning a datetime field from the database? | 1,181,145 | <p>For my first Django app, I'm trying to write a simple quote collection site (think bash.org), with really simple functionality, just to get my feet wet. I'm using sqlite as my database, since it's the easiest to setup.</p>
<p>Here's my only model right now:</p>
<pre><code>class Quote(models.Model):
text = mod... | 2 | 2009-07-25T03:50:28Z | 1,181,150 | <p>I'm not sure what you're doing with that <code>date:</code> filter -- what happens if you replace it with something simple, such as <code>date:"D d M Y</code>?</p>
| 0 | 2009-07-25T03:54:56Z | [
"python",
"django",
"datetime",
"sqlite"
] |
Why isn't Django returning a datetime field from the database? | 1,181,145 | <p>For my first Django app, I'm trying to write a simple quote collection site (think bash.org), with really simple functionality, just to get my feet wet. I'm using sqlite as my database, since it's the easiest to setup.</p>
<p>Here's my only model right now:</p>
<pre><code>class Quote(models.Model):
text = mod... | 2 | 2009-07-25T03:50:28Z | 1,181,203 | <p>As Adam Bernier mentioned, you're misspelling <code>quote</code></p>
| 2 | 2009-07-25T04:28:00Z | [
"python",
"django",
"datetime",
"sqlite"
] |
Why isn't Django returning a datetime field from the database? | 1,181,145 | <p>For my first Django app, I'm trying to write a simple quote collection site (think bash.org), with really simple functionality, just to get my feet wet. I'm using sqlite as my database, since it's the easiest to setup.</p>
<p>Here's my only model right now:</p>
<pre><code>class Quote(models.Model):
text = mod... | 2 | 2009-07-25T03:50:28Z | 1,183,105 | <p>I believe that django.views.generic.list_detail.object_detail <a href="http://docs.djangoproject.com/en/dev/intro/tutorial04/" rel="nofollow">uses a variable named object_id, not id</a>.</p>
<pre><code> urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
... | 0 | 2009-07-25T21:23:45Z | [
"python",
"django",
"datetime",
"sqlite"
] |
emulating LiveHTTPheader in server side script or javascript? | 1,181,233 | <p>I ran into this problem when scraping sites with heavy usage of javascript to obfuscate it's data.</p>
<p>For example,</p>
<p>"a href="javascript:void(0)" onClick="grabData(23)"> VIEW DETAILS </p>
<p>This href attribute, reveals no information about the actual URL. You'd have to manually look and examine the grab... | 0 | 2009-07-25T04:49:09Z | 1,181,238 | <p>I'm not sure I understand the question but...</p>
<p>In PHP, incoming POST parameters are stored in the <code>$_POST</code> array, you can display them with <code>print_r($_POST);</code>.</p>
| 1 | 2009-07-25T04:51:43Z | [
"php",
"jquery",
"python"
] |
dynamic plotting in wxpython | 1,181,391 | <p>I have been developing a GUI for reading continuous data from a serial port. After reading the data, some calculations are made and the results will be plotted and refreshed (aka dynamic plotting). I use the wx backend provided in the matplotlib for this purposes. To do this, I basically use an array to store my res... | 2 | 2009-07-25T06:29:50Z | 1,181,433 | <blockquote>
<p>To do this, I basically use an array
to store my results, in which I keep
appending it to</p>
</blockquote>
<p>Try limiting the size of this array, either by deleting old data or by deleting every n-th entry (the screen resolution will prevent all entries to be displayed anyway). I assume you wri... | 3 | 2009-07-25T07:01:02Z | [
"python",
"wxpython",
"matplotlib"
] |
dynamic plotting in wxpython | 1,181,391 | <p>I have been developing a GUI for reading continuous data from a serial port. After reading the data, some calculations are made and the results will be plotted and refreshed (aka dynamic plotting). I use the wx backend provided in the matplotlib for this purposes. To do this, I basically use an array to store my res... | 2 | 2009-07-25T06:29:50Z | 1,181,968 | <p>I have created such a component with pythons Tkinter. The source is <a href="http://code.google.com/p/asuro-syd/source/browse/lib/pysyd/SydPlot.py" rel="nofollow">here</a>. </p>
<p>Basically, you have to keep the plotted data <em>somewhere</em>. You cannot keep an infinite amount of data points in memory, so you ei... | 1 | 2009-07-25T12:00:36Z | [
"python",
"wxpython",
"matplotlib"
] |
dynamic plotting in wxpython | 1,181,391 | <p>I have been developing a GUI for reading continuous data from a serial port. After reading the data, some calculations are made and the results will be plotted and refreshed (aka dynamic plotting). I use the wx backend provided in the matplotlib for this purposes. To do this, I basically use an array to store my res... | 2 | 2009-07-25T06:29:50Z | 1,182,006 | <p>Data and representation of data are two different things. You might want to store your data to disk if it's important data to be analyzed later, but only keep a fixed period of time or the last N points for display purposes. You could even let the user pick the time frame to be displayed. </p>
| 1 | 2009-07-25T12:23:40Z | [
"python",
"wxpython",
"matplotlib"
] |
dynamic plotting in wxpython | 1,181,391 | <p>I have been developing a GUI for reading continuous data from a serial port. After reading the data, some calculations are made and the results will be plotted and refreshed (aka dynamic plotting). I use the wx backend provided in the matplotlib for this purposes. To do this, I basically use an array to store my res... | 2 | 2009-07-25T06:29:50Z | 7,823,652 | <p>I actually ran into this problem (more of a mental block, actually...).</p>
<p>First of all I copy-pasted some wx Plot code from <a href="http://wiki.wxpython.org/Using%20wxPython%20Demo%20Code" rel="nofollow">wx Demo Code</a>. </p>
<p>What I do is keep a live log of a value, and compare it to two markers (min and... | 0 | 2011-10-19T15:19:34Z | [
"python",
"wxpython",
"matplotlib"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,181,468 | <p>Here's two possibilities:</p>
<ol>
<li>Perhaps the C++ code is already written & available for use. </li>
<li>It's likely the C++ code is faster/smaller than equivalent Python</li>
</ol>
| 3 | 2009-07-25T07:19:34Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,181,475 | <p>It depends on your point of view:</p>
<p><strong>Calling C++ code from a python application</strong></p>
<p>You generally want to do this when performance is an issue. Highly dynamic languages like python are typically somewhat slower then native code such as C++. "Features" of C++ such as manual memory management... | 21 | 2009-07-25T07:24:16Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,181,476 | <p>Generally, you'd call C++ from python in order to use an existing library or other functionality. Often someone else has written a set of functions that make your life easier, and calling compiled C code is easier than re-writing the library in python.</p>
<p>The other reason is for performance purposes. Often, spe... | 5 | 2009-07-25T07:25:08Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,181,481 | <p>Because C++ provides a direct way of calling OS services, and (if used in a careful way) can produce code that is more efficient in memory and time, whereas Python is a high-level language, and is less painful to use in those situations where utter efficiency isn't a concern and where you already have libraries givi... | 3 | 2009-07-25T07:28:47Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,181,567 | <ol>
<li>Performance :</li>
</ol>
<p>From my limited experience, Python is about 10 times slower than using C.
Using Psyco will dramatically improve it, but still about 5 times slower than C.
BUT, calling c module from python is only a little faster than Psyco.</p>
<ol>
<li>When you have some libraries in C.<br />
Fo... | 0 | 2009-07-25T08:14:46Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,182,051 | <p>One nice thing about using a scripting language is that you can reload new code into the application without quitting the app, then making changes, recompile, and then relaunching the app. When people talk about quicker development times, some of that refers to this capability.
A downside of using a scripting langu... | 0 | 2009-07-25T12:54:35Z | [
"c++",
"python"
] |
Practical point of view: Why would I want to use Python with C++? | 1,181,462 | <p>I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python?</p>
<p>I'd appreciate a simple example - Boost::Python will do</p>
| 4 | 2009-07-25T07:14:52Z | 1,182,301 | <p>Here's a real-life example: I've written a DLL in C to interface with some custom hardware for work. Then for the very first stage of testing, I was writing short programs in C to verify that the different commands were working properly. The process of write, compile, run took probably 3-5 times as long as when I... | 2 | 2009-07-25T15:23:09Z | [
"c++",
"python"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 1,181,517 | <p><a href="http://danielbaggio.blogspot.com/2009/03/python-mouse-move-in-5-lines-of-code.html" rel="nofollow">http://danielbaggio.blogspot.com/2009/03/python-mouse-move-in-5-lines-of-code.html</a></p>
<pre><code>from Xlib import X, display
d = display.Display()
s = d.screen()
root = s.root
root.warp_pointer(300,300)
... | 7 | 2009-07-25T07:43:37Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 1,181,538 | <p>Tested on WinXP, Python 2.6 after installing <a href="http://sourceforge.net/projects/pywin32/files/">pywin32</a> (pywin32-214.win32-py2.6.exe in my case):</p>
<pre><code>import win32api, win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
wi... | 193 | 2009-07-25T07:57:19Z | [
"python",
"mouse"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.