title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
python optparse, how to include additional info in usage output?
1,857,346
<p>Using python's optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:</p> <pre><code>usage: check_dell.py [options] options: -h, --help show this help message and exit -s, --storage checks virtual and physical disks -c, --chassis...
23
2009-12-07T01:48:08Z
2,830,216
<p>Another idea on how to do this would be disabling the default behavior for <code>-h</code> and printing your own help screen, which can include the default one:</p> <pre><code>from optparse import OptionParser parser = OptionParser(add_help_option=False, epilog="This can't be easily\n multil...
4
2010-05-13T20:49:19Z
[ "python", "optparse" ]
python optparse, how to include additional info in usage output?
1,857,346
<p>Using python's optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:</p> <pre><code>usage: check_dell.py [options] options: -h, --help show this help message and exit -s, --storage checks virtual and physical disks -c, --chassis...
23
2009-12-07T01:48:08Z
4,882,964
<p>Elaborating on the winning answer (which helped me solve the same problem in my own code), one quick-and-dirty option is to directly override the class's method with an identity method:</p> <pre><code>optparse.OptionParser.format_epilog = lambda self, formatter: self.epilog optparser = optparse.OptionParser(epilog=...
11
2011-02-03T05:54:44Z
[ "python", "optparse" ]
python optparse, how to include additional info in usage output?
1,857,346
<p>Using python's optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:</p> <pre><code>usage: check_dell.py [options] options: -h, --help show this help message and exit -s, --storage checks virtual and physical disks -c, --chassis...
23
2009-12-07T01:48:08Z
22,867,239
<p>I subclassed IndentedHelpFormatter, and it was pretty simple:</p> <pre><code>class PlainHelpFormatter(optparse.IndentedHelpFormatter): def format_description(self, description): if description: return description + "\n" else: return "" def format_epilog(self, epilog):...
0
2014-04-04T15:41:40Z
[ "python", "optparse" ]
How do I break up the controllers (views) into cohesive files in a Django project?
1,857,427
<p>I am currently working through the tutorial on Django's website. Upon completing the following command:</p> <p>python manage.py startapp polls</p> <p>it creates the following structure: </p> <pre><code>polls/ __init__.py models.py tests.py views.py </code></pre> <p>As I was going through the tuto...
1
2009-12-07T02:18:17Z
1,857,445
<p>Each app you create for the project will have its own <code>views.py</code> file (assuming it uses views), so you don't need to worry about it becoming monolithic.</p> <p>Just make sure to keep your apps' functionality focused.</p> <p>From the Django docs:</p> <blockquote> <p>Projects vs. apps</p> <p>What'...
0
2009-12-07T02:24:08Z
[ "python", "django" ]
How do I break up the controllers (views) into cohesive files in a Django project?
1,857,427
<p>I am currently working through the tutorial on Django's website. Upon completing the following command:</p> <p>python manage.py startapp polls</p> <p>it creates the following structure: </p> <pre><code>polls/ __init__.py models.py tests.py views.py </code></pre> <p>As I was going through the tuto...
1
2009-12-07T02:18:17Z
1,857,480
<p>I worked though that tutorial recently. I had figured that most of the "core" logic would go in to various classes or methods in other supporting files. Then the views.py would contain basic calls to setup and execute the methods. </p> <p>Given this design, I'd expect that a single view function might end up with 3...
0
2009-12-07T02:33:15Z
[ "python", "django" ]
How do I break up the controllers (views) into cohesive files in a Django project?
1,857,427
<p>I am currently working through the tutorial on Django's website. Upon completing the following command:</p> <p>python manage.py startapp polls</p> <p>it creates the following structure: </p> <pre><code>polls/ __init__.py models.py tests.py views.py </code></pre> <p>As I was going through the tuto...
1
2009-12-07T02:18:17Z
1,857,487
<p>You could split up views in a similar manner to how this blog entry splits models</p> <p><a href="http://www.nomadjourney.com/2009/11/splitting-up-django-models/" rel="nofollow">http://www.nomadjourney.com/2009/11/splitting-up-django-models/</a></p> <p>eg </p> <pre><code>/myapp * /views o __init__....
2
2009-12-07T02:35:59Z
[ "python", "django" ]
How do I break up the controllers (views) into cohesive files in a Django project?
1,857,427
<p>I am currently working through the tutorial on Django's website. Upon completing the following command:</p> <p>python manage.py startapp polls</p> <p>it creates the following structure: </p> <pre><code>polls/ __init__.py models.py tests.py views.py </code></pre> <p>As I was going through the tuto...
1
2009-12-07T02:18:17Z
1,857,574
<p>The view functions don't have to be in <code>views.py</code>, they can be anywhere, as long as they're mapped properly in <code>urls.py</code>. So it's up to you how you organize your project.</p> <blockquote> <p>but it appears that the script that generates the file structure creates a "views" module when it cre...
1
2009-12-07T03:03:21Z
[ "python", "django" ]
How do I break up the controllers (views) into cohesive files in a Django project?
1,857,427
<p>I am currently working through the tutorial on Django's website. Upon completing the following command:</p> <p>python manage.py startapp polls</p> <p>it creates the following structure: </p> <pre><code>polls/ __init__.py models.py tests.py views.py </code></pre> <p>As I was going through the tuto...
1
2009-12-07T02:18:17Z
1,857,623
<p>One of the things I do to make my apps' views more compact is to factor my views pretty aggressively. I hate writing any code twice, so this comes naturally for me. Anywhere I can, I use a generic view to perform the needed actions. A good percentage of the functionality of my views is decorators, which perform c...
0
2009-12-07T03:18:11Z
[ "python", "django" ]
"Better option" from the python library, any list?
1,857,432
<p>I just found out the existence of the optparse module. I personally always used getopt, so I did not care to look for something better. It's clear, however, that optparse is much more advanced, so I would expect it to be the preferred way in the future to get options from the command line.</p> <p>Anyway, this event...
0
2009-12-07T02:19:13Z
1,857,471
<p>I suggest this might be a good place to start such a list</p> <p>note that there is pep389 to replace optparse with argparse</p> <p><code>collections.defaultdict</code> works nicer in most places you would use <code>dict.setdefault</code> </p> <p>the collections module is a good one to become familiar with as it...
2
2009-12-07T02:31:23Z
[ "python", "command-line-arguments", "argparse", "getopt", "optparse" ]
"Better option" from the python library, any list?
1,857,432
<p>I just found out the existence of the optparse module. I personally always used getopt, so I did not care to look for something better. It's clear, however, that optparse is much more advanced, so I would expect it to be the preferred way in the future to get options from the command line.</p> <p>Anyway, this event...
0
2009-12-07T02:19:13Z
1,857,476
<p>I wouldn't absolutely agree with a statement "<code>optparse</code> is better than <code>getopt</code>". If <code>optparse</code> suites you better, it doesn't mean someone wouldn't find <code>getopt</code> much preferable. They are intended for different purposes: <code>getopt</code> is much simpler and requires le...
0
2009-12-07T02:32:38Z
[ "python", "command-line-arguments", "argparse", "getopt", "optparse" ]
"Better option" from the python library, any list?
1,857,432
<p>I just found out the existence of the optparse module. I personally always used getopt, so I did not care to look for something better. It's clear, however, that optparse is much more advanced, so I would expect it to be the preferred way in the future to get options from the command line.</p> <p>Anyway, this event...
0
2009-12-07T02:19:13Z
1,857,478
<p>Not exactly compact, and referring only to the standard library (and other parts of standard Python) but not any third-party packages, there are all the <a href="http://docs.python.org/dev/whatsnew/index.html" rel="nofollow">"What's New in Python X.X?"</a> essays.</p> <p>Other than that, and Google, I don't think t...
1
2009-12-07T02:33:10Z
[ "python", "command-line-arguments", "argparse", "getopt", "optparse" ]
"Better option" from the python library, any list?
1,857,432
<p>I just found out the existence of the optparse module. I personally always used getopt, so I did not care to look for something better. It's clear, however, that optparse is much more advanced, so I would expect it to be the preferred way in the future to get options from the command line.</p> <p>Anyway, this event...
0
2009-12-07T02:19:13Z
1,857,594
<p>I use Richard Gruet's <a href="http://rgruet.free.fr/PQR26/PQR2.6.html" rel="nofollow">Python Quick Reference</a> which is a great reference for all things Python including some of the more important parts of the standard library. It does a good job of making changes in the language and library prevalent using colou...
0
2009-12-07T03:08:02Z
[ "python", "command-line-arguments", "argparse", "getopt", "optparse" ]
With sqlalchemy how to dynamically bind to database engine on a per-request basis
1,857,465
<p>I have a Pylons-based web application which connects via <a href="http://www.sqlalchemy.org/" rel="nofollow">Sqlalchemy</a> (v0.5) to a Postgres database. For security, rather than follow the typical pattern of simple web apps (as seen in just about all tutorials), I'm not using a generic Postgres user (e.g. "webap...
6
2009-12-07T02:29:48Z
1,857,572
<p>I would look at the connection pooling and see if you can't find a way to have one pool per user. You can <code>dispose()</code> the pool when the user's session has expired</p>
-1
2009-12-07T03:02:22Z
[ "python", "postgresql", "web-applications", "sqlalchemy", "pylons" ]
With sqlalchemy how to dynamically bind to database engine on a per-request basis
1,857,465
<p>I have a Pylons-based web application which connects via <a href="http://www.sqlalchemy.org/" rel="nofollow">Sqlalchemy</a> (v0.5) to a Postgres database. For security, rather than follow the typical pattern of simple web apps (as seen in just about all tutorials), I'm not using a generic Postgres user (e.g. "webap...
6
2009-12-07T02:29:48Z
1,858,010
<p>Binding global objects (mappers, metadata) to user-specific connection is not good way. As well as using scoped session. I suggest to create new session for each request and configure it to use user-specific connections. The following sample assumes that you use separate metadata objects for each database:</p> <pre...
3
2009-12-07T05:29:52Z
[ "python", "postgresql", "web-applications", "sqlalchemy", "pylons" ]
Django - Populating a database for test purposes
1,857,527
<p>I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", fiel...
4
2009-12-07T02:48:13Z
1,857,545
<p>You can use fixtures for this purpose, and the <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/?from=olddocs#loaddata-fixture-fixture" rel="nofollow">loaddata</a> management command.</p> <p>One approach is to do it like this.</p> <ol> <li><p>Prepare your test database.</p></li> <li><p>Use dumpdata t...
4
2009-12-07T02:53:36Z
[ "python", "database", "django" ]
Django - Populating a database for test purposes
1,857,527
<p>I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", fiel...
4
2009-12-07T02:48:13Z
1,857,546
<p>I'm not sure why you require any serialization. As long as you have setup your Django settings.py file to point to your test database, populating a test database should be nothing more than saving models.</p> <pre><code>for x in range(0, 200): m = my_model(title=random_title(), field2=random_string(), ...) ...
0
2009-12-07T02:55:07Z
[ "python", "database", "django" ]
Django - Populating a database for test purposes
1,857,527
<p>I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", fiel...
4
2009-12-07T02:48:13Z
1,857,561
<p>Django <a href="http://www.djangoproject.com/documentation/models/fixtures/" rel="nofollow">fixtures</a> provide a mechanism for importing data on <code>syncdb</code>. However, doing this initial data propagation is often easier via Python code. The technique you outline should work, either via syncdb or a managem...
2
2009-12-07T02:59:10Z
[ "python", "database", "django" ]
Django - Populating a database for test purposes
1,857,527
<p>I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", fiel...
4
2009-12-07T02:48:13Z
1,858,008
<p>Check this app </p> <p><a href="https://github.com/aerosol/django-dilla" rel="nofollow">https://github.com/aerosol/django-dilla/</a></p> <p>Let's say you wrote your blog application (oh yeah, your favorite!) in Django. Unit tests went fine, and everything runs extremely fast, even those ORM-generated ultra-long qu...
7
2009-12-07T05:29:22Z
[ "python", "database", "django" ]
Django - Populating a database for test purposes
1,857,527
<p>I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", fiel...
4
2009-12-07T02:48:13Z
37,124,630
<p>The app recommended by the accepted answer is no longer being maintained however django-seed can be used as a replacement:</p> <p><a href="https://github.com/brobin/django-seed" rel="nofollow">https://github.com/brobin/django-seed</a></p>
0
2016-05-09T20:11:58Z
[ "python", "database", "django" ]
Questionnaire/survey app like Google Form - (python+javascript)
1,857,739
<p>Django-survey or django-questionnaire is too admin-centric for me (beside tied to django). I want my user to create their own survey. Something like Google Form survey (view <a href="http://spreadsheets.google.com/viewform?formkey=dENteVBPMmFiZGFxbm5ZUHFrNFBsRnc6MA" rel="nofollow" title="view example">example</a>), ...
4
2009-12-07T04:03:45Z
1,872,501
<p>Have tried taking a look at <a href="http://code.google.com/appengine/" rel="nofollow">google app engine</a>? It really is not just a survey library, but much much more - and since it gives you Python APIs it probably is not too hard to create a web service that can be used by your users to create new surveys.</p> ...
1
2009-12-09T08:56:29Z
[ "python", "survey" ]
sparse assignment list in python
1,857,780
<p>I need a list with the following behavior</p> <pre><code>&gt;&gt;&gt; l = SparseList() &gt;&gt;&gt; l [] &gt;&gt;&gt; l[2] = "hello" &gt;&gt;&gt; l [ None, None, "hello"] &gt;&gt;&gt; l[5] None &gt;&gt;&gt; l[4] = 22 &gt;&gt;&gt; l [ None, None, "hello", None, 22] &gt;&gt;&gt; len(l) 5 &gt;&gt;&gt; for i in l: prin...
8
2009-12-07T04:20:43Z
1,857,828
<p>You can just copy and paste the code from numpy.</p>
-4
2009-12-07T04:32:29Z
[ "python" ]
sparse assignment list in python
1,857,780
<p>I need a list with the following behavior</p> <pre><code>&gt;&gt;&gt; l = SparseList() &gt;&gt;&gt; l [] &gt;&gt;&gt; l[2] = "hello" &gt;&gt;&gt; l [ None, None, "hello"] &gt;&gt;&gt; l[5] None &gt;&gt;&gt; l[4] = 22 &gt;&gt;&gt; l [ None, None, "hello", None, 22] &gt;&gt;&gt; len(l) 5 &gt;&gt;&gt; for i in l: prin...
8
2009-12-07T04:20:43Z
1,857,860
<p>Here's minimal code to pass your given examples (with indispensable adjustments: you expect weird spacing and quoting, 'None' to be printed out at the prompt without a <code>print</code> statement, etc etc):</p> <pre><code>class SparseList(list): def __setitem__(self, index, value): missing = index - len(self...
16
2009-12-07T04:45:42Z
[ "python" ]
sparse assignment list in python
1,857,780
<p>I need a list with the following behavior</p> <pre><code>&gt;&gt;&gt; l = SparseList() &gt;&gt;&gt; l [] &gt;&gt;&gt; l[2] = "hello" &gt;&gt;&gt; l [ None, None, "hello"] &gt;&gt;&gt; l[5] None &gt;&gt;&gt; l[4] = 22 &gt;&gt;&gt; l [ None, None, "hello", None, 22] &gt;&gt;&gt; len(l) 5 &gt;&gt;&gt; for i in l: prin...
8
2009-12-07T04:20:43Z
14,192,006
<p>Dictionaries can be used as sparse lists. Whilst they will not provide the characteristics you are after (as you are not actually after a sparse list, all the list elements are complete references to None in a dynamically-sized Array), they act as a textbook sparse array.</p> <pre>sparse_vars = [(0,"Hi"),(10000,"By...
0
2013-01-07T08:02:52Z
[ "python" ]
Python proxy checker, change to threaded version
1,857,799
<p>i have some python proxy checker.</p> <p>and to speed up check, i was decided change to multithreaded version,</p> <p>and thread module is first for me, i was tried several times to convert to thread version</p> <p>and look for many info, but it not so much easy for novice python programmer.</p> <p>if anyone can...
1
2009-12-07T04:25:01Z
1,857,892
<p><code>urllib2.install_opener()</code> function installs <em>global</em> opener, i.e. it's not thread safe. So don't use it and call <code>opener.open()</code> method instead of global <code>urllib2.urlopen()</code> function. Also use <code>Queue</code> class from <code>Queue</code> module to hold the list of proxies...
4
2009-12-07T04:56:31Z
[ "python", "multithreading" ]
How to extract every possible values of python Dict's values to list
1,857,820
<pre><code>DICTA={'bw':['BW','VW'],'b':['BB','VV'],'a':['AA']} DICTB={'yn':['$YN','$YNN'],'ye':['$YE','A$Y'],'y':['Y$']} </code></pre> <p>How to extract every possible values of that 2 Dict to</p> <pre><code>["BWYN","VWYN","BBYN","VVYN","AAYN","BWYNN","VWYNN","BBYNN","VVYNN","AAYNN", "BWYE","VWYE","BBYE","VVYE","AAYE...
1
2009-12-07T04:30:09Z
1,857,835
<p>Many possible minor variants on the following fundamental theme:</p> <pre><code>print [y.replace('$', x) for y in (v for y in DICTB.values() for v in y) for x in (v for y in DICTA.values() for v in y) ] </code></pre>
4
2009-12-07T04:35:31Z
[ "python" ]
How to extract every possible values of python Dict's values to list
1,857,820
<pre><code>DICTA={'bw':['BW','VW'],'b':['BB','VV'],'a':['AA']} DICTB={'yn':['$YN','$YNN'],'ye':['$YE','A$Y'],'y':['Y$']} </code></pre> <p>How to extract every possible values of that 2 Dict to</p> <pre><code>["BWYN","VWYN","BBYN","VVYN","AAYN","BWYNN","VWYNN","BBYNN","VVYNN","AAYNN", "BWYE","VWYE","BBYE","VVYE","AAYE...
1
2009-12-07T04:30:09Z
1,857,906
<p>I like to go with <code>itertools</code> myself, but essentially the same as Alex's solution:</p> <pre><code>from itertools import product [ y.replace('$', x) for (x, y) in product(sum(DICTA.values(), []), sum(DICTB.values(), [])) ] </code></pre>
4
2009-12-07T05:02:54Z
[ "python" ]
Flexible numeric string parsing in Python
1,858,117
<p>Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like:</p> <ul> <li>Numbers with commas: 2,147,483,647...
7
2009-12-07T06:06:50Z
1,858,289
<p>I haven't heard of one. Do you know of any such library for any other languages? That way you could leverage their documentation and tests. </p> <p>If you can't find one, write a bunch of testcases, then we can help you fill out the parsing code.</p> <p>Google must have one, try searching for 5.5billion * 10, but...
0
2009-12-07T06:50:22Z
[ "python", "validation", "parsing", "numbers" ]
Flexible numeric string parsing in Python
1,858,117
<p>Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like:</p> <ul> <li>Numbers with commas: 2,147,483,647...
7
2009-12-07T06:06:50Z
1,858,636
<p>It should be pretty straightforward to build one in pyparsing - in fact, one of the tutorial pyparsing projects does some of this (<code>wordsToNum.py</code> on <a href="http://pyparsing.wikispaces.com/Examples" rel="nofollow">this page</a>) does some of it already. You're talking about things that don't really hav...
1
2009-12-07T08:35:05Z
[ "python", "validation", "parsing", "numbers" ]
Flexible numeric string parsing in Python
1,858,117
<p>Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like:</p> <ul> <li>Numbers with commas: 2,147,483,647...
7
2009-12-07T06:06:50Z
1,858,700
<p>If you want to convert "localized" numbers such as the American "2,147,483,647" form, you can use the <code>atof()</code> function from the <a href="http://docs.python.org/library/locale.html" rel="nofollow">locale</a> module. Example:</p> <pre><code>import locale locale.setlocale(locale.LC_NUMERIC, 'en_US') print...
6
2009-12-07T08:49:39Z
[ "python", "validation", "parsing", "numbers" ]
Flexible numeric string parsing in Python
1,858,117
<p>Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like:</p> <ul> <li>Numbers with commas: 2,147,483,647...
7
2009-12-07T06:06:50Z
1,858,981
<p><a href="http://babel.edgewall.org/" rel="nofollow">babel</a> has support for the first case (i18n numbers with commas). Docs: <a href="http://babel.edgewall.org/wiki/ApiDocs/babel.numbers" rel="nofollow">http://babel.edgewall.org/wiki/ApiDocs/babel.numbers</a>.</p> <p>Supporting simple named numbers should not be ...
0
2009-12-07T09:56:48Z
[ "python", "validation", "parsing", "numbers" ]
Bind different ip addresses to urllib2 object in seperate threads
1,858,310
<p>The following code binds specified ip address to socket in main program globally.</p> <pre><code>import socket true_socket = socket.socket def bound_socket(*a, **k): sock = true_socket(*a, **k) sock.bind((sourceIP, 0)) return sock socket.socket = bound_socket </code></pre> <p>Suppose main program has 1...
0
2009-12-07T06:58:58Z
1,858,672
<p>You can define a dictionary mapping thread identifier to IP address or use <code>threading.local()</code> global object to define it per thread:</p> <pre><code>socket_data = threading.local() socket_data = bind_ip = None true_socket = socket.socket def bound_socket(*a, **k): sock = true_socket(*a, **k) if...
1
2009-12-07T08:43:55Z
[ "python", "ip-address", "urllib2" ]
How to pass items as args lists in map?
1,858,720
<p>This is a piece of my code. Lambda accepts 3 parameters, and I wanted to pass them as a tuple of positional arguments, but apparently <code>map</code> supplies them as a single argument.</p> <p>How can I supply those tuples in the bottom as lists of arguments? (I know I can rewrite the lambda, but it will become no...
1
2009-12-07T08:54:26Z
1,858,745
<p>Try putting parens around them</p> <pre><code>adds = map((lambda (j, f, a): j.join([f.format(i) for i in parse.options[a]]) if parse.options[a] else ''), ((' ', ' -not -path "{0}" ', 'exclude'), (' -or ', '-path "{0}"', 'include'))) </code></pre>
3
2009-12-07T09:03:51Z
[ "python", "map", "arguments" ]
How to pass items as args lists in map?
1,858,720
<p>This is a piece of my code. Lambda accepts 3 parameters, and I wanted to pass them as a tuple of positional arguments, but apparently <code>map</code> supplies them as a single argument.</p> <p>How can I supply those tuples in the bottom as lists of arguments? (I know I can rewrite the lambda, but it will become no...
1
2009-12-07T08:54:26Z
1,858,770
<p>One way is to rewrite as a list comprehension:</p> <pre><code>adds = [ j.join([f.format(i) for i in parse.options[a]]) if parse.options[a] else '' for j, f, a in ((' ', ' -not -path "{0}" ', 'exclude'), (' -or ', '-path "{0}"', 'include'))] </code></pre>
1
2009-12-07T09:09:55Z
[ "python", "map", "arguments" ]
How to pass items as args lists in map?
1,858,720
<p>This is a piece of my code. Lambda accepts 3 parameters, and I wanted to pass them as a tuple of positional arguments, but apparently <code>map</code> supplies them as a single argument.</p> <p>How can I supply those tuples in the bottom as lists of arguments? (I know I can rewrite the lambda, but it will become no...
1
2009-12-07T08:54:26Z
1,858,783
<p>The <a href="http://docs.python.org/library/functions.html#map"><code>map()</code></a> description:</p> <blockquote> <p><code>map(function, iterable, ...)</code></p> <p>Apply function to every item of iterable and return a list of the results. <strong>If additional iterable arguments are passed, function mus...
5
2009-12-07T09:13:42Z
[ "python", "map", "arguments" ]
How to pass items as args lists in map?
1,858,720
<p>This is a piece of my code. Lambda accepts 3 parameters, and I wanted to pass them as a tuple of positional arguments, but apparently <code>map</code> supplies them as a single argument.</p> <p>How can I supply those tuples in the bottom as lists of arguments? (I know I can rewrite the lambda, but it will become no...
1
2009-12-07T08:54:26Z
1,858,954
<p>An alternative is to use itertools.starmap which accepts pre-zipped arguments:</p> <pre><code>adds = itertools.starmap((lambda j, f, a: j.join([f.format(i) for i in parse.options[a]]) if parse.options[a] else ''), ((' ', ' -not -path "{0}" ', 'exclude'), (' -or ', '-path "{0}"', 'include'))) </code></pr...
3
2009-12-07T09:51:02Z
[ "python", "map", "arguments" ]
Creating portable Django apps - help needed
1,858,749
<p>I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code.</p> <p>I've disc...
8
2009-12-07T09:04:57Z
1,858,877
<p>The --noreload option will stop Django auto-detecting which modules have changed. I don't know if that will fix it, but it might.</p> <p>Another option (and it's not ideal) is to obscure some of your core functionality by packaging it as a dll, which your plain text code will call.</p>
0
2009-12-07T09:36:58Z
[ "python", "linux", "django", "cherrypy", "software-distribution" ]
Creating portable Django apps - help needed
1,858,749
<p>I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code.</p> <p>I've disc...
8
2009-12-07T09:04:57Z
1,859,033
<p>I suggest you base your distro on <a href="http://ianbicking.org/docs/setuptools-presentation/">setuptools</a> (a tool that enhances the standard Python distro mechanizm <a href="http://docs.python.org/library/distutils.html">distutils</a>).</p> <p>Using setuptools, you should be able to create a Python egg contain...
7
2009-12-07T10:07:08Z
[ "python", "linux", "django", "cherrypy", "software-distribution" ]
Check if key is pressed using python (a daemon in the background)
1,859,049
<p>I've created a python script in which an event needs to be executed each time I press the Super (or WinKey) on my keyboard.</p> <p>How can one achieve this without the python process being "focused" - as it is running in the background waiting for the key to be pressed to execute the event?</p> <p>I've seen a lot ...
3
2009-12-07T10:09:09Z
1,859,608
<p>If you need to work on Linux, I think you need to somehow monitor for X events.</p> <p>You can see all events if you run the command "xev" - so I am sure that X provides an interface to all events. A quick googling finds <a href="http://python-xlib.sourceforge.net/" rel="nofollow">Python X library</a> that probably...
0
2009-12-07T12:07:13Z
[ "python", "daemon", "keypress", "ubuntu-9.10", "binding" ]
Check if key is pressed using python (a daemon in the background)
1,859,049
<p>I've created a python script in which an event needs to be executed each time I press the Super (or WinKey) on my keyboard.</p> <p>How can one achieve this without the python process being "focused" - as it is running in the background waiting for the key to be pressed to execute the event?</p> <p>I've seen a lot ...
3
2009-12-07T10:09:09Z
1,860,125
<p>My previous answer apparently was completely wrong, sorry. I think the correct approach would be to read from /dev/input/event1 (?)</p> <p>This short test showed scancodes for me, even if the terminal did not have focus:</p> <pre><code>from struct import unpack port = open("/dev/input/event1","rb") while 1: ...
2
2009-12-07T13:54:26Z
[ "python", "daemon", "keypress", "ubuntu-9.10", "binding" ]
Check if key is pressed using python (a daemon in the background)
1,859,049
<p>I've created a python script in which an event needs to be executed each time I press the Super (or WinKey) on my keyboard.</p> <p>How can one achieve this without the python process being "focused" - as it is running in the background waiting for the key to be pressed to execute the event?</p> <p>I've seen a lot ...
3
2009-12-07T10:09:09Z
2,573,493
<p>This allows me to get the state of <strong>modifier</strong> keys on my <strong>*nix</strong> system.</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- """OSD Neo2 ======== On screen display for learning the keyboard layout Neo2 Copyright (c) 2009 Martin Zuther (http://www.mzuther.de/) This p...
5
2010-04-04T03:49:37Z
[ "python", "daemon", "keypress", "ubuntu-9.10", "binding" ]
Python: Continuing to next iteration in outer loop
1,859,072
<p>I wanted to know if there are any built-in ways to continue to next iteration in outer loop in python. For example, consider the code:</p> <pre><code>for ii in range(200): for jj in range(200, 400): ...block0... if something: continue ...block1... </code></pre> <p>I want this ...
52
2009-12-07T10:14:11Z
1,859,099
<pre><code>for ii in range(200): for jj in range(200, 400): ...block0... if something: break else: ...block1... </code></pre> <p><code>Break</code> will break the inner loop, and block1 won't be executed (it will run only if the inner loop is exited normally).</p>
71
2009-12-07T10:20:35Z
[ "python", "loops" ]
Python: Continuing to next iteration in outer loop
1,859,072
<p>I wanted to know if there are any built-in ways to continue to next iteration in outer loop in python. For example, consider the code:</p> <pre><code>for ii in range(200): for jj in range(200, 400): ...block0... if something: continue ...block1... </code></pre> <p>I want this ...
52
2009-12-07T10:14:11Z
1,859,147
<p>In other languages you can label the loop and break from the labelled loop. <a href="http://www.python.org/dev/peps/pep-3136/">Python Enhancement Proposal (PEP) 3136 suggested adding these to Python</a> but <a href="http://mail.python.org/pipermail/python-3000/2007-July/008663.html">Guido rejected it</a>:</p> <blo...
18
2009-12-07T10:28:51Z
[ "python", "loops" ]
Python: Continuing to next iteration in outer loop
1,859,072
<p>I wanted to know if there are any built-in ways to continue to next iteration in outer loop in python. For example, consider the code:</p> <pre><code>for ii in range(200): for jj in range(200, 400): ...block0... if something: continue ...block1... </code></pre> <p>I want this ...
52
2009-12-07T10:14:11Z
3,409,911
<p>I think you could do something like this:</p> <pre><code>for ii in range(200): restart = False for jj in range(200, 400): ...block0... if something: restart = True break if restart: continue ...block1... </code></pre>
7
2010-08-04T21:19:55Z
[ "python", "loops" ]
Pygame sprite transformation with interpolation
1,859,125
<p>Im currently working on a Python/Pygame module to wrap some basic sprite animation. Animation in the sense that the image itself is static but I apply <strong>rotation</strong> and <strong>scale</strong> with start and end values with a <strong>sine wave interpolation</strong>. That is, sprite transformation like th...
0
2009-12-07T10:24:50Z
1,860,683
<p>You can transform images by <a href="http://www.pygame.org/docs/ref/transform.html" rel="nofollow">pygame.transform</a>, but interpolation is not included in pygame. </p> <p><a href="http://matthewmarshall.org/projects/rabbyt/" rel="nofollow">Rabbyt</a> provides animation including interpolation, even though I have...
0
2009-12-07T15:26:10Z
[ "python", "animation", "pygame", "sprite", "interpolation" ]
problem with pyglet playing video
1,859,195
<p>I'm new to pyglet and i have a problem with video.. I'm trying to play a video using pyglet .. but instead of playing the video in the window it just exits immediately and terminates .. do you guys have any solution for this problem how can i hold the window to play vedio?? i use windows vista 64x with python 2.5 ...
1
2009-12-07T10:38:17Z
1,860,559
<p>I think calling "pyglet.app.run()" is missing. </p>
0
2009-12-07T15:07:33Z
[ "python", "video", "pyglet" ]
problem with pyglet playing video
1,859,195
<p>I'm new to pyglet and i have a problem with video.. I'm trying to play a video using pyglet .. but instead of playing the video in the window it just exits immediately and terminates .. do you guys have any solution for this problem how can i hold the window to play vedio?? i use windows vista 64x with python 2.5 ...
1
2009-12-07T10:38:17Z
6,080,857
<p>This might be a tad bit late and ironically if you dig around enough in the media_player.py piglet documentation you can piece this all together, but for those of us that spent hours trying to get pygame to play a movie on windows, and hopelessly tried to get pymedia to interface with pygame correctly and get the au...
7
2011-05-21T09:28:44Z
[ "python", "video", "pyglet" ]
Is there a buildout recipe that uses pip but does not install virtualenv?
1,859,421
<p>I would like to use buildout rather than virtualenv. This decision means that I don't want virtualenv to be snuck into my kit, so I am looking for either a way to tell gp.recipe.pip <em>not</em> to install the virtualenv meme virus, or, a way to install packages from git repos for use with django/djangorecipe.</p> ...
1
2009-12-07T11:25:43Z
6,298,659
<p>Sure, You want to use <a href="http://pypi.python.org/pypi/mr.developer">mr.developer</a> in your buildout.</p> <p>Specifically, (taken from the mr.developer page), something like:</p> <pre><code>[buildout] extensions = mr.developer auto-checkout = my.package [sources] my.package = svn http://example.com/svn/my.p...
5
2011-06-09T20:10:56Z
[ "python", "virtualenv", "buildout", "pip" ]
Using Python, how do I get a binary serialization of my Google protobuf message?
1,859,438
<p>I see the function SerializeAsString in the <a href="http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf.message.Message-class.html" rel="nofollow">protobuf Python documentation</a>, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing...
0
2009-12-07T11:29:36Z
1,859,509
<p>It not clear what you want to do:</p> <ol> <li>Do something with the serialized form of an entire message (From the SerializeAsString method). Not sure what you'd want to do with this?</li> <li>Store a byte string inside a protobuf message - just use the <code>bytes</code> type in the .proto file, and a byte string...
0
2009-12-07T11:46:26Z
[ "python", "protocol-buffers" ]
Using Python, how do I get a binary serialization of my Google protobuf message?
1,859,438
<p>I see the function SerializeAsString in the <a href="http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf.message.Message-class.html" rel="nofollow">protobuf Python documentation</a>, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing...
0
2009-12-07T11:29:36Z
1,859,515
<p>I think that strings are the usual way to represent binary data in Python. What do you exactly want to do?</p> <p>[Edit]</p> <p>Have a look at the struct module: <a href="http://docs.python.org/library/struct.html" rel="nofollow">http://docs.python.org/library/struct.html</a></p>
1
2009-12-07T11:47:39Z
[ "python", "protocol-buffers" ]
Using Python, how do I get a binary serialization of my Google protobuf message?
1,859,438
<p>I see the function SerializeAsString in the <a href="http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf.message.Message-class.html" rel="nofollow">protobuf Python documentation</a>, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing...
0
2009-12-07T11:29:36Z
1,860,799
<p>You can use Pythons Strings for getting proto buffers serialized data (doesn't matter how they ware crated - in Python, Java, C++ or any other language).</p> <p>These is line from Pythons version of proto buffers tutorial: <code>address_book.ParseFromString(f.read())</code></p>
0
2009-12-07T15:45:22Z
[ "python", "protocol-buffers" ]
Using Python, how do I get a binary serialization of my Google protobuf message?
1,859,438
<p>I see the function SerializeAsString in the <a href="http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf.message.Message-class.html" rel="nofollow">protobuf Python documentation</a>, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing...
0
2009-12-07T11:29:36Z
2,003,514
<p>Python strings can hold binary data, therefore <code>SerializeAsString</code> returns binary data.</p>
3
2010-01-05T01:13:50Z
[ "python", "protocol-buffers" ]
Using AppEngine XMPP for Client Notifications
1,859,634
<p>I've been looking for a way to tell clients about expired objects and AppEngine's XMPP implementation seems really interesting because it's scalable, should be reliable and can contain up to 100kb of data.</p> <ol> <li><p>But as I understand it, before a client can listen to messages, he should have a gmail account...
1
2009-12-07T12:12:06Z
1,859,647
<ol> <li>No this isn't true: you can have the AppEngine robot as contact over any Jabber/XMPP based networks.</li> </ol> <p>Unless you are talking about the need for a GMAIL account to create an AppEngine robot... in which case YES you need to have a Google account.</p>
1
2009-12-07T12:15:34Z
[ "python", "web-services", "google-app-engine", "xmpp" ]
Using AppEngine XMPP for Client Notifications
1,859,634
<p>I've been looking for a way to tell clients about expired objects and AppEngine's XMPP implementation seems really interesting because it's scalable, should be reliable and can contain up to 100kb of data.</p> <ol> <li><p>But as I understand it, before a client can listen to messages, he should have a gmail account...
1
2009-12-07T12:12:06Z
1,859,664
<p>In that situation, I would perform ajax calls every 5 minutes in example to check it.</p> <p>It's easy to implement and the data exchanged can be reduced to the max (taking advantage of "fast query/response" bonifications of google-app).</p> <p>Regards.</p>
0
2009-12-07T12:19:36Z
[ "python", "web-services", "google-app-engine", "xmpp" ]
Using AppEngine XMPP for Client Notifications
1,859,634
<p>I've been looking for a way to tell clients about expired objects and AppEngine's XMPP implementation seems really interesting because it's scalable, should be reliable and can contain up to 100kb of data.</p> <ol> <li><p>But as I understand it, before a client can listen to messages, he should have a gmail account...
1
2009-12-07T12:12:06Z
1,860,241
<p><a href="http://stackoverflow.com/users/171461/jldupont">jldupont</a> has it right for the first point : any <strong>JID</strong> should work :) </p> <p>For the 2nd point, the only option is probably to set up your own server and allow anonymous access + temporary accounts. </p>
0
2009-12-07T14:18:07Z
[ "python", "web-services", "google-app-engine", "xmpp" ]
Inheritance in Python Such That All Base Functions Are Called
1,859,848
<p>Basically, what I want is to do this:</p> <pre><code>class B: def fn(self): print 'B' class A: def fn(self): print 'A' @extendInherit class C(A,B): pass c=C() c.fn() </code></pre> <p>And have the output be</p> <pre><code>A B </code></pre> <p>How would I implement the extendInherit ...
1
2009-12-07T13:05:05Z
1,859,892
<p>I personally wouldn't try doing this with a decorator since using new-style classes and <code>super()</code>, the following can be achieved:</p> <pre><code>&gt;&gt;&gt; class A(object): ... def __init__(self): ... super(A, self).__init__() ... print "A" ... &gt;&gt;&gt; class B(object): ... ...
1
2009-12-07T13:13:08Z
[ "python", "inheritance", "decorator", "multiple-inheritance" ]
Inheritance in Python Such That All Base Functions Are Called
1,859,848
<p>Basically, what I want is to do this:</p> <pre><code>class B: def fn(self): print 'B' class A: def fn(self): print 'A' @extendInherit class C(A,B): pass c=C() c.fn() </code></pre> <p>And have the output be</p> <pre><code>A B </code></pre> <p>How would I implement the extendInherit ...
1
2009-12-07T13:05:05Z
1,860,594
<p>This is not a job for decorators. You want to completely change the normal behaviour of a class, so this is actually a job for a metaclass.</p> <pre><code>import types class CallAll(type): """ MetaClass that adds methods to call all superclass implementations """ def __new__(meta, clsname, bases, attrs): ...
4
2009-12-07T15:11:41Z
[ "python", "inheritance", "decorator", "multiple-inheritance" ]
Inheritance in Python Such That All Base Functions Are Called
1,859,848
<p>Basically, what I want is to do this:</p> <pre><code>class B: def fn(self): print 'B' class A: def fn(self): print 'A' @extendInherit class C(A,B): pass c=C() c.fn() </code></pre> <p>And have the output be</p> <pre><code>A B </code></pre> <p>How would I implement the extendInherit ...
1
2009-12-07T13:05:05Z
1,861,391
<p>A metaclass is a possible solution, but somewhat complex. <code>super</code> can do it very simply (with new style classes of course: there's no reason to use legacy classes in new code!):</p> <pre><code>class B(object): def fn(self): print 'B' try: super(B, self).fn() except AttributeE...
1
2009-12-07T17:09:47Z
[ "python", "inheritance", "decorator", "multiple-inheritance" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,859,884
<pre><code>&gt;&gt;&gt; a = [0] * 10 &gt;&gt;&gt; a [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] </code></pre>
5
2009-12-07T13:11:35Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,859,886
<pre><code>a = 10 * [0] </code></pre> <p>gives you an array of length 10, filled with zeroes.</p>
1
2009-12-07T13:12:12Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,859,887
<p>two ways:</p> <pre><code>x = [0] * 10 x = [0 for i in xrange(10)] </code></pre> <p>Edit: replaced <code>range</code> by <code>xrange</code> to avoid creating another list.</p> <p>Also: as many others have noted including Pi and Ben James, this creates a <code>list</code>, not a Python array. While a list is in ma...
21
2009-12-07T13:12:31Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,859,889
<p>If you are not satisfied with lists (because they can contain anything and take up too much memory) you can use efficient array of integers:</p> <pre><code>import array array.array('i') </code></pre> <p>See <a href="http://docs.python.org/library/array.html" rel="nofollow">here</a></p> <p>If you need to initializ...
13
2009-12-07T13:12:47Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,859,893
<p>Use the <em>array</em> module. With it you can store collections of the same type efficiently.</p> <pre><code>&gt;&gt;&gt; import array &gt;&gt;&gt; import itertools &gt;&gt;&gt; a = array_of_signed_ints = array.array("i", itertools.repeat(0, 10)) </code></pre> <p>For more information - e.g. different types, look ...
6
2009-12-07T13:13:23Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,860,003
<pre><code>import random def random_zeroes(max_size): "Create a list of zeros for a random size (up to max_size)." a = [] for i in xrange(random.randrange(max_size)): a += [0] </code></pre> <p>Use <code>range</code> instead if you are using Python 3.x.</p>
1
2009-12-07T13:32:57Z
[ "python", "arrays" ]
How to create an integer array in Python?
1,859,864
<p>It should not be so hard. I mean in C, </p> <pre><code>int a[10]; </code></pre> <p>is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module.</p>
15
2009-12-07T13:08:31Z
1,861,331
<p>If you need to initialize an array fast, you might do it by blocks instead of with a generator initializer, and it's going to be much faster. Creating a list by <code>[0]*count</code> is just as fast, still.</p> <pre><code>import array def zerofill(arr, count): count *= arr.itemsize blocksize = 1024 bl...
1
2009-12-07T17:00:46Z
[ "python", "arrays" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,859,872
<p>Quoting <a href="http://en.wikipedia.org/wiki/Jython">Wikipedia</a>:</p> <blockquote> <p>Jython, successor of JPython, is an implementation of the Python programming language written in Java.</p> </blockquote> <p>As for what uses it may have:</p> <blockquote> <p>Jython programs can seamlessly import and use a...
18
2009-12-07T13:10:17Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,859,894
<p>Jython is a Python implementation which runs on top of JVM. Theoretically, Jython is a bit slower, then CPython.</p> <p>You can find some benchmarks here: <a href="http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/" rel="nofollow">http://www....
3
2009-12-07T13:13:23Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,859,951
<p>The JVM does some nice dynamic optimization, but it's probably nothing to get excited about. JRuby sometimes runs faster on the JVM (<a href="http://www.engineyard.com/blog/2009/j-is-for-jvm-why-the-j-in-jruby/" rel="nofollow">http://www.engineyard.com/blog/2009/j-is-for-jvm-why-the-j-in-jruby/</a>) by optimizing th...
0
2009-12-07T13:23:03Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,859,971
<blockquote> <p>When will I need Jython?</p> </blockquote> <p>When you want to program in Python but need (or want) to have the result run on a Java virtual machine, or use existing Java components.</p> <blockquote> <p>What are the drawbacks.</p> </blockquote> <p>Jython may not be 100% compatible with Python, th...
3
2009-12-07T13:25:20Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,860,018
<blockquote> <p>When will I need Jython?</p> </blockquote> <p>For example to add a nice scripting language to your code.</p> <blockquote> <p>What are the drawbacks?</p> </blockquote> <p>The main drawback is that Jython lags behind the official CPython distribution. Currently, you can get a version of Jython that...
3
2009-12-07T13:35:04Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,860,242
<p>Two other reasons:</p> <ul> <li>Embedding scripting into large Java application. </li> <li>Use Java threads to write multi-threaded programs in Jython. </li> </ul>
2
2009-12-07T14:18:14Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,860,474
<p>When will I need Jython?</p> <p>You can write administrative scripts for Websphere application server using Jython. The scripts are used to automate common administrative tasks and configure security in Websphere application server.</p> <p>WebSphere utilizes the JMX API to create MBeans that are exposed as an API ...
1
2009-12-07T14:57:58Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,865,328
<blockquote> <p>When will I need Jython?</p> </blockquote> <p>I need Jython to test JDBC drivers. Some of apps I use work use ODBC, some use JDBC. Using Jython I can test both type of drivers from one Python source (to test ODBC I use JDBC-ODBC bridge).</p>
0
2009-12-08T07:45:21Z
[ "java", "python", "jython" ]
What is Jython and is it useful at all?
1,859,865
<p>I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks.</p>
11
2009-12-07T13:08:40Z
1,872,738
<p>If you know Python and has bought into the "pythonic" way of doing things, then Jython allows you to bring that philosophy to the JVM stack. If you do this, it is much more than just adding scripting capability.</p> <p>In our latest projects, all the custom and business logic is built in Jython, at the same time we...
5
2009-12-09T09:47:13Z
[ "java", "python", "jython" ]
Django search capabilities
1,859,866
<p>Is there a easy way to add a search capability on fields in Django? Also please let me know what is <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow">Lucene</a> search.</p>
1
2009-12-07T13:08:54Z
1,859,904
<ol> <li>Try <a href="http://haystacksearch.org/">Haystack</a>. It's pretty easy to setup.</li> <li><a href="http://lucene.apache.org/java/docs/">Apache Lucene</a> is full-text search engine written in Java.</li> </ol>
6
2009-12-07T13:14:57Z
[ "python", "django" ]
Django search capabilities
1,859,866
<p>Is there a easy way to add a search capability on fields in Django? Also please let me know what is <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow">Lucene</a> search.</p>
1
2009-12-07T13:08:54Z
1,859,992
<p>I second the Haystack suggestion. Here's a <a href="http://ericholscher.com/blog/2009/nov/2/large-problems-django-mostly-solved/" rel="nofollow">good blog post about it</a>. In fact, the entire series—Large Problems in Django, Mostly Solved—is excellent reading. Here's a <a href="http://www.google.com/search?q=L...
1
2009-12-07T13:31:00Z
[ "python", "django" ]
Django search capabilities
1,859,866
<p>Is there a easy way to add a search capability on fields in Django? Also please let me know what is <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow">Lucene</a> search.</p>
1
2009-12-07T13:08:54Z
1,861,217
<p>I would use <a href="http://haystacksearch.org/" rel="nofollow">Haystack</a> as mentioned above together with <a href="http://github.com/notanumber/xapian-haystack" rel="nofollow">Xapian</a>.</p> <p>Xapian doesn't require you to run it as a process (which is some sort of advantage in my opinion).</p>
2
2009-12-07T16:44:16Z
[ "python", "django" ]
Django search capabilities
1,859,866
<p>Is there a easy way to add a search capability on fields in Django? Also please let me know what is <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow">Lucene</a> search.</p>
1
2009-12-07T13:08:54Z
1,862,292
<p>Haystack setup on my blog application took me &lt;30 min as Django newbie. I can strongly recommend it.</p>
0
2009-12-07T19:26:32Z
[ "python", "django" ]
Django search capabilities
1,859,866
<p>Is there a easy way to add a search capability on fields in Django? Also please let me know what is <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow">Lucene</a> search.</p>
1
2009-12-07T13:08:54Z
1,862,704
<p>If your database is MySQL don't underestimate the power of QuerySet's <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#search" rel="nofollow">search</a> method. It uses MySQL's full-text index (assuming you've created one) to do full-text searching. It's the quickest to set up of all the options (...
1
2009-12-07T20:32:39Z
[ "python", "django" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
1,859,972
<p>NOTE - it looks like the question has changed some. The answer to the question of how you call an instance method from a static method is that you can't without passing an instance in as an argument or instantiating that instance inside the static method.</p> <p>What follows is mostly to answer "how do you call a ...
5
2009-12-07T13:25:49Z
[ "python", "static-methods" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
1,859,975
<p><code>class.method</code> should work. </p> <pre><code>class SomeClass: @classmethod def some_class_method(cls): pass @staticmethod def some_static_method(): pass SomeClass.some_class_method() SomeClass.some_static_method() </code></pre>
27
2009-12-07T13:26:39Z
[ "python", "static-methods" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
1,860,024
<p>ok, this is what I have</p> <pre><code>class test2(object): def __init__(self): pass @staticmethod def dosomething(): print "do something" test2.dosomethingelse() def dosomethingelse(self): print "do something else" a = test2 a.dosomething() </code></pre> <p>if I ...
-1
2009-12-07T13:36:22Z
[ "python", "static-methods" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
1,860,427
<p>you cant call non-static methods from static methods but by creating an instance inside the static method.... it should work like that</p> <pre><code>class test2(object): def __init__(self): pass @staticmethod def dosomething(): print "do something" #creating an instance to be a...
2
2009-12-07T14:48:05Z
[ "python", "static-methods" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
1,860,603
<p>ok the main deffirence between class methods and static methods is: class method has its own identity, thats why they have to be called from within an INSTANCE. on the other hand static method can be shared between multiple instances so that it must be called from within THE CLASS</p>
3
2009-12-07T15:13:55Z
[ "python", "static-methods" ]
Python static methods - how to call a method from another method
1,859,959
<p>When I have regular methods for calling another method in a class I have to do this</p> <pre><code>class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" </code></pre> <...
22
2009-12-07T13:23:42Z
4,104,303
<blockquote> <p>How do I have to do in Python for calling an static method from another static method of the same class?</p> </blockquote> <pre><code>class Test() : @staticmethod def static_method_to_call() pass @staticmethod def another_static_method() : Test.static_method_to_call()...
28
2010-11-05T08:08:06Z
[ "python", "static-methods" ]
Need help understanding how this recursive function is working
1,860,049
<p>Here's a function (credit to user Abbot, for providing it in another question)</p> <pre><code>def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level </code></pre...
2
2009-12-07T13:40:47Z
1,860,074
<p><code>level</code> is a local variable. Every "run" of the function has its own variable called <code>level</code>, so the variables don't interfere with each other.</p>
1
2009-12-07T13:45:41Z
[ "python", "recursion" ]
Need help understanding how this recursive function is working
1,860,049
<p>Here's a function (credit to user Abbot, for providing it in another question)</p> <pre><code>def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level </code></pre...
2
2009-12-07T13:40:47Z
1,860,089
<p>The scope of <code>level</code> is limited to the function only. Even if a function calls itself, it doesn't mean that <em>that</em> function call's internal variables (a <em>different</em> <code>level</code>) is the same as <em>this</em> one's.</p>
1
2009-12-07T13:47:29Z
[ "python", "recursion" ]
Need help understanding how this recursive function is working
1,860,049
<p>Here's a function (credit to user Abbot, for providing it in another question)</p> <pre><code>def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level </code></pre...
2
2009-12-07T13:40:47Z
1,860,090
<p>variable <code>level</code> exists only in the scope of a function, at the end of function local variables discarded, so for each execution of <code>traverse</code> there will be it's own <code>level</code> dictionary. Nothing will be re-written or over-written.</p>
1
2009-12-07T13:47:44Z
[ "python", "recursion" ]
Need help understanding how this recursive function is working
1,860,049
<p>Here's a function (credit to user Abbot, for providing it in another question)</p> <pre><code>def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level </code></pre...
2
2009-12-07T13:40:47Z
1,860,137
<p>No. Every "instance" of the function has its own copy of <code>level</code> and there are no side effects between the various copies of <code>level</code>.</p> <p>Take this folder tree:</p> <pre><code>root `-home |- lyrae | |- ftp.py | `- http.py `- badp </code></pre> <p>Here's the (simplifie...
7
2009-12-07T13:57:23Z
[ "python", "recursion" ]
Need help understanding how this recursive function is working
1,860,049
<p>Here's a function (credit to user Abbot, for providing it in another question)</p> <pre><code>def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level </code></pre...
2
2009-12-07T13:40:47Z
1,860,148
<p>These other answers don't quite explain enough I think. Each recursive entrance into this function creates a new local level dictionary. But crucially, also returns it. This means that the local version of level from each recursion becomes a dictionary tree of levels. Once the recursion is unrolled you're left w...
2
2009-12-07T13:59:53Z
[ "python", "recursion" ]
How do I read binary C++ protobuf data using Python protobuf?
1,860,187
<p>The Python version of Google protobuf gives us only:</p> <pre><code>SerializeAsString() </code></pre> <p>Where as the C++ version gives us both:</p> <pre><code>SerializeToArray(...) SerializeAsString() </code></pre> <p>We're writing to our C++ file in binary format, and we'd like to keep it this way. That said, ...
2
2009-12-07T14:07:06Z
1,860,275
<p>I'm not an expert with Python, but you can pass the result of a <code>file.read()</code> operation into <code>message.ParseFromString(...)</code> without having to build a new string type or anything.</p>
4
2009-12-07T14:23:20Z
[ "c++", "python", "protocol-buffers" ]
How do I read binary C++ protobuf data using Python protobuf?
1,860,187
<p>The Python version of Google protobuf gives us only:</p> <pre><code>SerializeAsString() </code></pre> <p>Where as the C++ version gives us both:</p> <pre><code>SerializeToArray(...) SerializeAsString() </code></pre> <p>We're writing to our C++ file in binary format, and we'd like to keep it this way. That said, ...
2
2009-12-07T14:07:06Z
1,860,296
<p>Python strings can contain any character, i.e. they are capable of holding "binary" data directly. There should be no need to convert from string to "binary".</p>
4
2009-12-07T14:27:08Z
[ "c++", "python", "protocol-buffers" ]
rdflib graph not updated. Why?
1,860,282
<p>I am trying to understand this behavior. It's definitely not what I expect. I have two programs, one reader, and one writer. The reader opens a RDFlib graph store, then performs a query every 2 seconds</p> <pre><code>import rdflib import random from rdflib import store import time default_graph_uri = "urn:uuid:a19...
2
2009-12-07T14:24:21Z
1,861,975
<p>One easy fix is to put "graph.commit()" just after the line "graph = rdflib.ConjunctiveGraph(...)" in reader. I'm not sure what's the cause and why commiting before read fixes this. I'm <em>guessing</em> that:</p> <ul> <li>When opening MySQLdb connection, a transaction is started automatically</li> <li>This transac...
3
2009-12-07T18:32:16Z
[ "python", "rdf", "rdflib" ]
Virtualenv: global site-packages vs the site-packages in the virtual environment
1,860,348
<ol> <li>If I have a certain package installed both in the global site-packages and in the local one, which package will get imported? Will that even work or will I get an error?</li> <li>Which packages should I put in the global site-packages and which in the local one?</li> </ol>
7
2009-12-07T14:35:10Z
1,860,614
<p>Newly created virtual environment by default have access to global site-packages directory, unless created with --no-site-packages. Calling easy_install (installing new packages) with certain environment activated will cause local overwrite of already existing ones in global site-packages (similar to inheritance). E...
3
2009-12-07T15:15:14Z
[ "python", "virtualenv" ]
Virtualenv: global site-packages vs the site-packages in the virtual environment
1,860,348
<ol> <li>If I have a certain package installed both in the global site-packages and in the local one, which package will get imported? Will that even work or will I get an error?</li> <li>Which packages should I put in the global site-packages and which in the local one?</li> </ol>
7
2009-12-07T14:35:10Z
1,861,734
<p>The previous answer wraps up question 1 but ignores question 2.</p> <p>The general best practice I've seen for which packages to put globally: </p> <p>First, the core Python packages, as these don't change with backwards-incompatible issues unless you're upgrading a major version, and you'll want whatever security...
9
2009-12-07T17:56:11Z
[ "python", "virtualenv" ]
How do I distinguish "module not found" from "module threw exception" on ImportError?
1,860,363
<p>In Python, <code>import does_not_exist</code> raises <code>ImportError</code>, and</p> <pre><code>import exists </code></pre> <p><code>exists.py</code>:</p> <pre><code>import does_not_exist </code></pre> <p>will also raise <code>ImportError</code>.</p> <p>How should I tell the difference in code?</p>
1
2009-12-07T14:38:21Z
1,860,398
<p>The only method I know is to check if the toplevel modulename "exists" is in the Exception's message or not:</p> <pre><code>try: import exists except ImportError as exc: if "exists" in str(exc): pass else: raise </code></pre> <p>Could this be a feature request for Python's ImportError? Having a var...
3
2009-12-07T14:43:14Z
[ "python", "importerror" ]
How do I distinguish "module not found" from "module threw exception" on ImportError?
1,860,363
<p>In Python, <code>import does_not_exist</code> raises <code>ImportError</code>, and</p> <pre><code>import exists </code></pre> <p><code>exists.py</code>:</p> <pre><code>import does_not_exist </code></pre> <p>will also raise <code>ImportError</code>.</p> <p>How should I tell the difference in code?</p>
1
2009-12-07T14:38:21Z
1,860,554
<p>You can use the tb_next of the traceback. It will be different from None if the exception occured on another module</p> <pre><code>import sys try: import exists except Exception, e: print "None on exists", sys.exc_info()[2].tb_next == None try: import notexists except Exception, e: print "None on n...
2
2009-12-07T15:07:24Z
[ "python", "importerror" ]
Text extraction from email in Python
1,860,375
<p>My users will send me posts by email ala <a href="http://www.posterous.com" rel="nofollow">Posterous</a></p> <p>I'm using Google Apps Engine (GAE) to receive and parse emails. GAE returns the text part of the message.</p> <p>I need to extract the post from the plain text part of the message.</p> <p>The plain text...
1
2009-12-07T14:40:14Z
1,863,329
<p>I would go with a list of compiled regular expressions. Something along the lines of: </p> <pre><code>import re regexes = ( re.compile("visit my blog at: .*$", re.IGNORECASE), re.compile("please post this:", re.IGNORECASE), re.compile("please can you include this:", re.IGNORECASE) # etc ) for file...
2
2009-12-07T22:22:21Z
[ "python", "regex", "google-app-engine", "email" ]
Using Google App Engine to display a Rss/Atom feed
1,860,407
<p>Im thinking of setting up a <strong>Google App that simply displays an RSS or Atom feed</strong>. The idea is that every once in a while (a cron job or at the push of a magic button) the feed is read and copied into the apps internal data, ready to be viewed. This would be done in Python.</p> <p>I found <a href="ht...
2
2009-12-07T14:44:16Z
1,860,555
<p>What about using an additional library, like for instance <a href="http://www.feedparser.org/" rel="nofollow">Feedparser</a>?</p>
0
2009-12-07T15:07:30Z
[ "python", "google-app-engine", "rss", "atom", "feed" ]
Using Google App Engine to display a Rss/Atom feed
1,860,407
<p>Im thinking of setting up a <strong>Google App that simply displays an RSS or Atom feed</strong>. The idea is that every once in a while (a cron job or at the push of a magic button) the feed is read and copied into the apps internal data, ready to be viewed. This would be done in Python.</p> <p>I found <a href="ht...
2
2009-12-07T14:44:16Z
1,867,937
<p>One option is to use the <a href="http://www.feedparser.org/" rel="nofollow">universal feed parser</a> library, which will take care of most of these issues for you. Another option would be to use a PubSubHubbub-powered service such as <a href="http://superfeedr.com/" rel="nofollow">Superfeedr</a>, which will POST u...
3
2009-12-08T16:05:13Z
[ "python", "google-app-engine", "rss", "atom", "feed" ]
Unable to get Wacom events from /dev/input/event*
1,860,668
<p>I have created a pygtk program to monitor the keyboard status and mouse clicks across any application (i.e. not just for my application). This uses evdev by Micah Dowty which basically monitors /dev/input/event* for output and decodes the information in a way that I can display the information to the user.</p> <p>T...
0
2009-12-07T15:24:18Z
5,188,461
<p>This is due to X that take the full control of your input device, you can't read event yourself. You might have one of theses 2 issues :</p> <ol> <li><p>A "catchall" is actually getting your device. In your /var/log/Xorg.0.log, you should see a line like :</p> <p>Stantum MTP USB Controller: Applying InputClass "ev...
0
2011-03-04T00:49:42Z
[ "python", "linux", "pygtk", "wacom" ]