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
Python: what kind of literal delimiter is "better" to use?
1,312,940
<p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p> <p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
2
2009-08-21T16:26:42Z
1,312,983
<p>Semantically there is no difference in Python; use either. Python also provides the handy triple string delimiter """ or ''' which can simplify multi-line quotes. There is also the raw string literal (r"..." or r'...') to inhibit \ escapes. The <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#str...
3
2009-08-21T16:35:00Z
[ "python", "string" ]
Python: what kind of literal delimiter is "better" to use?
1,312,940
<p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p> <p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
2
2009-08-21T16:26:42Z
1,313,334
<p>Other answers are about nested quoting. Another point of view I've come across, but I'm not sure I subscribe to, is to use single-quotes(') for characters (which are strings, but ord/chr are quick picky) and to use double-quotes for strings. Which disambiguates between a string that is supposed to be one character a...
0
2009-08-21T17:49:58Z
[ "python", "string" ]
Python: what kind of literal delimiter is "better" to use?
1,312,940
<p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p> <p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
2
2009-08-21T16:26:42Z
1,314,042
<p>This is a rule I have heard about:</p> <p>") If the string is for human consuption, that is interface text or output, use ""</p> <p>') If the string is a specifier, like a dictionary key or an option, use ''</p> <p>I think a well-enforced rule like that can make sense for a project, but it's nothing that I would ...
0
2009-08-21T20:24:54Z
[ "python", "string" ]
Python: what kind of literal delimiter is "better" to use?
1,312,940
<p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p> <p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
2
2009-08-21T16:26:42Z
1,314,065
<p>I don't think there is a single best string delimiter. I like to use different delimiters to indicate different kinds of string. Specifically, I like to use <code>"..."</code> to delimit stings that are used for interpolation or that are natural language messages, and <code>'...'</code> to delimit small symbol-like...
0
2009-08-21T20:32:07Z
[ "python", "string" ]
Inserting python tuple in a MySQL database
1,313,000
<p>I need to insert a python tuple (of floats) into a MySQL database. In principle I could pickle it and insert it as a string, but that would grant me the chance only to retrieve it through python. Alternative is to serialize the tuple to XML and store the XML string.</p> <p>What solutions do you think would be also ...
0
2009-08-21T16:39:03Z
1,313,012
<p>How about <a href="http://www.json.org/" rel="nofollow" title="JSON">JSON</a> ... it's compact, and there are interpreters available for it in most languages.</p>
2
2009-08-21T16:42:59Z
[ "python", "mysql" ]
Inserting python tuple in a MySQL database
1,313,000
<p>I need to insert a python tuple (of floats) into a MySQL database. In principle I could pickle it and insert it as a string, but that would grant me the chance only to retrieve it through python. Alternative is to serialize the tuple to XML and store the XML string.</p> <p>What solutions do you think would be also ...
0
2009-08-21T16:39:03Z
1,313,013
<p>Make another table and do one-to-many. Don't try to cram a programming language feature into a database as-is if you can avoid it.</p> <p>If you absolutely need to be able to store an object down the line, your options are a bit more limited. YAML is probably the best balance of human-readable and program-readabl...
3
2009-08-21T16:43:15Z
[ "python", "mysql" ]
Inserting python tuple in a MySQL database
1,313,000
<p>I need to insert a python tuple (of floats) into a MySQL database. In principle I could pickle it and insert it as a string, but that would grant me the chance only to retrieve it through python. Alternative is to serialize the tuple to XML and store the XML string.</p> <p>What solutions do you think would be also ...
0
2009-08-21T16:39:03Z
1,313,016
<p>I'd look at serializing it to JSON, using the simplejson package, or the built-in json package in python 2.6.</p> <p>It's simple to use in python, importable by practically every other language, and you don't have to make all of the "what tag should I use? what attributes should this have?" decisions that you might...
2
2009-08-21T16:44:01Z
[ "python", "mysql" ]
Porting python app to mobile platforms
1,313,164
<p>I have a python app running fine on Windows, Linux and Mac which I would like to port to multiple mobile platforms such as Blackberry, Windows Mobile, Palm, Android and iPhone.</p> <p>I have couple of ideas:</p> <ul> <li>port app to platform supporting some kind of Python like Android and Windows Mobile</li> <li>p...
3
2009-08-21T17:13:00Z
1,313,192
<p><a href="http://www.velocityreviews.com/forums/t321090-jython-and-j2me.html" rel="nofollow">Jython is out of the question</a>, so either go with supported phones (Windows Mobile, Android, Nokia S60), or rewrite in J2ME.</p>
1
2009-08-21T17:17:27Z
[ "python", "mobile", "porting" ]
Porting python app to mobile platforms
1,313,164
<p>I have a python app running fine on Windows, Linux and Mac which I would like to port to multiple mobile platforms such as Blackberry, Windows Mobile, Palm, Android and iPhone.</p> <p>I have couple of ideas:</p> <ul> <li>port app to platform supporting some kind of Python like Android and Windows Mobile</li> <li>p...
3
2009-08-21T17:13:00Z
1,313,234
<p>Here's what we're doing ...</p> <p>Make the app a generic web application/website. Host it on your server and have your server detect the type of browser. If it is a mobile browser, show the small-screen version of your app.</p> <p>Once you get that going, create individual apps for the particular phones/mobile ...
4
2009-08-21T17:27:11Z
[ "python", "mobile", "porting" ]
Porting python app to mobile platforms
1,313,164
<p>I have a python app running fine on Windows, Linux and Mac which I would like to port to multiple mobile platforms such as Blackberry, Windows Mobile, Palm, Android and iPhone.</p> <p>I have couple of ideas:</p> <ul> <li>port app to platform supporting some kind of Python like Android and Windows Mobile</li> <li>p...
3
2009-08-21T17:13:00Z
1,313,264
<p>Use JavaScript with <a href="http://www.appcelerator.com/products/titanium-mobile/" rel="nofollow">Titanium Mobile</a> to target iPhone and Android, and the Pre in the future. It compiles into native applications.</p>
0
2009-08-21T17:33:06Z
[ "python", "mobile", "porting" ]
Porting python app to mobile platforms
1,313,164
<p>I have a python app running fine on Windows, Linux and Mac which I would like to port to multiple mobile platforms such as Blackberry, Windows Mobile, Palm, Android and iPhone.</p> <p>I have couple of ideas:</p> <ul> <li>port app to platform supporting some kind of Python like Android and Windows Mobile</li> <li>p...
3
2009-08-21T17:13:00Z
1,313,550
<p>Use <a href="http://rhomobile.com/" rel="nofollow">RhoMobile's Rhodes</a>. Allows you to write the app in Ruby once and run it in multiple mobile platforms: iPhone, Symbian, Android, BlackBerry, and Windows Mobile.</p>
2
2009-08-21T18:26:19Z
[ "python", "mobile", "porting" ]
Django without additional tables?
1,313,362
<p>is it possible to write Django apps, for example for internal/personal use with existing databases, without having the 'overhead' of Djangos own tables that are usually installed when starting a project ? I would like to use existing tables via models, but not have all the other stuff that is surely useful on normal...
1
2009-08-21T17:56:13Z
1,313,406
<p>Django doesn't install any tables by itself. It comes with some pre-fabricated applications, which install tables, but those are easily disabled by removing them from the <code>INSTALLED_APPS</code> setting.</p>
3
2009-08-21T18:03:50Z
[ "python", "database", "django", "table" ]
Django without additional tables?
1,313,362
<p>is it possible to write Django apps, for example for internal/personal use with existing databases, without having the 'overhead' of Djangos own tables that are usually installed when starting a project ? I would like to use existing tables via models, but not have all the other stuff that is surely useful on normal...
1
2009-08-21T17:56:13Z
1,313,575
<p>Don't install any of Django's built-in apps and don't use any <code>models.py</code> in your apps. Your database will have zero tables in it.</p> <p>You won't have users, sites or sessions -- those are Django features that use the database.</p> <p>AFAIK you should still, however, have a SQLite database. I think ...
0
2009-08-21T18:32:33Z
[ "python", "database", "django", "table" ]
Django without additional tables?
1,313,362
<p>is it possible to write Django apps, for example for internal/personal use with existing databases, without having the 'overhead' of Djangos own tables that are usually installed when starting a project ? I would like to use existing tables via models, but not have all the other stuff that is surely useful on normal...
1
2009-08-21T17:56:13Z
1,313,592
<p>The most noticable app with database tables defined is <code>django.contrib.auth</code>, which implements its own auth backend in the database. You could probably skip auth all together if your app is firewalled and you trust all the people that have access to it. If otherwise, you want to create your own auth mec...
1
2009-08-21T18:36:11Z
[ "python", "database", "django", "table" ]
Django without additional tables?
1,313,362
<p>is it possible to write Django apps, for example for internal/personal use with existing databases, without having the 'overhead' of Djangos own tables that are usually installed when starting a project ? I would like to use existing tables via models, but not have all the other stuff that is surely useful on normal...
1
2009-08-21T17:56:13Z
1,315,203
<p>Just commentize the <em>django</em> app strings of the INSTALLED_APPS tuple in your project settings.py file (at the beginning of the project, before running syncdb).</p>
0
2009-08-22T05:18:26Z
[ "python", "database", "django", "table" ]
Django without additional tables?
1,313,362
<p>is it possible to write Django apps, for example for internal/personal use with existing databases, without having the 'overhead' of Djangos own tables that are usually installed when starting a project ? I would like to use existing tables via models, but not have all the other stuff that is surely useful on normal...
1
2009-08-21T17:56:13Z
3,186,831
<p>You can also just add an extra database (set it as default) for keeping the extra django overhead stuff in:</p> <pre><code>DATABASES = { 'default': { 'ENGINE' : 'django.db.backends.sqlite', 'NAME' : 'djangoOverhead', 'USER' : '', 'PASSWORD' : '', ...
2
2010-07-06T13:57:26Z
[ "python", "database", "django", "table" ]
Where is the best place to put cache-evicting logic in an AppEngine application?
1,313,626
<p>I've written an application for Google AppEngine, and I'd like to make use of the memcache API to cut down on per-request CPU time. I've profiled the application and found that a large chunk of the CPU time is in template rendering and API calls to the datastore, and after chatting with a co-worker I jumped (perhaps...
2
2009-08-21T18:44:29Z
1,314,437
<p>I've got just such a decorator up in an open source Github project:</p> <p><a href="http://github.com/jamslevy/gae%5Fmemoize/tree/master" rel="nofollow">http://github.com/jamslevy/gae%5Fmemoize/tree/master</a></p> <p>It's a bit more in-depth, allowing for things like forcing execution of the function (when you wan...
1
2009-08-21T22:13:02Z
[ "python", "google-app-engine", "optimization", "caching", "memcached" ]
Where is the best place to put cache-evicting logic in an AppEngine application?
1,313,626
<p>I've written an application for Google AppEngine, and I'd like to make use of the memcache API to cut down on per-request CPU time. I've profiled the application and found that a large chunk of the CPU time is in template rendering and API calls to the datastore, and after chatting with a co-worker I jumped (perhaps...
2
2009-08-21T18:44:29Z
1,348,633
<p>A couple of alternatives to regular eviction:</p> <ol> <li>The obvious one: Don't evict, and set a timer instead. Even a really short one - a few seconds - can cut down on effort a huge amount for a popular app, without users even noticing data may be a few seconds stale.</li> <li>Instead of evicting, generate the ...
1
2009-08-28T18:29:13Z
[ "python", "google-app-engine", "optimization", "caching", "memcached" ]
Parsing FLV header (duration) of remote file in Java
1,313,640
<p>I'm looking for an example of parsing an FLV header for duration specifically in Java. Given the URL of an FLV file I want to download the header only and parse out the duration. I have the FLV spec but I want an example. Python or PHP would be OK too but Java is preferred.</p>
5
2009-08-21T18:47:56Z
1,314,739
<p>Do you have problems downloading the header or parsing it? if it's downloading then use this code:</p> <pre><code>URL url = new URL(fileUrl); InputStream dis = url.openStream(); byte[] header = new byte[HEADER_SIZE]; dis.read(header); </code></pre> <p>You can wrap InputStream with DataInputStream if you want to re...
1
2009-08-22T00:15:51Z
[ "java", "python", "flash", "flv" ]
Parsing FLV header (duration) of remote file in Java
1,313,640
<p>I'm looking for an example of parsing an FLV header for duration specifically in Java. Given the URL of an FLV file I want to download the header only and parse out the duration. I have the FLV spec but I want an example. Python or PHP would be OK too but Java is preferred.</p>
5
2009-08-21T18:47:56Z
3,670,931
<p>As <a href="http://stackoverflow.com/users/423943/the-alchemist">the-alchemist</a> states in <a href="http://stackoverflow.com/questions/3669109/how-to-get-flv-duration-in-java">this other question</a>:</p> <blockquote> <p>The <a href="https://code.google.com/p/red5/" rel="nofollow">Red5 project</a> has a class c...
0
2010-09-08T18:44:44Z
[ "java", "python", "flash", "flv" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,809
<p>Its a list with a single tuple.</p>
14
2009-08-21T19:28:11Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,814
<p>Yes, it's a <a href="http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences" rel="nofollow">tuple</a>.</p> <p>They look like this:</p> <pre><code>() (foo,) (foo, bar) (foo, bar, baz) </code></pre> <p>etc.</p>
1
2009-08-21T19:28:40Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,816
<p>That's a list of tuples.</p> <p>This is a list of integers: <code>[1, 2, 3, 4, 5]</code></p> <p>This is also a list of integers: <code>[1]</code></p> <p>This is a (string, integer) tuple: <code>("hello world", 42)</code></p> <p>This is a list of (string, integer) tuples: <code>[("a", 1), ("b", 2), ("c", 3)]</cod...
2
2009-08-21T19:29:15Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,820
<pre><code>[('/', MainPage)] </code></pre> <p>That's a list consisting of a two element tuple.</p> <pre><code>() </code></pre> <p>That's a zero element tuple.</p>
1
2009-08-21T19:30:02Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,851
<p>Note that this:</p> <pre><code>("is not a tuple") </code></pre> <p>A tuple is defined by the commas, except in the case of the zero-length tuple. This:</p> <pre><code>"is a tuple", </code></pre> <p>because of the comma at the end. The parentheses just enforce grouping (again, except in the case of a zero-lengt...
3
2009-08-21T19:35:32Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,900
<p>It is a list of tuple(s). You can verify that by</p> <pre><code>x=[('/', MainPage)] print type(x) # You will find a &lt;list&gt; type here print type(x[0]) # You will find a &lt;tuple&gt; type here </code></pre> <p>You can build a dictionary from this type of structure (may be more tuple inside the list) with this...
1
2009-08-21T19:45:46Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,313,925
<p>It is a list of tuples containing one tuple.</p> <p>A tuple is just like a list except that it is immutable, meaning that it can't be changed once it's created. You can't add, remove, or change elements in a tuple. If you want your tuple to be different, you have to create a new tuple with the new data. This may...
0
2009-08-21T19:51:41Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,315,047
<p>Since no one has answered this bit yet:</p> <blockquote> <p>A tuple? ( or whatever they call it? ) </p> </blockquote> <p>The word "tuple" comes from maths. In maths, we might talk about (ordered) pairs, if we're doing 2d geometry. Moving to three dimensions means we need triples. In higher dimensions, we need...
6
2009-08-22T03:32:19Z
[ "python" ]
What is this construct called in python: ( x, y )
1,313,805
<p>What is this called in python:</p> <pre><code>[('/', MainPage)] </code></pre> <p>Is that an array .. of ... erhm one dictionary? </p> <p>Is that</p> <pre><code>() </code></pre> <p>A tuple? ( or whatever they call it? ) </p>
5
2009-08-21T19:27:03Z
1,737,602
<p>It's a <em>list</em> of just one <em>tuple</em>. That tuple has two elements, a string and the object <code>MainPage</code> whatever it is.</p> <p>Both <em>lists</em> and <em>tuples</em> are ordered groups of object, it doesn't matter what kind of object, they can be heterogeneous in both cases.</p> <p>The main di...
0
2009-11-15T14:07:59Z
[ "python" ]
Raise exception vs. return None in Python functions
1,313,812
<p>What's better practice in a user-defined function in Python: raise an exception or return None? For example, I have a function that finds the most recent file in a folder.</p> <pre><code>def latestpdf(folder): # list the files and sort them try: latest = files[-1] except IndexError: # F...
44
2009-08-21T19:28:19Z
1,313,837
<p>It's really a matter of semantics. What does <code>foo = latestpdf(d)</code> <em>mean</em>?</p> <p>Is it perfectly reasonable that there's no latest file? Then sure, just return None.</p> <p>Are you expecting to always find a latest file? Raise an exception. And yes, re-raising a more appropriate exception is ...
53
2009-08-21T19:34:06Z
[ "python", "exception-handling" ]
Raise exception vs. return None in Python functions
1,313,812
<p>What's better practice in a user-defined function in Python: raise an exception or return None? For example, I have a function that finds the most recent file in a folder.</p> <pre><code>def latestpdf(folder): # list the files and sort them try: latest = files[-1] except IndexError: # F...
44
2009-08-21T19:28:19Z
1,313,838
<p>In general, I'd say an exception should be thrown if something catastrophic has occured that cannot be recovered from (i.e. your function deals with some internet resource that cannot be connected to), and you should return None if your function should really return something but nothing would be appropriate to retu...
0
2009-08-21T19:34:15Z
[ "python", "exception-handling" ]
Raise exception vs. return None in Python functions
1,313,812
<p>What's better practice in a user-defined function in Python: raise an exception or return None? For example, I have a function that finds the most recent file in a folder.</p> <pre><code>def latestpdf(folder): # list the files and sort them try: latest = files[-1] except IndexError: # F...
44
2009-08-21T19:28:19Z
1,313,956
<p>I usually prefer to handle exceptions internally (i.e. try/except inside the called function, possibly returning a None) because python is dynamically typed. In general, I consider it a judgment call one way or the other, but in a dynamically typed language, there are small factors that tip the scales in favor of n...
2
2009-08-21T19:59:20Z
[ "python", "exception-handling" ]
Raise exception vs. return None in Python functions
1,313,812
<p>What's better practice in a user-defined function in Python: raise an exception or return None? For example, I have a function that finds the most recent file in a folder.</p> <pre><code>def latestpdf(folder): # list the files and sort them try: latest = files[-1] except IndexError: # F...
44
2009-08-21T19:28:19Z
1,314,026
<p>I would make a couple suggestions before answering your question as it may answer the question for you.</p> <ul> <li>Always name your functions descriptive. <code>latestpdf</code> means very little to anyone but looking over your function <code>latestpdf()</code> gets the latest pdf. I would suggest that you name...
4
2009-08-21T20:20:00Z
[ "python", "exception-handling" ]
If I have the contents of a zipfile in a Python string, can I decompress it without writing it to a file?
1,313,845
<p>I've written some Python code that fetches a zip file from the web and into a string:</p> <pre><code>In [1]: zip_contents[0:5] Out[1]: 'PK\x03\x04\x14' </code></pre> <p>I see there's a zipfile library, but I'm having trouble finding a function in it that I can just pass a bunch of raw zip data. It seems to want to...
12
2009-08-21T19:35:05Z
1,313,867
<p>Wrap your string in a <a href="http://docs.python.org/library/stringio.html#module-cStringIO">cStringIO</a> object. It looks, acts, and quacks like a file object, but resides in memory.</p>
5
2009-08-21T19:37:29Z
[ "python" ]
If I have the contents of a zipfile in a Python string, can I decompress it without writing it to a file?
1,313,845
<p>I've written some Python code that fetches a zip file from the web and into a string:</p> <pre><code>In [1]: zip_contents[0:5] Out[1]: 'PK\x03\x04\x14' </code></pre> <p>I see there's a zipfile library, but I'm having trouble finding a function in it that I can just pass a bunch of raw zip data. It seems to want to...
12
2009-08-21T19:35:05Z
1,313,868
<p><code>zipfile.ZipFile</code> accepts any file-like object, so you can use <code>StringIO</code> (2.x) or <code>BytesIO</code> (3.x):</p> <pre><code>try: from cStringIO import StringIO except: from StringIO import StringIO import zipfile fp = StringIO('PK\x03\x04\x14') zfp = zipfile.ZipFile(fp, "r") </code></pr...
23
2009-08-21T19:37:45Z
[ "python" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,005
<p>You didn't have to do anything when deploying a PHP site because your hosting provider had already installed it. Web hosts which support Django typically install and configure it for you.</p>
1
2009-08-21T20:14:52Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,019
<p><strong>Can the deployment process of django project be made easier?</strong></p> <p>No. You can script some of this, if you want. However, you're never going to install MySQL, MySQLPuthon, mod_wsgi (or mod_python), or Django again.</p> <p>You will, however, tweak your application all the time.</p> <p><strong>A...
3
2009-08-21T20:18:29Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,039
<p>Django hosting support is not as widespread as for PHP, but there are some good options. I can recommend <a href="http://www.webfaction.com/" rel="nofollow">WebFaction</a> - they provide an easy-to-use control panel which offers various combinations of Django versions, Python versions, mod_python, mod_wsgi, MySQL, P...
2
2009-08-21T20:23:16Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,127
<p>Most shared hosting sites run the LAMP (Linux, Apache, MySQL, PHP) stack so deployment is just a matter of copying some files over. If you were using one of the PHP frameworks like CakePHP or something the service hasn't installed (like an imaging library) you'd be going through extra deployment steps as well.</p> ...
0
2009-08-21T20:45:30Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,254
<p>You just install this already made <a href="http://www.turnkeylinux.org/appliances/django" rel="nofollow">solution</a> if your allowed to run an image on a virtual machine. I can imagine installations will be done this way in future as complicated security configuration can be done automatically.</p>
1
2009-08-21T21:12:38Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,314,721
<p>You can use Python <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> and <a href="http://pip.openplans.org/" rel="nofollow">pip</a> (see also "<a href="http://clemesha.org/blog/2009/jul/05/modern-python-hacker-tools-virtualenv-fabric-pip/" rel="nofollow">Tools of the Modern Python Hacker...
0
2009-08-22T00:02:10Z
[ "python", "django" ]
How can Django projects be deployed with minimal installation work?
1,313,989
<p>To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):</p> <ul> <li>Install MySQLPython</li> <li>Install ModPython</li> <li>Install Django (using <em>python setup.py install</em>)</li> <li>Add some directives on httpd.conf file (or use .htaccess)</li> </ul> <p>But, when I deploye...
3
2009-08-21T20:11:33Z
1,315,907
<p>To enable easy Django deployement I would to the following:</p> <p><strong>Fisrt-time server configuration</strong></p> <ul> <li>Install <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> which allow you to run in <em>embedded</em> mode OR in <strong>daemon</strong> mode.</li> <li>Install pyth...
4
2009-08-22T12:46:14Z
[ "python", "django" ]
Using PyUNO on Windows and CentOS
1,314,009
<p>Is there any way to use OpenOffice's <a href="http://wiki.services.openoffice.org/wiki/PyUNO_bridge" rel="nofollow">PyUNO</a> without using the version of Python that comes with OpenOffice? </p> <p>I mean, can I install a package (on Windows and CentOS) that uses the version of Python that's already on the server?...
2
2009-08-21T20:16:34Z
1,316,731
<p>You can't use PyUNO with just any version of Python. You need to use the specific one that's integrated into your OpenOffice installation. However, the very latest OO (3.1 I believe) comes (on all platforms) with the very latest Python (2.6.2 I believe), so if you can upgrade your OpenOffice to the very latest relea...
2
2009-08-22T18:56:42Z
[ "python", "openoffice.org", "uno" ]
How can I scrape this frame?
1,314,052
<p>If you visit <a href="http://cad.chp.ca.gov/iiqr.asp?Center=RDCC&amp;LogNumber=0197D0820&amp;t=Traffic%20Hazard&amp;l=3358%20MYRTLE&amp;b=" rel="nofollow">this link</a> right now, you will probably get a VBScript error.</p> <p>On the other hand, if you visit <a href="http://cad.chp.ca.gov/" rel="nofollow">this link...
2
2009-08-21T20:28:36Z
1,314,095
<p>You might also try <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> in addition to Mechanize. I'm not positive, but you should be able to parse the DOM down into the framed page.</p> <p>I also find <a href="https://addons.mozilla.org/en-US/firefox/addon/966" rel="nofollow">T...
1
2009-08-21T20:38:27Z
[ "python", "vbscript", "screen-scraping", "mechanize" ]
How can I scrape this frame?
1,314,052
<p>If you visit <a href="http://cad.chp.ca.gov/iiqr.asp?Center=RDCC&amp;LogNumber=0197D0820&amp;t=Traffic%20Hazard&amp;l=3358%20MYRTLE&amp;b=" rel="nofollow">this link</a> right now, you will probably get a VBScript error.</p> <p>On the other hand, if you visit <a href="http://cad.chp.ca.gov/" rel="nofollow">this link...
2
2009-08-21T20:28:36Z
1,314,138
<p>It always comes down to the request/response model. You just have to craft a series of http requests such that you get the desired responses. In this case, you also need the server to treat each request as part of the same session. To do that, you need to figure out how the server is tracking sessions. It could be a...
8
2009-08-21T20:46:55Z
[ "python", "vbscript", "screen-scraping", "mechanize" ]
Is there any way to get vim to auto wrap python strings at 79 chars?
1,314,174
<p>I found this <a href="http://stackoverflow.com/questions/1302364/python-pep8-printing-wrapped-strings-without-indent/1302381#1302381">answer</a> about wrapping strings using parens extremely useful, but is there a way in Vim to make this happen automatically? I want to be within a string, typing away, and have Vim ...
32
2009-08-21T20:54:01Z
1,315,419
<p>More a direction than a solution.</p> <p>Use <code>'formatexpr'</code> or <code>'formatprg'</code>. When a line exceeds <code>'textwidth'</code> and passes the criteria set by the <code>'formatoptions'</code> these are used (if set) to break the line. The only real difference is that <code>'formatexpr'</code> is ...
12
2009-08-22T07:46:39Z
[ "python", "vim", "string", "wrapping", "textwrapping" ]
How can I filter items from a list in Python?
1,314,314
<p>I have data naively collected from package dependency lists.</p> <p>Depends: foo bar baz >= 5.2</p> <p>I end up with </p> <pre><code> d = set(['foo','bar','baz','&gt;=','5.2']) </code></pre> <p>I don't want the numerics and the operands.</p> <p>In Perl I would</p> <pre><code>@new = grep {/^[a-z]+$/} @old </co...
7
2009-08-21T21:27:30Z
1,314,331
<p>How about </p> <pre><code>d = set([item for item in d if re.match("^[a-zA-Z]+$",item)]) </code></pre> <p>that gives you just the values you want, back in d (the order may be different, but that's the price you pay for using sets.</p>
1
2009-08-21T21:31:58Z
[ "python" ]
How can I filter items from a list in Python?
1,314,314
<p>I have data naively collected from package dependency lists.</p> <p>Depends: foo bar baz >= 5.2</p> <p>I end up with </p> <pre><code> d = set(['foo','bar','baz','&gt;=','5.2']) </code></pre> <p>I don't want the numerics and the operands.</p> <p>In Perl I would</p> <pre><code>@new = grep {/^[a-z]+$/} @old </co...
7
2009-08-21T21:27:30Z
1,314,352
<p>No need for regular expressions here. Use <a href="http://docs.python.org/library/stdtypes.html#str.isalpha"><code>str.isalpha</code></a>. With and without list comprehensions:</p> <pre><code>my_list = ['foo','bar','baz','&gt;=','5.2'] # With only_words = [token for token in my_list if token.isalpha()] # Without...
18
2009-08-21T21:40:28Z
[ "python" ]
How to get pyodbc.connect to prompt?
1,314,445
<p>In my C++ programs, I'm used to the connection process prompting for a missing password or letting you select your own connection. Whe I use pyodbc.connect(), an exception is generated instead.</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#41&gt;", line 1, in &lt;module&gt; c=pyodbc.con...
0
2009-08-21T22:14:53Z
1,314,517
<p>I'm not sure if you can, I just checked the source for this and it seems like it always sends SQL_DRIVER_NOPROMPT.</p> <p><a href="http://github.com/mkleehammer/pyodbc/blob/10ac782c60f8aa92c401963ca363d20f03de0a3e/src/connection.cpp#L88" rel="nofollow">See line 88 in connection.cpp</a></p>
2
2009-08-21T22:45:39Z
[ "python", "pyodbc" ]
Is there a LGPL/Apache/BSD Python library for rendering modern HTML and Flash with a transparent background on Windows,Mac,Linux?
1,314,596
<p>I'm looking for a Python library that's suitable, with DOM access too. I don't mind if the flash transparency doesn't carry over. PyQT's license isn't compatible with the project, and PySide isn't compiled cross-platform yet. Any thoughts?</p>
2
2009-08-21T23:19:04Z
1,314,609
<p>Actually, the <a href="http://www.pyside.org/" rel="nofollow">pyside</a> project now provides LGPL 2.1 python bindings for Qt.</p> <p>The first public release was on August 18th. It is being developed with support from Nokia.</p> <p>According to the <a href="http://www.pyside.org/2009/08/pyside-has-been-released/...
2
2009-08-21T23:24:23Z
[ "python", "webkit", "widget", "alphablending", "gecko" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
1,314,625
<p>In this line:</p> <pre><code>if value is not None and not value.has_key(): </code></pre> <p><code>value</code> is a unicode string. It looks like the code is expecting it to be a <code>db.Model</code>,</p> <p>(From what I can see, <code>has_key</code> is a method of <code>db.Model</code>, as well as a method of ...
6
2009-08-21T23:30:48Z
[ "python", "google-app-engine" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
1,314,634
<p>If you read the traceback, it'll tell you exactly what is going on:</p> <pre><code> if value is not None and not value.has_key(): AttributeError: 'unicode' object has no attribute 'has_key' </code></pre> <p>What this says is the the <code>value</code> variable which you're using doesn't have the <code>has_key</...
1
2009-08-21T23:34:03Z
[ "python", "google-app-engine" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
1,315,050
<p>Note: normally "mapping" types in Python (dictionaries and dictionary like classes ... such as various types of dbm (indexed file) and some DBMS/ORM interfaces ... will implement a <code>has_key()</code> method.</p> <p>Somehow you have gotten a Unicode (string) object into this statement when you were expecting to ...
2
2009-08-22T03:34:31Z
[ "python", "google-app-engine" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
1,316,202
<p>You're attempting to set a string to a ReferenceProperty. The 'country' field of CMSCountry is a db.ReferenceProperty, which takes a db.Key or a CMSCountry object, but you're attempting to set it to a string.</p> <p>You should be doing something like this:</p> <pre><code>def post(self): postedcountry = self.requ...
1
2009-08-22T15:30:01Z
[ "python", "google-app-engine" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
1,318,908
<p>Your problem is that postedcountry is a string and not a country object. Values retrieved from self.request.get are the string values of variables passed by the browser. </p> <p>You need to look up a country object using some GQL. Exactly how you do that will depend on what exactly the country field of your HTML ...
3
2009-08-23T16:10:44Z
[ "python", "google-app-engine" ]
Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "
1,314,617
<p>I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace:</p> <pre><code>Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.pos...
5
2009-08-21T23:26:54Z
3,891,621
<p>The dictionary object's has_key() method is deprecated in 3.0 - use the "in" expression instead. If you are using the old library in 3.x, you must make code changes to accommodate it.</p>
0
2010-10-08T14:36:55Z
[ "python", "google-app-engine" ]
Cannot connect to server externally using Twisted library in Python
1,315,087
<p>I am trying to get a simple TCP server running on my server. I am using echoserv.py and echoclient.py on the <a href="http://twistedmatrix.com/projects/core/documentation/examples/" rel="nofollow">Twisted examples page</a>. When I run echoserv.py on the server, I can connect fine using the following in echoclient.py...
1
2009-08-22T04:00:24Z
1,315,106
<p>When you program your router to port-forward outcoming connections to your inbound server, it actually works only if the clients (those who try to connect) are really outside your network, really coming from the cloud. You, from inside your network, can't use it, it won't work for you. You will have the feeling that...
4
2009-08-22T04:12:30Z
[ "python", "tcp", "twisted", "port" ]
Cannot connect to server externally using Twisted library in Python
1,315,087
<p>I am trying to get a simple TCP server running on my server. I am using echoserv.py and echoclient.py on the <a href="http://twistedmatrix.com/projects/core/documentation/examples/" rel="nofollow">Twisted examples page</a>. When I run echoserv.py on the server, I can connect fine using the following in echoclient.py...
1
2009-08-22T04:00:24Z
1,315,119
<p>Have you tried the following?</p> <ol> <li>Do a port scan on the IP of the machine running the server to confirm that the port is open. A simple [google search][1] will give you plenty of options.</li> <li>If the port is shown to be open, try the remote connection via telnet instead of the twisted client script. ...
1
2009-08-22T04:20:12Z
[ "python", "tcp", "twisted", "port" ]
Efficient way to verify that records are unique in Python/PyTables
1,315,129
<p>I have a table in PyTables with ~50 million records. The combination of two fields (specifically userID and date) should be unique (i.e. a user should have at most one record per day), but I need to verify that this is indeed the case.</p> <p>Illustratively, my table looks like this:</p> <pre><code>userID | dat...
4
2009-08-22T04:25:39Z
1,316,043
<p>I don't know much about PyTables, but I would try this approach</p> <ol> <li>For each userID, get all <code>(userID, date)</code> pairs</li> <li><code>assert len(rows)==len(set(rows))</code> - this assertion holds true if all <code>(userID, date)</code> tuples contained in the <code>rows</code> list are unique</li>...
0
2009-08-22T14:05:16Z
[ "python" ]
Efficient way to verify that records are unique in Python/PyTables
1,315,129
<p>I have a table in PyTables with ~50 million records. The combination of two fields (specifically userID and date) should be unique (i.e. a user should have at most one record per day), but I need to verify that this is indeed the case.</p> <p>Illustratively, my table looks like this:</p> <pre><code>userID | dat...
4
2009-08-22T04:25:39Z
1,316,398
<p>It seems that indexes in PyTables are limited to single columns.</p> <p>I would suggest adding a hash column and putting an index on it. Your unique data is defined as the concatenation of other columns in the DB. Separators will ensure that there aren't two different rows that yield the same unique data. The hash ...
3
2009-08-22T16:36:40Z
[ "python" ]
Efficient way to verify that records are unique in Python/PyTables
1,315,129
<p>I have a table in PyTables with ~50 million records. The combination of two fields (specifically userID and date) should be unique (i.e. a user should have at most one record per day), but I need to verify that this is indeed the case.</p> <p>Illustratively, my table looks like this:</p> <pre><code>userID | dat...
4
2009-08-22T04:25:39Z
11,302,850
<p>So years later I still have the same question, but with the power of indexing and querying this problem is only slightly painful, depending on the size of your table. With the use of readWhere, or getListWhere I think that the problem is approx O(n)</p> <p>Here is what I did... 1. I created a table that had two ind...
1
2012-07-03T00:07:29Z
[ "python" ]
app-engine-patch with pyamf = No module named encoding
1,315,368
<p>I'm trying to use app-engine-patch with pyamf by following this: <a href="http://pyamf.org/wiki/GoogleAppEngine" rel="nofollow">http://pyamf.org/wiki/GoogleAppEngine</a> because I want to migrate my Django &lt;-> pyamf application to app-engine-patch &lt;-> pyamf.</p> <p>What I have now is that I created my gateway...
0
2009-08-22T07:07:22Z
1,316,754
<p>Are you activating Django 1.0.2 in your app engine startup code? App Engine now comes with it, but also (for backwards compatibility) with 0.9.6, and (still for backwards compatibility) 0.9.6 is what it defaults to -- all it takes to fix this is, at startup, use:</p> <pre><code>from google.appengine.dist import use...
1
2009-08-22T19:04:17Z
[ "python", "google-app-engine", "pyamf", "app-engine-patch" ]
Python, find a file in the same directory
1,315,390
<p>Let's say I have the files a.py and b.txt in the same directory. I can't garuntee <strong>where</strong> that directory is, but I know b.txt will be in the same directory as a.py. a.py needs to access b.txt, how would I go about finding the path to b.txt? Something like "./b.txt" won't work if the user runs the p...
0
2009-08-22T07:31:50Z
1,315,401
<p>Use the <code>__file__</code> variable:</p> <pre><code>os.path.join(os.path.dirname(__file__), "b.txt") </code></pre>
4
2009-08-22T07:37:05Z
[ "python" ]
Python, find a file in the same directory
1,315,390
<p>Let's say I have the files a.py and b.txt in the same directory. I can't garuntee <strong>where</strong> that directory is, but I know b.txt will be in the same directory as a.py. a.py needs to access b.txt, how would I go about finding the path to b.txt? Something like "./b.txt" won't work if the user runs the p...
0
2009-08-22T07:31:50Z
1,315,403
<p>If you want the location of the main script, even from code that might be running in an imported module, you need to use <code>sys.argv[0]</code> rather than <code>__file__</code>. (<code>sys.argv[0]</code> is always the path to the main script; see <a href="http://docs.python.org/library/sys.html#sys.argv" rel="nof...
1
2009-08-22T07:38:22Z
[ "python" ]
dictionary of object
1,315,407
<p>I have a sorted dict </p> <p><code> { 1L: '&lt;'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '&lt;'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '&lt;'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '&lt;...
0
2009-08-22T07:40:23Z
1,315,449
<p>Python dictionaries are not sorted. If you have some custom class which implements some mapping methods (like a dictionary) but over-rides some of them to give the appearance of maintaining some (sorted) ordering then the implementation details of that might also explain why your example doesn't look like valid Pyt...
1
2009-08-22T07:59:22Z
[ "python", "dictionary", "sorted" ]
dictionary of object
1,315,407
<p>I have a sorted dict </p> <p><code> { 1L: '&lt;'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '&lt;'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '&lt;'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '&lt;...
0
2009-08-22T07:40:23Z
1,316,728
<pre><code>class Foo(object): def __init__(self,name,weight): self.name = name self.weight = weight &gt;&gt;&gt; D = {} &gt;&gt;&gt; D['1L'] = Foo("James",67) &gt;&gt;&gt; D['2L'] = Foo("Jack",83) &gt;&gt;&gt; D {'2L': &lt;__main__.Foo object at 0x013EB330&gt;, '1L': &lt;__main__.Foo object at 0x00C402D...
0
2009-08-22T18:55:48Z
[ "python", "dictionary", "sorted" ]
How can I specify that some command line arguments are mandatory in Python?
1,315,425
<p>I'm writing a program in Python that accepts command line arguments. I am parsing them with <code>getopt</code> (though my choice of <code>getopt</code> is no Catholic marriage. I'm more than willing to use any other library). Is there any way to specify that certain arguments <em>must</em> be given, or do I have...
5
2009-08-22T07:49:17Z
1,315,446
<p>The simplest approach would be to do it yourself. I.e.</p> <pre><code>found_f = False try: opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) for o, a in opts: if o == '-f': process_f() found_f = Tr...
6
2009-08-22T07:57:48Z
[ "python", "command-line" ]
How can I specify that some command line arguments are mandatory in Python?
1,315,425
<p>I'm writing a program in Python that accepts command line arguments. I am parsing them with <code>getopt</code> (though my choice of <code>getopt</code> is no Catholic marriage. I'm more than willing to use any other library). Is there any way to specify that certain arguments <em>must</em> be given, or do I have...
5
2009-08-22T07:49:17Z
1,315,462
<p>As for me I prefer using <a href="http://docs.python.org/library/optparse.html">optparse module</a>, it is quite powerful, for exapmle it can automatically generate -h message by given options:</p> <pre><code>from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", dest="filename...
10
2009-08-22T08:10:24Z
[ "python", "command-line" ]
What do you make of this Python error?
1,315,465
<p>Here's the error.</p> <pre><code>Traceback (most recent call last): File "_ctypes/callbacks.c", line 295, in 'calling callback function' File "USB2.py", line 454, in ff self.drv_locked = False SystemError: Objects/cellobject.c:24: bad argument to internal function </code></pre> <p>Here's the Python code in...
2
2009-08-22T08:10:58Z
1,315,500
<p>The <code>PyCell_Check</code> function checks that its argument actually is a cell object (an internal type used to implement variables referenced by multiple scopes). If <code>op</code> is not a cell object, you would get this error.</p> <p>The code you posted does not give enough context/information to determine ...
2
2009-08-22T08:32:41Z
[ "python", "ctypes" ]
What do you make of this Python error?
1,315,465
<p>Here's the error.</p> <pre><code>Traceback (most recent call last): File "_ctypes/callbacks.c", line 295, in 'calling callback function' File "USB2.py", line 454, in ff self.drv_locked = False SystemError: Objects/cellobject.c:24: bad argument to internal function </code></pre> <p>Here's the Python code in...
2
2009-08-22T08:10:58Z
1,316,789
<p>An internal error is clearly a bug in Python itself, and if you're interested in further exploring this and offering a fix for the Python core, then simplifying your code down to where it still triggers the bug would be the right strategy.</p> <p>If you're more interested in having your code work, rather than in fi...
5
2009-08-22T19:16:18Z
[ "python", "ctypes" ]
How to migrate packages to a new Python installation?
1,315,511
<p>How can i quickly migrate/copy my python packages that i have installed over time to a new machine?</p> <p>This is my scenario;</p> <p>Am upgrading from an old laptop running python2.5 &amp; Django1.0, to a new laptop which i intend to install python 2.6.2 &amp; Django 1.1. In time i have downloaded and installed ...
1
2009-08-22T08:38:39Z
1,315,529
<p>If they're pure Python, then in theory you could just copy them across from one <code>Lib\site-packages</code> directory to the other. However, this will not work for any packages which include C extensions (as these need to be recompiled anew for every Python version). You also need to consider e.g. <code>.pth</cod...
2
2009-08-22T08:49:55Z
[ "python", "migration", "packages" ]
How to migrate packages to a new Python installation?
1,315,511
<p>How can i quickly migrate/copy my python packages that i have installed over time to a new machine?</p> <p>This is my scenario;</p> <p>Am upgrading from an old laptop running python2.5 &amp; Django1.0, to a new laptop which i intend to install python 2.6.2 &amp; Django 1.1. In time i have downloaded and installed ...
1
2009-08-22T08:38:39Z
1,315,764
<p>As Vinay says, there are some parts of common installations that can't be just copied over. Also, keep in mind that setup.py scripts can perform arbitrary work, for example, they could test for the version of Python, and change how they install things, or they could write registry entries, or create .rc files, etc....
1
2009-08-22T11:10:53Z
[ "python", "migration", "packages" ]
How to migrate packages to a new Python installation?
1,315,511
<p>How can i quickly migrate/copy my python packages that i have installed over time to a new machine?</p> <p>This is my scenario;</p> <p>Am upgrading from an old laptop running python2.5 &amp; Django1.0, to a new laptop which i intend to install python 2.6.2 &amp; Django 1.1. In time i have downloaded and installed ...
1
2009-08-22T08:38:39Z
1,315,834
<p>Use <a href="http://www.PortablePython.com" rel="nofollow">Portable Python</a> then you can have everything on your USB stick. Your entire development environment always in your pocket, just plug it in in ANY pc and start coding.</p> <p>You can even have multiple versions of Portable Python on same USB stick and ru...
0
2009-08-22T11:59:50Z
[ "python", "migration", "packages" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,568
<p><code>text[0]</code> fails if <code>text</code> is an empty string:</p> <pre><code>IronPython 2.6 Alpha (2.6.0.1) on .NET 4.0.20506.1 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; text = "" &gt;&gt;&gt; print(text.startswith("a")) False &gt;&gt;&gt; print(text[0]=='a') Tracebac...
25
2009-08-22T09:04:25Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,570
<p>Personally I would say <code>startswith</code> is more readable.</p> <p>Also, from Python 2.5 <code>startwith</code> can take a tuple of prefixes to look for:</p> <pre><code>&gt;&gt;&gt; "hello world".startswith(("hello","goodbye")) True </code></pre>
9
2009-08-22T09:05:48Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,577
<p>Yes: it’s easier to use and easier to read. When you are testing for more than one letter, when using slicing, you’ll have to know how long the target text is:</p> <pre><code>haystack = 'Hello, World!' needle = 'Hello' # The easy way result = haystack.startswith(needle) # The slightly harder way result = hays...
10
2009-08-22T09:07:49Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,580
<p>The stock phrase for the questiom is: "Premature optimization is the root of all evil".</p>
7
2009-08-22T09:09:46Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,591
<p>text[0]=='a' is good considering performance. Also you need to add validation when you use this.</p>
1
2009-08-22T09:20:26Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,315,600
<p><code>text[0]</code> can fail but the equivalent <code>text[:1]</code> is safe if the string is empty.<br></p> <p>If you want to compare more than one characters, I believe <code>.startswith()</code> is better.</p>
4
2009-08-22T09:24:06Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,316,245
<p>I'd agree with the others that startswith is more readable, and you should use that. That said, if performance is a big issue for such a special case, benchmark it:</p> <pre><code>$ python -m timeit -s 'text="foo"' 'text.startswith("a")' 1000000 loops, best of 3: 0.537 usec per loop $ python -m timeit -s 'text="f...
18
2009-08-22T15:44:09Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
1,342,749
<p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> explicitly tells to use <code>startswith</code>, because of readability:</p> <blockquote> <pre><code>- Use ''.startswith() and ''.endswith() instead of string </code></pre> <p>slicing to check for prefixes or suffixes.</p> <pre><code> start...
5
2009-08-27T17:58:00Z
[ "python" ]
How good is startswith?
1,315,559
<p>Is </p> <pre><code>text.startswith('a') </code></pre> <p>better than </p> <pre><code>text[0]=='a' </code></pre> <p>?</p> <p>Knowing text is not empty and we are only interested in the first character of it. </p>
11
2009-08-22T09:02:23Z
18,870,135
<pre><code>def compo2(): n = "abba" for i in range(1000000): n[:1]=="_" </code></pre> <p>is faster than</p> <pre><code>def compo(): n = "abba" for i in range(1000000): n.startswith("_") </code></pre> <p>cProfile reports 0.061 for <code>compo2</code> compared to 0.954 for <code>compo</...
2
2013-09-18T10:45:50Z
[ "python" ]
Amazon S3 Python Bulk File Transfer through Python
1,315,660
<p>I want to tranfer files in around 1000 directories to an Amazon S3 bucket using Pythons S3 package. How could I do it ?</p>
-2
2009-08-22T09:55:59Z
1,317,690
<p>I like boto,</p> <p><a href="http://code.google.com/p/boto/" rel="nofollow">http://code.google.com/p/boto/</a></p>
4
2009-08-23T03:31:30Z
[ "python", "amazon-s3" ]
Is there an way to programatically read a file from a TrueCrypt disk into memory?
1,315,677
<p>I need to load a file from an umounted TrueCrypt disk into memory. Is there any way to do this programatically? Does TrueCrypt offer an API?</p> <p>The way I believe is best for attempting this would be to mount the volume (prompting the user for a password, of course), open the file, and then unmount the volume....
10
2009-08-22T10:06:06Z
1,315,722
<p>Can you not use the <a href="http://www.truecrypt.org/docs/?s=command-line-usage">true crypt command line</a> from say System.Diagnostics.Process?</p> <pre><code>using System; using System.Diagnostics; namespace Test { class TrueCrypeStart { static void Main(string[] args) { s...
12
2009-08-22T10:38:11Z
[ "c#", "python", "perl", "readfile", "truecrypt" ]
Is there an way to programatically read a file from a TrueCrypt disk into memory?
1,315,677
<p>I need to load a file from an umounted TrueCrypt disk into memory. Is there any way to do this programatically? Does TrueCrypt offer an API?</p> <p>The way I believe is best for attempting this would be to mount the volume (prompting the user for a password, of course), open the file, and then unmount the volume....
10
2009-08-22T10:06:06Z
22,404,525
<p><a href="http://iknowu.dnsalias.com/files/public/TrueResize/TrueResize.htm" rel="nofollow">TrueResize</a> includes an open-source C# TrueCrypt library that will allow you to read the encrypted volume (without having to mount it), an additional library includes NTFS support.</p>
0
2014-03-14T12:06:12Z
[ "c#", "python", "perl", "readfile", "truecrypt" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,008
<p>Actually, in the second snippet, the last line executes always.</p> <p>You probably meant</p> <pre><code>try: some_code_that_can_cause_an_exception() code_that_needs_to_run_when_there_are_no_exceptions() except: some_code_to_handle_exceptions() </code></pre> <p><strike>I believe you can use the <code>...
6
2009-08-22T13:44:32Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,011
<p>In the second example, <code>code_that_needs_to_run_when_there_are_no_exceptions()</code> will be ran when you <strong>do</strong> have an exception and then you handle it, continuing after the except.</p> <p>so ...</p> <p>In both cases code_that_needs_to_run_when_there_are_no_exceptions() will execute when there ...
9
2009-08-22T13:46:00Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,037
<p>According to the <a href="http://docs.python.org/reference/compound%5Fstmts.html" rel="nofollow">docs</a>...</p> <p><em>"The optional else clause is executed if and when control flows off the end of the try clause.7.2 Exceptions in the else clause are not handled by the preceding except clauses."</em></p> <p>So lo...
1
2009-08-22T13:58:26Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,041
<p>Example 1:</p> <pre><code>try: a() b() except: c() </code></pre> <p>Here, <code>b()</code> will only be run if <code>a()</code> didn't throw, but the except block will also catch any exceptions that may be <em>thrown by <code>b()</code></em>, which you might not want. A general rule is: only catch exc...
5
2009-08-22T14:01:30Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,046
<p>You had the original code almost right. Here's the full treatment:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() code_that_runs_whether_there_was_an_exception_or_not() </code></pre>
4
2009-08-22T14:06:08Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,316,062
<p>I haven't been using Python for all that long, but I try to handle specific exceptions in a <code>try</code> block, and use <code>else</code> to handle the "other" exceptions I might not have expected, similar to a <code>default</code> block in C/C++ <code>switch</code> blocks. Is that an appropriate use for <code>...
0
2009-08-22T14:14:45Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
1,319,426
<p>I use try:..except:..else: a lot!</p> <p>This is the pattern: try..except should span just one line of code where I anticipate an exception. Then except does the fallback/default handling, and else: does the thing I really wanted to do (no exceptions => go on to make what I wanted).</p> <p>A simple example:</p> <...
1
2009-08-23T20:08:10Z
[ "python", "exception" ]
when is it necessary to add an `else` clause to a try..except in Python?
1,316,002
<p>When I write code in Python with exception handling I can write code like:</p> <pre><code>try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() </code></pre> <p>How does this differ from:</p> <pre><code>try: ...
4
2009-08-22T13:41:42Z
22,579,805
<p>While Ned Batchelder's response is appropriate for the OP, I'd like to slightly build upon it. Also, I can't reply as a comment to Mk12's comment (since I "only" have 49 rep, not 50, go figure). So my mite of contribution:</p> <pre><code>try: code_that_can_cause_an_exception() except ParticularException: co...
1
2014-03-22T15:47:22Z
[ "python", "exception" ]
Pythonic way of iterating over 3D array
1,316,068
<p>I have a 3D array in Python and I need to iterate over all the cubes in the array. That is, for all <code>(x,y,z)</code> in the array's dimensions I need to access the cube:</p> <pre><code>array[(x + 0, y + 0, z + 0)] array[(x + 1, y + 0, z + 0)] array[(x + 0, y + 1, z + 0)] array[(x + 1, y + 1, z + 0)] array[(x +...
5
2009-08-22T14:16:04Z
1,316,087
<pre><code>import itertools for x, y, z in itertools.product(xrange(x_size), xrange(y_size), xrange(z_size)): work_with_cube(array[x, y, z]) </code></pre>
7
2009-08-22T14:29:59Z
[ "python", "arrays", "loops" ]
Pythonic way of iterating over 3D array
1,316,068
<p>I have a 3D array in Python and I need to iterate over all the cubes in the array. That is, for all <code>(x,y,z)</code> in the array's dimensions I need to access the cube:</p> <pre><code>array[(x + 0, y + 0, z + 0)] array[(x + 1, y + 0, z + 0)] array[(x + 0, y + 1, z + 0)] array[(x + 1, y + 1, z + 0)] array[(x +...
5
2009-08-22T14:16:04Z
1,316,104
<p>Have a look at <a href="http://docs.python.org/library/itertools.html">itertools</a>, especially <a href="http://docs.python.org/library/itertools.html#itertools.product">itertools.product</a>. You can compress the three loops into one with </p> <pre><code>import itertools for x, y, z in itertools.product(*map(xra...
13
2009-08-22T14:38:12Z
[ "python", "arrays", "loops" ]
Transforming nested list in Python
1,316,319
<p>Assuming I have a structure like this:</p> <pre><code>a = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] </code></pre> <p>How can I transform it into:</p> <pre><code>a = [ ('A', 'D'), ('A', 'E'), ('A', 'F'), ('A', 'G'), ('B', 'H'), ('C', 'I'), ] </code></pre> <p>Thanks for your time!</p>
0
2009-08-22T16:14:36Z
1,316,335
<p>Here's a simple solution:</p> <pre><code>data = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] result = [] for x in data: for y in x[1]: result.append((x[0], y)) </code></pre>
4
2009-08-22T16:19:09Z
[ "python" ]
Transforming nested list in Python
1,316,319
<p>Assuming I have a structure like this:</p> <pre><code>a = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] </code></pre> <p>How can I transform it into:</p> <pre><code>a = [ ('A', 'D'), ('A', 'E'), ('A', 'F'), ('A', 'G'), ('B', 'H'), ('C', 'I'), ] </code></pre> <p>Thanks for your time!</p>
0
2009-08-22T16:14:36Z
1,316,339
<p>Try:</p> <pre><code>&gt;&gt;&gt; a = [('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I'])] &gt;&gt;&gt; [(k,j) for k, more in a for j in more] [('A', 'D'), ('A', 'E'), ('A', 'F'), ('A', 'G'), ('B', 'H'), ('C', 'I')] </code></pre> <p>This handles only one level of nesting of course.</p>
10
2009-08-22T16:19:33Z
[ "python" ]
Transforming nested list in Python
1,316,319
<p>Assuming I have a structure like this:</p> <pre><code>a = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] </code></pre> <p>How can I transform it into:</p> <pre><code>a = [ ('A', 'D'), ('A', 'E'), ('A', 'F'), ('A', 'G'), ('B', 'H'), ('C', 'I'), ] </code></pre> <p>Thanks for your time!</p>
0
2009-08-22T16:14:36Z
1,317,634
<p>(Side comment) Why on earth did you indent like that? Isn't the following more readable?</p> <pre><code>a = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] </code></pre>
1
2009-08-23T02:49:09Z
[ "python" ]
pylint not recognizing some of the standard library
1,316,334
<p>I'm using pylint + pydev, with python 2.6. I have a module with just this line of code</p> <pre><code>from email import Message </code></pre> <p>Now when I try to run this module it runs fine. But pylint reports an error:</p> <pre><code>ID: E0611 No name 'Message' in module 'email' </code></pre> <p>Although it e...
9
2009-08-22T16:19:08Z
1,316,351
<p>The <code>email</code> module uses some horrible import hackery, which has bitten me in the past. You can do this:</p> <pre><code>&gt;&gt;&gt; from email import Message </code></pre> <p>but you can't do this:</p> <pre><code>&gt;&gt;&gt; import email &gt;&gt;&gt; email.Message Traceback (most recent call last): ...
1
2009-08-22T16:23:25Z
[ "python", "email", "import", "pydev", "pylint" ]
pylint not recognizing some of the standard library
1,316,334
<p>I'm using pylint + pydev, with python 2.6. I have a module with just this line of code</p> <pre><code>from email import Message </code></pre> <p>Now when I try to run this module it runs fine. But pylint reports an error:</p> <pre><code>ID: E0611 No name 'Message' in module 'email' </code></pre> <p>Although it e...
9
2009-08-22T16:19:08Z
1,316,693
<p>I like pylint, but I do find I have to use a lot of <code># pylint: disable-msg=E0611</code> and the like to make it shut up in cases that are perfectly correct but confuse it (for example, like in this case, due to <code>email</code>'s playing with import tricks).</p>
9
2009-08-22T18:40:45Z
[ "python", "email", "import", "pydev", "pylint" ]