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
Installing Mercurial on Mac OS X 10.6 Snow Leopard
1,461,374
<h1>Installing Mercurial on Mac OS X 10.6 Snow Leopard</h1> <p>I installed Mercurial 1.3.1 on Mac OS X 10.6 Snow Leopard from source using the following:</p> <pre><code>cd ~/src curl -O http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz tar -xzvf mercurial-1.3.1.tar.gz cd mercurial-1.3.1 make all sudo make i...
13
2009-09-22T17:13:09Z
1,490,705
<p>Install mercurial - or any Python package in general - into your user home directory. Thus you can access them from any Python (of same version) or any virtualenv. See <a href="http://www.python.org/dev/peps/pep-0370/" rel="nofollow">PEP 370</a> for details.</p> <pre><code>$ cd mercurial-x.y.z/ $ python2.6 setup.py...
7
2009-09-29T05:28:44Z
[ "python", "osx", "mercurial", "osx-snow-leopard" ]
Installing Mercurial on Mac OS X 10.6 Snow Leopard
1,461,374
<h1>Installing Mercurial on Mac OS X 10.6 Snow Leopard</h1> <p>I installed Mercurial 1.3.1 on Mac OS X 10.6 Snow Leopard from source using the following:</p> <pre><code>cd ~/src curl -O http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz tar -xzvf mercurial-1.3.1.tar.gz cd mercurial-1.3.1 make all sudo make i...
13
2009-09-22T17:13:09Z
1,958,044
<p>as suggested by Sridhar, macports works fine on multiple architecture and versions of MacOsX + allows updates and more:</p> <pre><code>$ port variants mercurial mercurial has the variants: bash_completion: Completion support for bash zsh_completion: Install mercurial zsh completion file $ </code></pre> <p>so...
5
2009-12-24T11:47:24Z
[ "python", "osx", "mercurial", "osx-snow-leopard" ]
Installing Mercurial on Mac OS X 10.6 Snow Leopard
1,461,374
<h1>Installing Mercurial on Mac OS X 10.6 Snow Leopard</h1> <p>I installed Mercurial 1.3.1 on Mac OS X 10.6 Snow Leopard from source using the following:</p> <pre><code>cd ~/src curl -O http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz tar -xzvf mercurial-1.3.1.tar.gz cd mercurial-1.3.1 make all sudo make i...
13
2009-09-22T17:13:09Z
2,565,094
<p>Why need to use macports? python <code>easy_install</code> is the easiest way and error free:</p> <pre><code>easy_install -U mercurial </code></pre> <p><em>It's just a simple gold bullet, all the time.</em></p>
13
2010-04-02T05:11:21Z
[ "python", "osx", "mercurial", "osx-snow-leopard" ]
Installing Mercurial on Mac OS X 10.6 Snow Leopard
1,461,374
<h1>Installing Mercurial on Mac OS X 10.6 Snow Leopard</h1> <p>I installed Mercurial 1.3.1 on Mac OS X 10.6 Snow Leopard from source using the following:</p> <pre><code>cd ~/src curl -O http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz tar -xzvf mercurial-1.3.1.tar.gz cd mercurial-1.3.1 make all sudo make i...
13
2009-09-22T17:13:09Z
2,762,342
<p>All those answers look complicated to the average mac OS X users, because they are specific to other install platforms. As of now the Mercurial website offers an installer package (compressed as a zip file).</p>
1
2010-05-04T01:52:07Z
[ "python", "osx", "mercurial", "osx-snow-leopard" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,461,413
<p>In python lists are objects :) So no type mismatch</p>
0
2009-09-22T17:20:34Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,461,415
<p>If you are going to be returning iterators sometimes, and single objects on others, I'd say return always an iterator, so you don't have to think about it. </p> <p>Generaly, you would use that function in a context that expects an iterator, so if you'd have to check if it where a list to iterate or an object to do ...
11
2009-09-22T17:21:40Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,461,697
<p>The only situation where I would do this is with a parameterized function or method, where one or more of the parameters the caller gives determines the type returned; for example, a "factory" function that returns one of a logically similar family of objects:</p> <pre><code>newCharacter = characterFactory("human",...
1
2009-09-22T18:10:56Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,461,847
<p>In general, I would have to say that returning two different types is bad practice.</p> <p>Imagine the next developer coming to read and maintain your code. At first he/she will read a method using your function and think "Ah, read() returns a single item." </p> <p>Later they will see code treating read()'s result...
2
2009-09-22T18:36:02Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,462,139
<p>It may not be a matter of "pythonic" but rather a matter of "good design". If you returnd different things <em>AND</em> nobody has to do typechecks on them, then it's probably okay. That's polymorphism for you. OTOH, if the caller has to "pierce the veil" then you have a design problem, known as a violation of the...
1
2009-09-22T19:35:16Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,462,353
<p>I would have read(<em>integer</em>) and read_list(<em>iterable</em>).</p> <p>That way you could do read(10) and get back a single result and read_list([5, 5, 10, 5]) and get back a list of results. This is both more flexible and explicit.</p>
1
2009-09-22T20:21:38Z
[ "python", "return-value" ]
Is it Pythonic for a function to return an iterable or non-iterable depending on its input?
1,461,392
<p>(Title and contents updated after reading Alex's answer)</p> <p>In general I believe that it's considered bad form (un-Pythonic) for a function to sometimes return an iterable and sometimes a single item depending on its parameters.</p> <p>For example <code>struct.unpack</code> always returns a tuple even if it co...
6
2009-09-22T17:16:57Z
1,463,749
<p>Returning either a single object, or an iterable of objects, depending on arguments, is definitely hard to deal with. But the question in your title is much more general and the assertion that the standard library's function avoid (or "mostly avoid") returning different types based on the argument(s) is quite incorr...
2
2009-09-23T03:00:41Z
[ "python", "return-value" ]
Jinja2 If Statement
1,461,484
<p>The code below is a sample form I'm using to learn jinja2. As written, it returns an error saying that it doesn't recognize the {% endif %} tag. Why does this happen?</p> <pre><code>&lt;html&gt; Name: {{ name }} Print {{ num }} times Color: {{ color }} {% if convert_to_upper %}Case: Upper {% elif not convert_to_...
7
2009-09-22T17:34:57Z
1,461,505
<p>I think you have your lines mixed up. Your <code>endif</code> comese before <code>endfilter</code> whereas <code>if</code> is before <code>filter</code>. That's just a syntax error.</p>
10
2009-09-22T17:39:19Z
[ "python", "jinja2" ]
Command line options with optional arguments in Python
1,461,942
<p>I was wondering if there's a simple way to parse command line options having optional arguments in Python. For example, I'd like to be able to call a script two ways:</p> <pre><code>&gt; script.py --foo &gt; script.py --foo=bar </code></pre> <p>From the Python getopt docs it seems I have to choose one or the othe...
4
2009-09-22T18:53:11Z
1,462,032
<p>Also, note that the standard library also has <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a>, a more powerful options parser.</p>
3
2009-09-22T19:12:52Z
[ "python", "getopt" ]
Command line options with optional arguments in Python
1,461,942
<p>I was wondering if there's a simple way to parse command line options having optional arguments in Python. For example, I'd like to be able to call a script two ways:</p> <pre><code>&gt; script.py --foo &gt; script.py --foo=bar </code></pre> <p>From the Python getopt docs it seems I have to choose one or the othe...
4
2009-09-22T18:53:11Z
1,462,034
<p>Use the <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a> package. </p>
1
2009-09-22T19:13:32Z
[ "python", "getopt" ]
Command line options with optional arguments in Python
1,461,942
<p>I was wondering if there's a simple way to parse command line options having optional arguments in Python. For example, I'd like to be able to call a script two ways:</p> <pre><code>&gt; script.py --foo &gt; script.py --foo=bar </code></pre> <p>From the Python getopt docs it seems I have to choose one or the othe...
4
2009-09-22T18:53:11Z
1,462,035
<p>check out argparse: <a href="http://code.google.com/p/argparse/" rel="nofollow">http://code.google.com/p/argparse/</a></p> <p>especially the 'nargs' option</p>
3
2009-09-22T19:13:41Z
[ "python", "getopt" ]
Command line options with optional arguments in Python
1,461,942
<p>I was wondering if there's a simple way to parse command line options having optional arguments in Python. For example, I'd like to be able to call a script two ways:</p> <pre><code>&gt; script.py --foo &gt; script.py --foo=bar </code></pre> <p>From the Python getopt docs it seems I have to choose one or the othe...
4
2009-09-22T18:53:11Z
1,462,046
<p>There isn't an option in optparse that allows you to do this. But you can extend it to do it:</p> <p><a href="http://docs.python.org/library/optparse.html#adding-new-actions" rel="nofollow">http://docs.python.org/library/optparse.html#adding-new-actions</a></p>
2
2009-09-22T19:15:23Z
[ "python", "getopt" ]
Command line options with optional arguments in Python
1,461,942
<p>I was wondering if there's a simple way to parse command line options having optional arguments in Python. For example, I'd like to be able to call a script two ways:</p> <pre><code>&gt; script.py --foo &gt; script.py --foo=bar </code></pre> <p>From the Python getopt docs it seems I have to choose one or the othe...
4
2009-09-22T18:53:11Z
1,462,395
<p><code>optparse</code> module from stdlib doesn't support it out of the box (and it shouldn't due to it is a bad practice to use command-line options in such way).</p> <p>As <a href="http://stackoverflow.com/questions/1461942/command-line-options-with-optional-arguments-in-python/1462035#1462035">@Kevin Horn pointed...
3
2009-09-22T20:28:59Z
[ "python", "getopt" ]
Django forms: how to display media (javascript) for a DateTimeInput widget?
1,462,003
<p>Hello (please excuse me for my bad english ;) ),</p> <p>Imagine the classes bellow:</p> <p><strong>models.py</strong></p> <pre><code>from django import models class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) object_id = models.PositiveIntegerField...
1
2009-09-22T19:06:13Z
1,462,285
<p>The standard DateTimeWidget doesn't include any javascript. The widget used in the admin is a different one - <code>django.contrib.admin.widgets.AdminSplitDateTime</code> - and this includes the javascript.</p>
5
2009-09-22T20:05:22Z
[ "python", "django", "django-models", "django-admin", "django-forms" ]
How much data could be stored into a Google App Engine, application?
1,462,160
<p>Answering <a href="http://stackoverflow.com/questions/1462055/is-it-correct-that-developers-have-read-only-access-to-the-filesystem-on-app-eng">this question</a> and searching for references I have this doubt my self:</p> <p>*How much data could be stored into a Google App Engine, application?</p> <p>If I'm readin...
4
2009-09-22T19:38:49Z
1,462,234
<p>I read that to mean 1 GB stored during the course of a day, not added in a day, so in other words you can have up to 1 GB of storage for free. If you store more, calculated daily, you have to pay for that additional storage. There is no maximum on how much you can store, you just get billed for it.</p>
6
2009-09-22T19:53:44Z
[ "java", "python", "google-app-engine", "cloud" ]
How to improve performance of python cgi that reads a big file and returns it as a download?
1,462,330
<p>I have this python cgi script that checks if it hasn't been accessed to many times from the same IP, and if everything is ok, reads a big file form disk (11MB) and then returns it as a download.</p> <p>It works,but performance sucks. The bottleneck seems to be reading this huge file over and over:</p> <pre><code>...
2
2009-09-22T20:17:00Z
1,462,367
<p>Try reading and outputting (i.e. buffering) a chunk of say 16KB at a time. Probably Python is doing something slow behind the scenes and manually buffering may be faster.</p> <p>You shouldn't have to use e.g. a ramdisk - the OS disk cache ought to cache the file contents for you.</p>
1
2009-09-22T20:24:06Z
[ "python", "cgi", "performance", "mod-wsgi" ]
How to improve performance of python cgi that reads a big file and returns it as a download?
1,462,330
<p>I have this python cgi script that checks if it hasn't been accessed to many times from the same IP, and if everything is ok, reads a big file form disk (11MB) and then returns it as a download.</p> <p>It works,but performance sucks. The bottleneck seems to be reading this huge file over and over:</p> <pre><code>...
2
2009-09-22T20:17:00Z
1,462,369
<p>mod_wsgi or FastCGI would help in the sense that you don't need to reload the Python interpreter every time your script is run. However, they'd do little to improve the performance of reading the file (if that's what's really your bottleneck). I'd advise you to use something along the lines of memcached instead.</p>...
1
2009-09-22T20:24:12Z
[ "python", "cgi", "performance", "mod-wsgi" ]
How to improve performance of python cgi that reads a big file and returns it as a download?
1,462,330
<p>I have this python cgi script that checks if it hasn't been accessed to many times from the same IP, and if everything is ok, reads a big file form disk (11MB) and then returns it as a download.</p> <p>It works,but performance sucks. The bottleneck seems to be reading this huge file over and over:</p> <pre><code>...
2
2009-09-22T20:17:00Z
1,462,374
<p>Why are you printing is all in one print statement? Python has to generate several temporary strings to handle the content headers and because of that last %s, it has to hold the entire contents of the file in two different string vars. This should be better.</p> <pre><code>print "Content-Type:application/x-downloa...
2
2009-09-22T20:25:07Z
[ "python", "cgi", "performance", "mod-wsgi" ]
How to improve performance of python cgi that reads a big file and returns it as a download?
1,462,330
<p>I have this python cgi script that checks if it hasn't been accessed to many times from the same IP, and if everything is ok, reads a big file form disk (11MB) and then returns it as a download.</p> <p>It works,but performance sucks. The bottleneck seems to be reading this huge file over and over:</p> <pre><code>...
2
2009-09-22T20:17:00Z
1,463,235
<p>Use mod_wsgi and use something akin to:</p> <pre><code>def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain')] start_response(status, response_headers) file = open('/usr/share/dict/words', 'rb') return environ[...
9
2009-09-22T23:53:29Z
[ "python", "cgi", "performance", "mod-wsgi" ]
Can Python's MiniMock create mock of functions defined in the same file?
1,462,381
<p>I'm using the Python <a href="http://pypi.python.org/pypi/MiniMock" rel="nofollow">MiniMock</a> library for unit testing. I'd like to mock out a function defined in the same Python file as my doctest. Can MiniMock handle that? The naive approach fails: </p> <pre><code>def foo(): raise ValueError, "Don't call me...
3
2009-09-22T20:25:39Z
1,462,434
<p>This works:</p> <pre><code>def foo(): raise ValueError, "Don't call me during testing!" def bar(): """ Returns twice the value of foo() &gt;&gt;&gt; from minimock import mock &gt;&gt;&gt; mock('foo',returns=5) &gt;&gt;&gt; bar.func_globals['foo'] = foo &gt;&gt;&gt; bar() Called foo...
1
2009-09-22T20:35:02Z
[ "python", "mocking" ]
Can Python's MiniMock create mock of functions defined in the same file?
1,462,381
<p>I'm using the Python <a href="http://pypi.python.org/pypi/MiniMock" rel="nofollow">MiniMock</a> library for unit testing. I'd like to mock out a function defined in the same Python file as my doctest. Can MiniMock handle that? The naive approach fails: </p> <pre><code>def foo(): raise ValueError, "Don't call me...
3
2009-09-22T20:25:39Z
1,474,440
<p>I just replied on the mailing list with a MiniMock patch that fixes this.</p> <p>Until that's applied, instead of the following two lines in itsadok's snippet:</p> <pre><code>&gt;&gt;&gt; mock('foo',returns=5) &gt;&gt;&gt; bar.func_globals['foo'] = foo </code></pre> <p>you could also use</p> <pre><code>&gt;&gt;&...
5
2009-09-24T22:10:31Z
[ "python", "mocking" ]
Automatic String to Number conversion in Python
1,462,427
<p>I am trying to compare two lists of string in python. Some of the strings are numbers however I don't want to use it as number, only for string comparison.</p> <p>I read the string from a file and put them on a list like this:</p> <pre><code>def main(): inputFileName = 'BateCarteira.csv' inputFile = open(i...
1
2009-09-22T20:34:07Z
1,462,475
<p>Python never transforms a string to a number, unless you try something like:</p> <pre><code>s = "1.2" a = float(s) </code></pre> <p>So I guess that your .csv file has the string "1,20091E+11" inside it. Also notice that the decimal point is a coma. So, if you tried to convert it to a float, the transformation woul...
3
2009-09-22T20:43:09Z
[ "python", "casting" ]
Automatic String to Number conversion in Python
1,462,427
<p>I am trying to compare two lists of string in python. Some of the strings are numbers however I don't want to use it as number, only for string comparison.</p> <p>I read the string from a file and put them on a list like this:</p> <pre><code>def main(): inputFileName = 'BateCarteira.csv' inputFile = open(i...
1
2009-09-22T20:34:07Z
1,462,742
<p>You need the locale module to read numbers in the locale format (i.e with decimal comma that's used in (most) parts of Europe).</p> <pre><code>import locale locale.setlocale(locale.LC_ALL, '') f = locale.atof("1,20091E+11") </code></pre>
2
2009-09-22T21:31:23Z
[ "python", "casting" ]
Do I need multiple cursor objects to loop over a recordset and update at the same time?
1,462,511
<p>So I've got a large database that I can't hold in memory at once. I've got to loop over every item in a table, process it, and put the processed data into another column in the table.</p> <p>While I'm looping over my cursor, if I try to run an update statement it truncates the recordset (I believe because it's re-...
10
2009-09-22T20:48:01Z
1,462,554
<p>Cursors are bad bad bad for a multitude of reasons.</p> <p>I'd suggest (and a lot of others will definitely chime in) that you use a single UPDATE statement instead of going the CURSOR route.</p> <p>Can your Processed_Content be sent as a parameter to a single query that does set based operations like so:</p> <pr...
1
2009-09-22T20:55:13Z
[ "python", "database", "sqlite", "sqlite3", "cursor" ]
Do I need multiple cursor objects to loop over a recordset and update at the same time?
1,462,511
<p>So I've got a large database that I can't hold in memory at once. I've got to loop over every item in a table, process it, and put the processed data into another column in the table.</p> <p>While I'm looping over my cursor, if I try to run an update statement it truncates the recordset (I believe because it's re-...
10
2009-09-22T20:48:01Z
1,463,922
<p>I think you have roughly the right architecture -- presenting it in terms of "cursors" WILL confuse the "old SQL hands", because they'll be thinking of the many issues connected with <code>DECLARE foo CURSOR</code>, <code>FETCH FROM CURSOR</code>, <code>WHERE CURRENT OF CURSOR</code>, and other such beauts having to...
3
2009-09-23T04:16:26Z
[ "python", "database", "sqlite", "sqlite3", "cursor" ]
Do I need multiple cursor objects to loop over a recordset and update at the same time?
1,462,511
<p>So I've got a large database that I can't hold in memory at once. I've got to loop over every item in a table, process it, and put the processed data into another column in the table.</p> <p>While I'm looping over my cursor, if I try to run an update statement it truncates the recordset (I believe because it's re-...
10
2009-09-22T20:48:01Z
1,473,630
<p>Is it possible to create a DB function that will process your content? If so, you should be able to write a single update statement and let the database do all the work. Eg;</p> <pre><code>Update data_table set processed_col = Process_Column(col_to_be_processed) </code></pre>
2
2009-09-24T19:14:56Z
[ "python", "database", "sqlite", "sqlite3", "cursor" ]
What are sqlite development headers and how to install them?
1,462,565
<p>I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them.</p> <p>However, I have no ideas what these headers are (where I can find them, what they are doing and how to install them).</p> <p>Can anybody, pleas...
10
2009-09-22T20:57:06Z
1,462,623
<p>pysqlite needs to compiled/build before you can use it. This requires C language header files (*.H) which come with the source code of sqllite itself.</p> <p>i.e. sqllite and pysqlite are two different things. Did you install sqlite prior to trying and build pysqllte ? (or maybe you did, but did you do so just w...
0
2009-09-22T21:10:35Z
[ "python", "header", "pysqlite" ]
What are sqlite development headers and how to install them?
1,462,565
<p>I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them.</p> <p>However, I have no ideas what these headers are (where I can find them, what they are doing and how to install them).</p> <p>Can anybody, pleas...
10
2009-09-22T20:57:06Z
1,462,624
<p>debian/ubuntu:</p> <pre><code>$ apt-get install libsqlite3-dev # or rpm -i sqlite-devel-something.rpm </code></pre> <hr> <p>I think a number of interpreters just recompile their small connection libraries on installation, but to do that they need the C .h files in addition to the library to link against. You may ...
16
2009-09-22T21:10:39Z
[ "python", "header", "pysqlite" ]
What are sqlite development headers and how to install them?
1,462,565
<p>I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them.</p> <p>However, I have no ideas what these headers are (where I can find them, what they are doing and how to install them).</p> <p>Can anybody, pleas...
10
2009-09-22T20:57:06Z
5,671,345
<p>For me this worked (Redhat/CentOS):</p> <p>$ sudo yum install sqlite-devel</p>
7
2011-04-15T00:52:50Z
[ "python", "header", "pysqlite" ]
Print PDF document with python's win32print module?
1,462,842
<p>I'm trying to print a PDF document with the win32print module. Apparently this module can only accept PCL or raw text. Is that correct? </p> <p>If so, is there a module available to convert a PDF document into PCL?</p> <p>I contemplated using ShellExecute; however, this is not an option since it only allows printi...
2
2009-09-22T21:52:15Z
1,463,214
<p>I am not sure how to specifically get win32print to work, but there might be a couple of other options. <a href="http://www.reportlab.org/" rel="nofollow">Reportlab</a> if often mentioned when creating PDFs from Python. If you are already invested in your approach, maybe using <a href="http://pyx.sourceforge.net/"...
0
2009-09-22T23:44:50Z
[ "python", "windows", "pdf", "winapi", "postscript" ]
Print PDF document with python's win32print module?
1,462,842
<p>I'm trying to print a PDF document with the win32print module. Apparently this module can only accept PCL or raw text. Is that correct? </p> <p>If so, is there a module available to convert a PDF document into PCL?</p> <p>I contemplated using ShellExecute; however, this is not an option since it only allows printi...
2
2009-09-22T21:52:15Z
1,464,974
<p>I ended up using <a href="http://pages.cs.wisc.edu/~ghost/" rel="nofollow" title="Ghostscript">Ghostscript</a> to accomplish this task. There is a command line tool that relies on Ghostscript called <a href="http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm" rel="nofollow" title="gsprint">gsprint</a>.</p> <p>You d...
8
2009-09-23T09:37:55Z
[ "python", "windows", "pdf", "winapi", "postscript" ]
Print PDF document with python's win32print module?
1,462,842
<p>I'm trying to print a PDF document with the win32print module. Apparently this module can only accept PCL or raw text. Is that correct? </p> <p>If so, is there a module available to convert a PDF document into PCL?</p> <p>I contemplated using ShellExecute; however, this is not an option since it only allows printi...
2
2009-09-22T21:52:15Z
3,284,735
<p>I was already using the win32api.ShellExecute approach and needed to print to a non-default printer. The best way I could work out was to temporarily change the default printer. So right before I do the print I store what the current default printer is, change it, and then set it back after printing. Something li...
2
2010-07-19T20:22:27Z
[ "python", "windows", "pdf", "winapi", "postscript" ]
python system calls
1,462,878
<p>with this command, I get only the file called OUTPUT (in reality I have many more --include flags) - so works as expected:</p> <pre><code>os.system("rsync --rsh=ssh -arvuP --include='OUTPUT' --exclude='*' user@host:there/ ./here") </code></pre> <p>In this case, the --include and --exclude flags are ignored:</p> <...
0
2009-09-22T22:05:15Z
1,462,983
<p>Try using <code>subprocess.call</code> with <code>shell=True</code>, it will simulate os.system more closely:</p> <pre><code>subprocess.call("...", shell=True) </code></pre>
4
2009-09-22T22:31:44Z
[ "python", "shell" ]
python system calls
1,462,878
<p>with this command, I get only the file called OUTPUT (in reality I have many more --include flags) - so works as expected:</p> <pre><code>os.system("rsync --rsh=ssh -arvuP --include='OUTPUT' --exclude='*' user@host:there/ ./here") </code></pre> <p>In this case, the --include and --exclude flags are ignored:</p> <...
0
2009-09-22T22:05:15Z
1,463,567
<p>Python does have an rsync module if I am not wrong, why not use that instead of a call. It will make your app more manageable.</p>
1
2009-09-23T01:46:39Z
[ "python", "shell" ]
Django generates 'WHERE ... BETWEEN ...' sentences?
1,462,968
<p>Actually, somewhere in the view:</p> <pre><code>dif = datetime.timedelta(days=1) today = datetime.date.today() yesterday = today - dif ex = Fact.objects.filter(fecha_fact__lte=today ,fecha_fact__gte=yesterday ) </code></pre> <p>It results to this SQL Query:</p> <pre><code>SELECT `facts_fact`.`id` ... FROM `facts_...
2
2009-09-22T22:27:58Z
1,462,991
<p>Have you tried <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#range" rel="nofollow"><code>range</code></a>?</p> <pre><code>Fact.objects.filter(fecha_fact__range=(yesterday, today)) </code></pre>
4
2009-09-22T22:33:54Z
[ "python", "sql", "django", "django-models" ]
Django generates 'WHERE ... BETWEEN ...' sentences?
1,462,968
<p>Actually, somewhere in the view:</p> <pre><code>dif = datetime.timedelta(days=1) today = datetime.date.today() yesterday = today - dif ex = Fact.objects.filter(fecha_fact__lte=today ,fecha_fact__gte=yesterday ) </code></pre> <p>It results to this SQL Query:</p> <pre><code>SELECT `facts_fact`.`id` ... FROM `facts_...
2
2009-09-22T22:27:58Z
1,463,005
<p>i dont know, but maybe (gte / lte ):</p> <pre><code>q1 = Entry.objects.filter(headline__startswith="What") q2 = q1.exclude(pub_date__gte=datetime.now()) q3 = q1.filter(pub_date__gte=datetime.now()) q = Entry.objects.filter(headline__startswith="What") q = q.filter(pub_date__lte=datetime.now()) </code></pre>
0
2009-09-22T22:37:31Z
[ "python", "sql", "django", "django-models" ]
Lazy module variables--can it be done?
1,462,986
<p>I'm trying to find a way to lazily load a module-level variable.</p> <p>Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a <code>DOWNLOAD_FOLDER_PATH</code> module variable. Unfortunately, iTunes won't tell you where its download folder is, so I've written a function that grabs...
22
2009-09-22T22:32:05Z
1,463,036
<p>If that variable lived in a class rather than a module, then you could overload getattr, or better yet, populate it in init.</p>
0
2009-09-22T22:44:47Z
[ "python", "module", "variables", "lazy-loading", "itunes" ]
Lazy module variables--can it be done?
1,462,986
<p>I'm trying to find a way to lazily load a module-level variable.</p> <p>Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a <code>DOWNLOAD_FOLDER_PATH</code> module variable. Unfortunately, iTunes won't tell you where its download folder is, so I've written a function that grabs...
22
2009-09-22T22:32:05Z
1,463,121
<p><em>Is there any way to lazily assign a module variable when it's first accessed or will I have to rely on a function?</em></p> <p>I think you are correct in saying that a function is the best solution to your problem here. I will give you a brief example to illustrate.</p> <pre><code>#myfile.py - an example modu...
3
2009-09-22T23:10:16Z
[ "python", "module", "variables", "lazy-loading", "itunes" ]
Lazy module variables--can it be done?
1,462,986
<p>I'm trying to find a way to lazily load a module-level variable.</p> <p>Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a <code>DOWNLOAD_FOLDER_PATH</code> module variable. Unfortunately, iTunes won't tell you where its download folder is, so I've written a function that grabs...
22
2009-09-22T22:32:05Z
1,463,773
<p>You can't do it with modules, but you can disguise a class "as if" it was a module, e.g., in <code>itun.py</code>, code...:</p> <pre><code>import sys class _Sneaky(object): def __init__(self): self.download = None @property def DOWNLOAD_PATH(self): if not self.download: self.download = heavyCo...
39
2009-09-23T03:09:28Z
[ "python", "module", "variables", "lazy-loading", "itunes" ]
Lazy module variables--can it be done?
1,462,986
<p>I'm trying to find a way to lazily load a module-level variable.</p> <p>Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a <code>DOWNLOAD_FOLDER_PATH</code> module variable. Unfortunately, iTunes won't tell you where its download folder is, so I've written a function that grabs...
22
2009-09-22T22:32:05Z
14,345,798
<p>I used Alex' implementation on Python 3.3, but this crashes miserably: The code</p> <pre><code> def __getattr__(self, name): return globals()[name] </code></pre> <p>is not correct because an <code>AttributeError</code> should be raised, not a <code>KeyError</code>. This crashed immediately under Python 3.3, b...
9
2013-01-15T19:57:57Z
[ "python", "module", "variables", "lazy-loading", "itunes" ]
Lazy module variables--can it be done?
1,462,986
<p>I'm trying to find a way to lazily load a module-level variable.</p> <p>Specifically, I've written a tiny Python library to talk to iTunes, and I want to have a <code>DOWNLOAD_FOLDER_PATH</code> module variable. Unfortunately, iTunes won't tell you where its download folder is, so I've written a function that grabs...
22
2009-09-22T22:32:05Z
16,937,048
<p>Recently I came across the same problem, and have found a way to do it.</p> <pre><code>class LazyObject(object): def __init__(self): self.initialized = False setattr(self, 'data', None) def init(self, *args): #print 'initializing' pass def __len__(self): return len(self...
2
2013-06-05T10:04:07Z
[ "python", "module", "variables", "lazy-loading", "itunes" ]
How can I get an email message's text content using python?
1,463,074
<p>Given an RFC822 message in Python 2.6, how can I get the <em>right</em> text/plain content part? Basically, the algorithm I want is this:</p> <pre><code>message = email.message_from_string(raw_message) if has_mime_part(message, "text/plain"): mime_part = get_mime_part(message, "text/plain") text_content = ...
19
2009-09-22T22:56:24Z
1,463,144
<p>In a multipart e-mail, <code>email.message.Message.get_payload()</code> returns a list with one item for each part. The easiest way is to walk the message and get the payload on each part:</p> <pre><code>import email msg = email.message_from_string(raw_message) for part in msg.walk(): # each part is a either no...
51
2009-09-22T23:17:31Z
[ "python", "email", "mime", "rfc822" ]
How can I get an email message's text content using python?
1,463,074
<p>Given an RFC822 message in Python 2.6, how can I get the <em>right</em> text/plain content part? Basically, the algorithm I want is this:</p> <pre><code>message = email.message_from_string(raw_message) if has_mime_part(message, "text/plain"): mime_part = get_mime_part(message, "text/plain") text_content = ...
19
2009-09-22T22:56:24Z
34,039,927
<p>Flat is better than nested ;)</p> <pre><code>from email.mime.multipart import MIMEMultipart assert isinstance(msg, MIMEMultipart) for _ in [k.get_payload() for k in msg.walk() if k.get_content_type() == 'text/plain']: print _ </code></pre>
0
2015-12-02T10:06:28Z
[ "python", "email", "mime", "rfc822" ]
django - using a common header with some dynamic elements
1,463,153
<p>I'm planning to create a website using django that will have a common header throughout the entire website. I've read django's documentation on templating inheritance, but I can't seem to find an elegant solution for the "dynamic" elements in my header.</p> <p>For example, the header in the website will include ta...
3
2009-09-22T23:20:04Z
1,463,319
<p>A version of #1 will do the trick — with a separate template file for the tag.</p> <p>Lets say you have the models "Category" and "Article".</p> <pre><code>class Category(models.Model): title = models.CharField(_("Name"), max_length=200) introduction = models.TextField(blank=True, null=True)...
1
2009-09-23T00:22:03Z
[ "javascript", "python", "django" ]
django - using a common header with some dynamic elements
1,463,153
<p>I'm planning to create a website using django that will have a common header throughout the entire website. I've read django's documentation on templating inheritance, but I can't seem to find an elegant solution for the "dynamic" elements in my header.</p> <p>For example, the header in the website will include ta...
3
2009-09-22T23:20:04Z
1,463,395
<p>I'm assuming each tab is a list item in your template <code>base.html</code>.</p> <pre><code>&lt;ul&gt; &lt;li&gt;Tab 1&lt;/li&gt; &lt;li&gt;Tab 2&lt;/li&gt; ... &lt;/ul&gt; </code></pre> <p>Add an extra block to each <code>li</code>.</p> <pre><code>&lt;ul&gt; &lt;li class="{% block class_tab1 %}i...
9
2009-09-23T00:47:22Z
[ "javascript", "python", "django" ]
django - using a common header with some dynamic elements
1,463,153
<p>I'm planning to create a website using django that will have a common header throughout the entire website. I've read django's documentation on templating inheritance, but I can't seem to find an elegant solution for the "dynamic" elements in my header.</p> <p>For example, the header in the website will include ta...
3
2009-09-22T23:20:04Z
1,463,556
<p>This is a rather common problems and I've come up with some various ways to solve it.</p> <p>Since you're asking for options, here's 3 other alternative ways achieve this effect. The options you mentioned and these listed below all have thier positives and negatives. It's really up to you to decide which is a bes...
1
2009-09-23T01:41:37Z
[ "javascript", "python", "django" ]
How to create user defined fields in Django
1,463,242
<p>Ok, I am working on a Django application with several different models, namely Accounts, Contacts, etc, each with a different set of fields. I need to be able to allow each of my users to define their own fields in addition to the existing fields. I have seen several different ways to implement this, from having a...
2
2009-09-22T23:56:33Z
1,463,676
<p>What if you were to use a ForeignKey?</p> <p>This code (untested and for demo) is assuming there is a system-wide set of custom fields. To make it user-specific, you'd add a "user = models.ForiegnKey(User)" onto the class CustomField.</p> <pre><code>class Account(models.Model): name = models.CharField(max_len...
2
2009-09-23T02:26:37Z
[ "python", "django", "configuration", "modeling" ]
How does exec work with locals?
1,463,306
<p>I thought this would print 3, but it prints 1:</p> <pre><code>def f(): a = 1 exec("a = 3") print(a) </code></pre>
10
2009-09-23T00:18:47Z
1,463,370
<p>This issue is somewhat discussed in the <a href="http://bugs.python.org/issue4831">Python3 bug list</a>. Ultimately, to get this behavior, you need to do:</p> <pre><code>def foo(): ldict = locals() exec("a=3",globals(),ldict) a = ldict['a'] print(a) </code></pre> <p>And if you check <a href="http:...
18
2009-09-23T00:37:27Z
[ "python", "python-3.x", "exec", "locals" ]
How does exec work with locals?
1,463,306
<p>I thought this would print 3, but it prints 1:</p> <pre><code>def f(): a = 1 exec("a = 3") print(a) </code></pre>
10
2009-09-23T00:18:47Z
32,828,675
<p>If you are inside a method, you can do so:</p> <pre><code>class Thing(): def __init__(self): exec('self.foo = 2') x = Thing() print(x.foo) </code></pre> <p><a href="http://chimera.labs.oreilly.com/books/1230000000393/ch09.html#_problem_166" rel="nofollow">You can read more about it here</a></p>
2
2015-09-28T17:32:06Z
[ "python", "python-3.x", "exec", "locals" ]
Django: how to including inline model fields in the list_display?
1,463,398
<p>I'm attempting to extend django's contrib.auth User model, using an inline 'Profile' model to include extra fields.</p> <pre><code>from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin class Profile(models.Model): user = models.ForeignKey(Us...
3
2009-09-23T00:48:30Z
1,464,624
<p>You've mentioned the only solution - creating a callable. There's currently no other way to do it, and yes this does mean you can't sort by that column. </p>
7
2009-09-23T08:09:18Z
[ "python", "django", "django-models", "django-admin" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
1,463,501
<p>You can't. HttpResponseRedirect sends a client-side redirect (HTTP status code 302) to the browser, and then the browser re-requests another page.</p> <p>You can set a URL query string on the redirect, though that will be visible to the user and anyone intercepting HTTP requests (i.e. proxies), and is therefore not...
4
2009-09-23T01:24:46Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
1,463,504
<p>You add ?saved=1 to the query string and check for it with something like:</p> <pre><code>saved = request.GET.get('saved', False) </code></pre>
0
2009-09-23T01:25:42Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
1,463,508
<p>The only way I know of to pass any data with a redirect is to add GET parameters to the URL you're passing in. To avoid XSS hacks you'd want to pass a specific constant like:</p> <p>[current path you're passing in]?message=saved</p> <p>And then process the message=saved parameter in the handler for the path you p...
1
2009-09-23T01:26:35Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
1,463,511
<p>The best way would probably be to use a coded querystring on the redirect URL... its an old school approach.</p> <p>You could do something like</p> <p>/page/?m=1, /page/?m=2, etc</p> <p>You would then parse that variable with request.GET in the view code and show the appropriate message.</p>
5
2009-09-23T01:27:14Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
1,463,857
<p>if you are using auth and have a logged in user you could: </p> <p><a href="http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.message_set.create" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.message_set.create</a></p> <p>GET params...
7
2009-09-23T03:51:39Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
5,735,480
<p>From your views.py you hast have to put a key/value-pair into the session and then read it from the HTML template.</p> <p>For example:</p> <p><strong>views.py</strong></p> <pre><code># your code here request.session['vote'] = 1 return HttpResponseRedirect(request.path) </code></pre> <p><strong>your_template.html...
0
2011-04-20T19:17:20Z
[ "python", "django", "http", "redirect" ]
How do I pass template context information when using HttpResponseRedirect in Django?
1,463,489
<p>I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning</p> <pre><code>HttpResponseRedirect(request.path) </code></pre> <p>which works fine. However, I'd also like to display some messages ...
24
2009-09-23T01:19:17Z
11,594,329
<p>For the sake of completion and future reference, you can now use <a href="https://docs.djangoproject.com/en/dev/ref/contrib/messages/">the messages framework</a>. After you install it:</p> <p><strong>views.py</strong></p> <pre><code>from django.contrib import messages def view(request): # your code messages.s...
34
2012-07-21T17:25:09Z
[ "python", "django", "http", "redirect" ]
What is the accepted python alternative to C++ overloaded input stream operators?
1,463,499
<p>In C++, you can do this to easily read data into a class:</p> <pre><code>istream&amp; operator &gt;&gt; (istream&amp; instream, SomeClass&amp; someclass) { ... } </code></pre> <p>In python, the only way I can find to read from the console is the "raw_input" function, which isn't very adaptable to this sort of ...
2
2009-09-23T01:24:01Z
1,463,518
<p>You are essentially looking for deserialization. Python has a myriad of options for this depending on the library used. The default is python <a href="http://www.network-theory.co.uk/docs/pytut/pickleModule.html" rel="nofollow">pickling</a>. There are lots of other options you can have a look <a href="http://blog.me...
6
2009-09-23T01:28:52Z
[ "python", "input", "operator-overloading" ]
What is the accepted python alternative to C++ overloaded input stream operators?
1,463,499
<p>In C++, you can do this to easily read data into a class:</p> <pre><code>istream&amp; operator &gt;&gt; (istream&amp; instream, SomeClass&amp; someclass) { ... } </code></pre> <p>In python, the only way I can find to read from the console is the "raw_input" function, which isn't very adaptable to this sort of ...
2
2009-09-23T01:24:01Z
1,463,539
<p>Rather than use raw_input, you can read from sys.stdin (a file-like object):</p> <pre><code>import sys input_line = sys.stdin.readline() # do something with input_line </code></pre>
2
2009-09-23T01:34:50Z
[ "python", "input", "operator-overloading" ]
What is the accepted python alternative to C++ overloaded input stream operators?
1,463,499
<p>In C++, you can do this to easily read data into a class:</p> <pre><code>istream&amp; operator &gt;&gt; (istream&amp; instream, SomeClass&amp; someclass) { ... } </code></pre> <p>In python, the only way I can find to read from the console is the "raw_input" function, which isn't very adaptable to this sort of ...
2
2009-09-23T01:24:01Z
1,463,950
<p>No, there's no widespread Pythonic convention for "read the next instance of class X from this open input text file". I believe this applies to most languages, including e.g. Java; C++ is kind of the outlier there (and many C++ shops forbid the <code>operator&gt;&gt;</code> use in their local style guides). Serializ...
3
2009-09-23T04:26:45Z
[ "python", "input", "operator-overloading" ]
Deploying CherryPy (daemon)
1,463,510
<p>I've followed the basic CherryPy tutorial (<a href="http://www.cherrypy.org/wiki/CherryPyTutorial">http://www.cherrypy.org/wiki/CherryPyTutorial</a>). One thing not discussed is deployment.</p> <p>How can I launch a CherryPy app as a daemon and "forget about it"? What happens if the server reboots?</p> <p>Is the...
21
2009-09-23T01:27:13Z
1,463,562
<p>There is a <a href="http://docs.cherrypy.org/stable/refman/process/plugins/daemonizer.html">Daemonizer</a> plugin for CherryPy included by default which is useful for getting it to start but by far the easiest way for simple cases is to use the cherryd script:</p> <pre><code>&gt; cherryd -h Usage: cherryd [options]...
13
2009-09-23T01:44:58Z
[ "python", "deployment", "cherrypy" ]
Deploying CherryPy (daemon)
1,463,510
<p>I've followed the basic CherryPy tutorial (<a href="http://www.cherrypy.org/wiki/CherryPyTutorial">http://www.cherrypy.org/wiki/CherryPyTutorial</a>). One thing not discussed is deployment.</p> <p>How can I launch a CherryPy app as a daemon and "forget about it"? What happens if the server reboots?</p> <p>Is the...
21
2009-09-23T01:27:13Z
5,353,332
<p>Daemonizer can be pretty simple to use:</p> <pre><code># this works for cherrypy 3.1.2 on Ubuntu 10.04 from cherrypy.process.plugins import Daemonizer # before mounting anything Daemonizer(cherrypy.engine).subscribe() cherrypy.tree.mount(MyDaemonApp, "/") cherrypy.engine.start() cherrypy.engine.block() </code></pr...
10
2011-03-18T14:22:32Z
[ "python", "deployment", "cherrypy" ]
Deploying CherryPy (daemon)
1,463,510
<p>I've followed the basic CherryPy tutorial (<a href="http://www.cherrypy.org/wiki/CherryPyTutorial">http://www.cherrypy.org/wiki/CherryPyTutorial</a>). One thing not discussed is deployment.</p> <p>How can I launch a CherryPy app as a daemon and "forget about it"? What happens if the server reboots?</p> <p>Is the...
21
2009-09-23T01:27:13Z
24,467,279
<p>I wrote a tutorial/project skeleton, <a href="https://bitbucket.org/saaj/cherrypy-webapp-skeleton" rel="nofollow">cherrypy-webapp-skeleton</a>, which goal was to fill the gaps for deploying a real-world CherryPy application on Debian* for a web-developer. It features extended <code>cherryd</code> for daemon privileg...
3
2014-06-28T13:27:24Z
[ "python", "deployment", "cherrypy" ]
How can this python function code work?
1,463,588
<p>this is from the source code of csv2rec in matplotlib</p> <p>how can this function work, if its only parameters are 'func, default'?</p> <pre><code>def with_default_value(func, default): def newfunc(name, val): if ismissing(name, val): return default else: return func(va...
6
2009-09-23T01:51:28Z
1,463,598
<p>This is a function that returns another function. <code>name</code> and <code>value</code> are the parameters of the returned function.</p>
0
2009-09-23T01:54:58Z
[ "python", "function", "matplotlib" ]
How can this python function code work?
1,463,588
<p>this is from the source code of csv2rec in matplotlib</p> <p>how can this function work, if its only parameters are 'func, default'?</p> <pre><code>def with_default_value(func, default): def newfunc(name, val): if ismissing(name, val): return default else: return func(va...
6
2009-09-23T01:51:28Z
1,463,600
<p>This is a Python decorator -- basically a function wrapper. (Read all about decorators in PEP 318 -- <a href="http://www.python.org/dev/peps/pep-0318/" rel="nofollow">http://www.python.org/dev/peps/pep-0318/</a>)</p> <p>If you look through the code, you will probably find something like this:</p> <pre><code>def so...
6
2009-09-23T01:55:59Z
[ "python", "function", "matplotlib" ]
How can this python function code work?
1,463,588
<p>this is from the source code of csv2rec in matplotlib</p> <p>how can this function work, if its only parameters are 'func, default'?</p> <pre><code>def with_default_value(func, default): def newfunc(name, val): if ismissing(name, val): return default else: return func(va...
6
2009-09-23T01:51:28Z
1,463,612
<p>As for why it works:</p> <p>with_default_value returns a function object, which is basically going to be a <em>copy</em> of that nested newfunc, with the 'func' call and default value substited with whatever was passed to with_default_value.</p> <p>If someone does 'foo = with_default_value(bar, 3)', the return val...
1
2009-09-23T02:01:41Z
[ "python", "function", "matplotlib" ]
How can this python function code work?
1,463,588
<p>this is from the source code of csv2rec in matplotlib</p> <p>how can this function work, if its only parameters are 'func, default'?</p> <pre><code>def with_default_value(func, default): def newfunc(name, val): if ismissing(name, val): return default else: return func(va...
6
2009-09-23T01:51:28Z
1,463,706
<p>This <code>with_default_value</code> function is what's often referred to (imprecisely) as "a closure" (technically, the closure is rather the <em>inner</em> function that gets returned, here <code>newfunc</code> -- see e.g. <a href="http://en.wikipedia.org/wiki/Closure%5F%28computer%5Fscience%29" rel="nofollow">her...
8
2009-09-23T02:41:30Z
[ "python", "function", "matplotlib" ]
How do I get this program to start over in python?
1,463,710
<p>I believe the word is "recurse" instead of 'start over.' I've created this program to hone my multiplication skills in the morning. I can get it to give me a multiplication problem, but how do I get it to ask me another one?</p> <pre><code>from random import randint print 'Good Morning Pete!' X = randint(0, 10)...
-1
2009-09-23T02:44:43Z
1,463,737
<p>A loop? See the <code>for</code> statement and the <code>range()</code> function. They're in the <a href="http://docs.python.org/tutorial/controlflow.html" rel="nofollow">Python tutorial</a>.</p> <p>And you might want to read the next chapter in whatever book you're using to teach yourself programming.</p>
1
2009-09-23T02:57:42Z
[ "python", "recursion" ]
How do I get this program to start over in python?
1,463,710
<p>I believe the word is "recurse" instead of 'start over.' I've created this program to hone my multiplication skills in the morning. I can get it to give me a multiplication problem, but how do I get it to ask me another one?</p> <pre><code>from random import randint print 'Good Morning Pete!' X = randint(0, 10)...
-1
2009-09-23T02:44:43Z
1,463,740
<p>Pete, you wouldn't need <em>recursion</em> in this case, but merely a <em>loop</em>.</p> <p>I suggest you put the bulk of the logic of this program (the part that asks the multiplcation problem and check your answer), into a function. Say One Problem(). This function could return 0 if you answered wrong, 1 if y...
3
2009-09-23T02:58:09Z
[ "python", "recursion" ]
How do I get this program to start over in python?
1,463,710
<p>I believe the word is "recurse" instead of 'start over.' I've created this program to hone my multiplication skills in the morning. I can get it to give me a multiplication problem, but how do I get it to ask me another one?</p> <pre><code>from random import randint print 'Good Morning Pete!' X = randint(0, 10)...
-1
2009-09-23T02:44:43Z
1,463,799
<p>to incorporate the loop, you might add this to the beginning of your code:</p> <p>running = True while True: //Add your code here</p> <pre><code>//Add this to the end of your code: print 'Another problem? Enter y or n' answer = raw_input().lower() if answer == 'n': running = False brea...
0
2009-09-23T03:20:05Z
[ "python", "recursion" ]
How do I get this program to start over in python?
1,463,710
<p>I believe the word is "recurse" instead of 'start over.' I've created this program to hone my multiplication skills in the morning. I can get it to give me a multiplication problem, but how do I get it to ask me another one?</p> <pre><code>from random import randint print 'Good Morning Pete!' X = randint(0, 10)...
-1
2009-09-23T02:44:43Z
1,463,803
<p>I agree 100% with those who said this isn't a good case for recursion, but calls for a loop instead. However, for the sake of showing how it might be done, I post the code below:</p> <pre><code>import random def do_mult(num_questions): x = random.randint(0, 10) y = random.randint(0, 10) a = x * y z...
0
2009-09-23T03:22:47Z
[ "python", "recursion" ]
How do I get this program to start over in python?
1,463,710
<p>I believe the word is "recurse" instead of 'start over.' I've created this program to hone my multiplication skills in the morning. I can get it to give me a multiplication problem, but how do I get it to ask me another one?</p> <pre><code>from random import randint print 'Good Morning Pete!' X = randint(0, 10)...
-1
2009-09-23T02:44:43Z
1,463,815
<p>I believe you want something like this</p> <pre><code>from random import randint print 'Good Morning Pete!' count = 0 while True: X = randint(0, 10) Y = randint(0, 10) A = X * Y Z = int(raw_input('%i * %i = ? ' % (X, Y))) if Z == A: count += 1 print 'Good Job!' else: ...
2
2009-09-23T03:29:11Z
[ "python", "recursion" ]
Calculate brute force size dynamically?
1,463,832
<p>How you could calculate size of brute force method dynamically? For example how many iterations and space would take if you printed all IPv6 addresses from 0:0:0:0:0:0:0:0 - ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff to file? The tricky parts are those when length of line varies. IP address is only example. </p> <p>Id...
0
2009-09-23T03:34:31Z
1,463,899
<p>Using <a href="http://en.wikipedia.org/wiki/Combinatorics" rel="nofollow">combinatorics</a> and discrete math:</p> <p>The IPv4 address space is 256<code>*</code>256<code>*</code>256<code>*</code>256 = 2^32 = 4,294,967,296 addresses.</p> <p>IPv6 has 2^128 addresses (8 groups of 16<code>*</code>16<code>*</code>16<co...
4
2009-09-23T04:08:43Z
[ "python", "math", "brute-force" ]
Calculate brute force size dynamically?
1,463,832
<p>How you could calculate size of brute force method dynamically? For example how many iterations and space would take if you printed all IPv6 addresses from 0:0:0:0:0:0:0:0 - ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff to file? The tricky parts are those when length of line varies. IP address is only example. </p> <p>Id...
0
2009-09-23T03:34:31Z
1,463,926
<p>First start by counting the number of lines you need. IPv6 addresses are 128 bits, so your output file will be 2<sup>128</sup> lines long. That's roughly 3.4 &times; 10<sup>38</sup> bytes, if all your lines are <em>empty</em>. A terabyte is only about 10<sup>12</sup> bytes, so you would need over 3 &times; 10<sup>26...
0
2009-09-23T04:17:40Z
[ "python", "math", "brute-force" ]
Calculate brute force size dynamically?
1,463,832
<p>How you could calculate size of brute force method dynamically? For example how many iterations and space would take if you printed all IPv6 addresses from 0:0:0:0:0:0:0:0 - ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff to file? The tricky parts are those when length of line varies. IP address is only example. </p> <p>Id...
0
2009-09-23T03:34:31Z
1,463,953
<p>Breaking it up into components is probably the way to go; for IPv4 you've got four parts, separated by three dots, and each part can be 1, 2 or 3 characters (0-9, 10-99, 100-255) long. So your combinations are:</p> <pre><code>comp_length = {1: 10, 2: 90, 3: 156} </code></pre> <p>You can work out the total lengths ...
0
2009-09-23T04:27:32Z
[ "python", "math", "brute-force" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,037
<p>You can use <a href="http://docs.python.org/library/functions.html?highlight=isinstance#isinstance" rel="nofollow"><code>isinstance</code></a> to check a variables type:</p> <pre><code>if isinstance(param, list): # it is a list print len(list) </code></pre>
1
2009-09-23T04:57:15Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,038
<p>Just use the type method? Or am I misinterpreting the question</p> <pre><code>if type(objectname) is list: do something else: do something else :P </code></pre>
-3
2009-09-23T04:57:28Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,049
<p>You don't.</p> <p><em>This works only for Python >= 2.6. If you're targeting anything below use <a href="http://stackoverflow.com/questions/1464028/what-is-the-pythonic-way-of-checking-if-an-object-is-a-list/">Alex' solution</a>.</em></p> <p>Python supports something called <a href="http://docs.python.org/glossary...
11
2009-09-23T05:00:23Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,050
<pre><code>if isinstance(your_object, list): print("your object is a list!") </code></pre> <p>This is more Pythonic than checking with type.</p> <p>Seems faster too:</p> <pre><code>&gt;&gt;&gt; timeit('isinstance(x, list)', 'x = [1, 2, 3, 4]') 0.40161490440368652 &gt;&gt;&gt; timeit('type(x) is list', 'x = [1, 2, ...
13
2009-09-23T05:00:29Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,089
<p>In such situations, you normally need to check for ANY iterable, not just lists -- if you're accepting lists OR numbers, rejecting (e.g) a tuple would be weird. The one kind of iterable you might want to treat as a "scalar" is a string -- in Python 2.*, this means <code>str</code> or <code>unicode</code>. So, either...
21
2009-09-23T05:17:53Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,124
<p>I don't want to be a pest, BUT: Are you sure the query set/object is a good interface? Make two functions, like:</p> <pre><code>def fobject(i): # do something def fqueryset(q): for obj in q: fobject( obj ) </code></pre> <p>Might not be the <em>pythonic</em> way to discern an int from a list, but seem...
2
2009-09-23T05:34:58Z
[ "python", "list" ]
What is the pythonic way of checking if an object is a list?
1,464,028
<p>I have a function that may take in a number or a list of numbers. Whats the most pythonic way of checking which it is? So far I've come up with try/except block checking if i can slice the zero item ie. obj[0:0]</p> <p>Edit:</p> <p>I seem to have started a war of words down below by not giving enough info. For com...
10
2009-09-23T04:54:10Z
1,464,235
<p>I think the way OP is doing, checking if it supports what he wants, is ok.</p> <p>Simpler way in this scenario would be to not check for list which can be of many types depending on definition, you may check if input is number, do something on it else try to use it as list if that throws exception bail out.</p> <p...
0
2009-09-23T06:16:57Z
[ "python", "list" ]
Pyqt - QMenu dynamically populated and clicked
1,464,548
<p>I need to be able to know what item I've clicked in a dynamically generated menu system. I only want to know what I've clicked on, even if it's simply a string representation.</p> <pre><code>def populateShotInfoMenus(self): self.menuFilms = QMenu() films = self.getList() for film in films: menu...
3
2009-09-23T07:53:24Z
1,464,589
<p>Instead of using <code>onFilmSet</code> directly as the receiver of your connection, use a lambda function so you can pass additional parameters:</p> <pre><code>receiver = lambda film=film: self.onFilmSet(self, film) self.connect(menuItem_Film, SIGNAL('triggered()'), receiver) </code></pre>
9
2009-09-23T08:01:51Z
[ "python", "user-interface", "qt", "pyqt" ]
Pyqt - QMenu dynamically populated and clicked
1,464,548
<p>I need to be able to know what item I've clicked in a dynamically generated menu system. I only want to know what I've clicked on, even if it's simply a string representation.</p> <pre><code>def populateShotInfoMenus(self): self.menuFilms = QMenu() films = self.getList() for film in films: menu...
3
2009-09-23T07:53:24Z
1,464,602
<p>Take a look at the Qt's property system. You can dynamically add a property containing a string or anything you desire, which defines the action. Then you can use sender() method in the slot to obtain the QObject calling the slot. Then, query the property you set and do whatever you want accordingly.</p> <p>But, th...
1
2009-09-23T08:03:54Z
[ "python", "user-interface", "qt", "pyqt" ]
Pyqt - QMenu dynamically populated and clicked
1,464,548
<p>I need to be able to know what item I've clicked in a dynamically generated menu system. I only want to know what I've clicked on, even if it's simply a string representation.</p> <pre><code>def populateShotInfoMenus(self): self.menuFilms = QMenu() films = self.getList() for film in films: menu...
3
2009-09-23T07:53:24Z
4,703,668
<p>I was trying to figure out a similar issue and after looking at the code above this is what worked for me. Thought it would be good to show it all together. =)</p> <pre><code>self.taskMenu = QtGui.QMenu("Task") self.tasks = self.getTasks() #FETCHES A LIST OF LIST self.menuTasks = QtGui.QMenu() for item in self.tas...
1
2011-01-16T03:41:19Z
[ "python", "user-interface", "qt", "pyqt" ]
Pyqt - QMenu dynamically populated and clicked
1,464,548
<p>I need to be able to know what item I've clicked in a dynamically generated menu system. I only want to know what I've clicked on, even if it's simply a string representation.</p> <pre><code>def populateShotInfoMenus(self): self.menuFilms = QMenu() films = self.getList() for film in films: menu...
3
2009-09-23T07:53:24Z
15,099,818
<p>Just some additional information, I don't know why, but lambda function doesn't work with new pyqt syntax for connections :</p> <p>Example of code not working :</p> <pre><code> self.contextTreeMenuAssignTo = QtGui.QMenu(self) actionAssign = contextMenu.addMenu( self.contextTreeMenuAssignTo ) actionAssig...
1
2013-02-26T21:37:56Z
[ "python", "user-interface", "qt", "pyqt" ]
Pyqt - QMenu dynamically populated and clicked
1,464,548
<p>I need to be able to know what item I've clicked in a dynamically generated menu system. I only want to know what I've clicked on, even if it's simply a string representation.</p> <pre><code>def populateShotInfoMenus(self): self.menuFilms = QMenu() films = self.getList() for film in films: menu...
3
2009-09-23T07:53:24Z
35,053,109
<p>I found <a href="http://stackoverflow.com/questions/28319889/pyqt5-whats-this-boolean-passed-when-a-menu-action-is-triggered">this</a> answer here for dealing with this issue in PyQt5, python3. I don't like it, the bVal variable to be precise, as I don't fully understand it but it took a long time to find so I thoug...
0
2016-01-28T04:51:48Z
[ "python", "user-interface", "qt", "pyqt" ]
internal server error (500) in simple cgi script
1,464,728
<p>I am trying to run a simple cgi script after configuring my server.</p> <p>My script looks like this:</p> <pre><code>print "Content-type: text/html" print print "&lt;html&gt;&lt;head&gt;&lt;title&gt;CGI&lt;/title&gt;&lt;/head&gt;" print "&lt;body&gt;" print "hello cgi" print "&lt;/body&gt;" print "&lt;/html&gt;" <...
7
2009-09-23T08:33:52Z
1,464,762
<p>You might need a <code>#!/usr/bin/python</code> at the top of your script to tell Apache to use Python to execute it. At least, I did that and it worked for me :-) .</p>
18
2009-09-23T08:44:12Z
[ "python", "apache", "cgi" ]
internal server error (500) in simple cgi script
1,464,728
<p>I am trying to run a simple cgi script after configuring my server.</p> <p>My script looks like this:</p> <pre><code>print "Content-type: text/html" print print "&lt;html&gt;&lt;head&gt;&lt;title&gt;CGI&lt;/title&gt;&lt;/head&gt;" print "&lt;body&gt;" print "hello cgi" print "&lt;/body&gt;" print "&lt;/html&gt;" <...
7
2009-09-23T08:33:52Z
1,464,770
<p>It looks like Apache has trouble executing it. Typically for a unix script you also need to specify the interpreter at the top of the script.</p> <p>Try adding this to the top:</p> <pre><code>#!/usr/bin/python </code></pre>
0
2009-09-23T08:45:40Z
[ "python", "apache", "cgi" ]
internal server error (500) in simple cgi script
1,464,728
<p>I am trying to run a simple cgi script after configuring my server.</p> <p>My script looks like this:</p> <pre><code>print "Content-type: text/html" print print "&lt;html&gt;&lt;head&gt;&lt;title&gt;CGI&lt;/title&gt;&lt;/head&gt;" print "&lt;body&gt;" print "hello cgi" print "&lt;/body&gt;" print "&lt;/html&gt;" <...
7
2009-09-23T08:33:52Z
1,464,804
<p>Also, save the file (if this is a Linux server) with Unix line endings. You did make it executable using <code>chmod +x</code> didn't you?</p> <p>You can use <code>#!/usr/bin/env python</code> to cover the current running Python version if you're running in various environments (hence the <code>env</code> part).</p...
8
2009-09-23T08:53:14Z
[ "python", "apache", "cgi" ]
internal server error (500) in simple cgi script
1,464,728
<p>I am trying to run a simple cgi script after configuring my server.</p> <p>My script looks like this:</p> <pre><code>print "Content-type: text/html" print print "&lt;html&gt;&lt;head&gt;&lt;title&gt;CGI&lt;/title&gt;&lt;/head&gt;" print "&lt;body&gt;" print "hello cgi" print "&lt;/body&gt;" print "&lt;/html&gt;" <...
7
2009-09-23T08:33:52Z
4,127,033
<p>Putting</p> <pre><code>#!/usr/bin/env python </code></pre> <p>on the top of the script works fine. I put it on top, but Netbeans was putting extra code (import commands) by itself on the top of the page which drove me crazy :(</p>
1
2010-11-08T19:01:36Z
[ "python", "apache", "cgi" ]
internal server error (500) in simple cgi script
1,464,728
<p>I am trying to run a simple cgi script after configuring my server.</p> <p>My script looks like this:</p> <pre><code>print "Content-type: text/html" print print "&lt;html&gt;&lt;head&gt;&lt;title&gt;CGI&lt;/title&gt;&lt;/head&gt;" print "&lt;body&gt;" print "hello cgi" print "&lt;/body&gt;" print "&lt;/html&gt;" <...
7
2009-09-23T08:33:52Z
37,512,768
<p>Maybe your problem is that new python version needs parentheses ( ). </p> <p>So your:</p> <pre><code>print "&lt;body&gt;" </code></pre> <p>Now should to be:</p> <pre><code>print ("&lt;body&gt;") </code></pre>
0
2016-05-29T17:15:40Z
[ "python", "apache", "cgi" ]
Windows impersonation for WMI calls via python?
1,464,894
<p>I'm using PyWin32 to make WMI calls to the system in python from my django web application. My goal is to allow users to add printers to the system via a web interface. To do this, I'm using win32print.AddPrinterConnection.</p> <p>This works well running the development server under my user account. I can add all t...
0
2009-09-23T09:17:44Z
1,844,714
<p>I can't help with the specific problem, but I do know that if I had to work with WMI stuff on Windows, with Python, I would definitely reach for Tim Golden's <a href="http://timgolden.me.uk/python/wmi/index.html" rel="nofollow">Python WMI</a> module instead of pywin32. Perhaps in the documentation/cookbook or Googl...
0
2009-12-04T03:47:13Z
[ "python", "django", "wmi", "pywin32" ]
How can I print only every third index in Perl or Python?
1,464,923
<p>How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array.</p>
5
2009-09-23T09:27:09Z
1,464,942
<p>Python:</p> <pre><code>for x in a[::3]: something(x) </code></pre>
7
2009-09-23T09:30:57Z
[ "python", "arrays", "perl" ]
How can I print only every third index in Perl or Python?
1,464,923
<p>How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array.</p>
5
2009-09-23T09:27:09Z
1,464,951
<p>Python</p> <pre><code>print list[::3] # print it newlist = list[::3] # copy it </code></pre> <p>Perl</p> <pre><code>for ($i = 0; $i &lt; @list; $i += 3) { print $list[$i]; # print it push @y, $list[$i]; # copy it } </code></pre>
11
2009-09-23T09:33:15Z
[ "python", "arrays", "perl" ]
How can I print only every third index in Perl or Python?
1,464,923
<p>How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array.</p>
5
2009-09-23T09:27:09Z
1,464,964
<p>In Perl:</p> <pre><code>$size = @array; for ($i=0; $i&lt;$size; $i+=3) # or start from $i=2, depends what you mean by "every third index" { print "$array[$i] "; } </code></pre>
2
2009-09-23T09:34:57Z
[ "python", "arrays", "perl" ]