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
Why does my 'hello world' Python C module work correctly in everything but IDLE?
2,420,317
<p>I compiled a simple hello world C module for Python and it works correctly in everything I've tried but IDLE. Here's what I type to test it:</p> <pre><code>&gt;&gt;&gt; import hello &gt;&gt;&gt; hello.say_hello('Justin') </code></pre> <p>I have tried this using Python from the command prompt(I'm using Windows), in...
2
2010-03-10T20:26:10Z
2,420,486
<p>Sounds like the hello is writing directly to <code>stdout</code>. Python's <code>stdout</code> is not necessarily the the same place as C <code>stdout</code></p> <p>Normally you would return a string to Python so Python can print it to it's own <code>stdout</code></p>
5
2010-03-10T20:51:40Z
[ "python", "c", "windows", "module", "mingw" ]
Why does my 'hello world' Python C module work correctly in everything but IDLE?
2,420,317
<p>I compiled a simple hello world C module for Python and it works correctly in everything I've tried but IDLE. Here's what I type to test it:</p> <pre><code>&gt;&gt;&gt; import hello &gt;&gt;&gt; hello.say_hello('Justin') </code></pre> <p>I have tried this using Python from the command prompt(I'm using Windows), in...
2
2010-03-10T20:26:10Z
2,420,977
<p>If you need to write to Python's <code>sys.stdout</code> from a C-coded extension, you can use something like:</p> <pre><code>void writeout(const char* nullterminated) { PyObject* sysmod = PyImport_ImportModuleNoBlock("sys"); PyObject* pystdout = PyObject_GetAttrString(sysmod, "stdout"); PyObject* resul...
5
2010-03-10T22:04:50Z
[ "python", "c", "windows", "module", "mingw" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,420,472
<p>You could use Pythons built in capability to do the search with regular expression matching. </p> <p>re module in python <a href="http://docs.python.org/library/re.html" rel="nofollow">http://docs.python.org/library/re.html</a></p> <p>regular expression primer <a href="http://www.regular-expressions.info/" rel="no...
0
2010-03-10T20:49:15Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,420,473
<p>You might find the various routines in <a href="http://www.michael-noll.com/wiki/Python-Levenshtein" rel="nofollow">Python-Levenshtein</a> of some use.</p>
3
2010-03-10T20:49:21Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,420,517
<p>This hints of the <a href="http://en.wikipedia.org/wiki/Longest_common_subsequence_problem" rel="nofollow">longest common subsequence problem</a>. The problem with string similarity here is that you need to test against a continuous string of 230000 sequences; so if you are comparing one of your 25 sequences to the ...
1
2010-03-10T20:57:35Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,420,528
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; seq="AGCCTCCCATGATTGAACAGATCAT" &gt;&gt;&gt; genome = "CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAGTGCGGAGCCTGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTT..." &gt;&gt;&gt; seq_re=re.compile('|'.join(seq[:i]+'.'+seq[i+1:] for i in range(len(seq)))) &gt;&gt;&gt; seq_re.findal...
2
2010-03-10T20:59:04Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,421,378
<p><strong>Before you read on</strong>, have you looked at <a href="http://biopython.org/wiki/Main_Page">biopython</a>?</p> <p>It appears that you want to find approximate matches with one substitution error, and zero insertion/deletion errors i.e. a Hamming distance of 1.</p> <p>If you have a Hamming distance match ...
18
2010-03-10T23:09:45Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,421,460
<p>You could make a <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">trie</a> out of all the different sequences that you want to match. Now is the tricky part of making a depth first search function down the trie that allows at most one mismatch.</p> <p>The advantage of this method is that you are searching...
1
2010-03-10T23:28:19Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,422,902
<p>I googled for "toxoplasma gondii parasite genome" to find some of these genome files online. I found what I think was close, a file titled "TgondiiGenomic_ToxoDB-6.0.fasta" at <a href="http://toxodb.org">http://toxodb.org</a>, about 158Mb in size. I used the following pyparsing expression to extract the gene seque...
6
2010-03-11T05:59:49Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
2,923,491
<p>I guess this may come a bit late, but there is a tool named PatMaN that does exactly what you want: <a href="http://bioinf.eva.mpg.de/patman/" rel="nofollow">http://bioinf.eva.mpg.de/patman/</a></p>
0
2010-05-27T17:46:45Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
9,178,839
<p>I tried some of the solutions, but as already written they are slow when dealing with a large amount of sequences (strings).</p> <p>I came up with using <a href="http://bowtie-bio.sourceforge.net/" rel="nofollow">bowtie</a> and mapping the substring of interest (soi) against a reference file which contains the stri...
1
2012-02-07T15:22:14Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
10,985,783
<p>You can use regex matching library TRE, for "approximate matching". It also has bindings for Python, Perl and Haskell.</p> <pre><code>import tre pt = tre.compile("Don(ald)?( Ervin)? Knuth", tre.EXTENDED) data = """ In addition to fundamental contributions in several branches of theoretical computer science, Donnal...
0
2012-06-11T18:45:12Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
10,986,521
<p>Python <a href="http://pypi.python.org/pypi/regex/">regex</a> library supports fuzzy regular expression matching. One advantage over <a href="http://laurikari.net/tre/">TRE</a> is that it allows to find all matches of regular expression in the text (supports overlapping matches as well).</p> <pre><code>import regex...
13
2012-06-11T19:44:02Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
Search for string allowing for one mismatch in any location of the string
2,420,412
<p>I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, but much longer than 230,000 sequences.</p> <p>I need to look for each of my sequences of 25 charac...
19
2010-03-10T20:42:30Z
35,105,995
<p>I thought the code below is simple and convenient.</p> <pre><code>in_pattern = ""; in_genome = ""; in_mistake = d; out_result = "" kmer = len(in_pattern) def FindMistake(v): mistake = 0 for i in range(0, kmer, 1): if (v[i]!=in_pattern[i]): mistake+=1 if mistake&gt;in_mistake: ...
0
2016-01-30T19:19:33Z
[ "python", "string", "pattern-matching", "string-matching", "dna-sequence" ]
How To Collapse Just One Field in Django Admin?
2,420,516
<p>The django admin allows you to <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets" rel="nofollow">specify fieldsets</a>. You properly structure a tuple that groups different fields together. You can also specify classes for certain groups of fields. One of thos...
4
2010-03-10T20:57:30Z
2,477,764
<p>If you want you can use fieldset in your admin.py and the field which you want to collapse use the class as collapse and remaining as foobar.</p> <p>Refer to django docs</p>
-3
2010-03-19T13:48:43Z
[ "python", "django", "django-admin" ]
How To Collapse Just One Field in Django Admin?
2,420,516
<p>The django admin allows you to <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets" rel="nofollow">specify fieldsets</a>. You properly structure a tuple that groups different fields together. You can also specify classes for certain groups of fields. One of thos...
4
2010-03-10T20:57:30Z
2,530,070
<p>Django doesn't have a built in way of doing this that I'm aware of but I can think of a couple of ways you could do something once, rather than having to manually modify lots of fieldsets.</p> <p>One approach would be to use javascript to rewrite the page markup. Maybe the javascript could have a list of fieldnames...
2
2010-03-27T16:47:51Z
[ "python", "django", "django-admin" ]
How To Collapse Just One Field in Django Admin?
2,420,516
<p>The django admin allows you to <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets" rel="nofollow">specify fieldsets</a>. You properly structure a tuple that groups different fields together. You can also specify classes for certain groups of fields. One of thos...
4
2010-03-10T20:57:30Z
2,530,217
<p>I do something like this, where I have one or more fields are only required based on the value of another. This is usually a checkbox or select, where true/false or one particular value means that we should show this other set of fields. I've added something like this:</p> <pre><code>$(document).ready(function(){ ...
0
2010-03-27T17:27:51Z
[ "python", "django", "django-admin" ]
google app engine: new version doesn't appear
2,420,519
<p>I have made an update on Google App Engine with a small fix and I got:</p> <pre><code>Closing update: new version is ready to start serving. </code></pre> <p>However, when I open the website, there is still old version. I have changed version to 2 in app.yaml, before running update. What am I missing?</p>
3
2010-03-10T20:57:48Z
2,420,530
<p>You have to set the new version to be the active version in the Admin console. Click the 'Versions' link, and make your new version the Default.</p>
4
2010-03-10T20:59:19Z
[ "python", "django", "google-app-engine", "version" ]
get an array variable in python
2,420,644
<p>can I do this in a loop, by producing the file name from the name of the array to store ? </p> <pre><code>ab = array.array('B', map( operator.xor, a, b ) ) f1 = open('ab', 'wb') ab.tofile(f1) f1.close ac = array.array('B', map( operator.xor, a, c ) ) f1 = open('ac', 'wb') ac.tofile(f1) f1.close ad = array.array('B'...
0
2010-03-10T21:15:46Z
2,420,706
<p>Assuming you are storing all the intermediate arrays for a reason.</p> <pre><code>A={} for v,x in zip((b,c,d,e,f),'bcdef'): fname = 'a'+x A[fname] = (array.array('B', map( operator.xor, a, v ) )) f1 = open(fname, 'wb') A[fname].tofile(f1) f1.close </code></pre> <p>Or something like this should ...
2
2010-03-10T21:23:18Z
[ "python", "arrays", "variables", "introspection" ]
get an array variable in python
2,420,644
<p>can I do this in a loop, by producing the file name from the name of the array to store ? </p> <pre><code>ab = array.array('B', map( operator.xor, a, b ) ) f1 = open('ab', 'wb') ab.tofile(f1) f1.close ac = array.array('B', map( operator.xor, a, c ) ) f1 = open('ac', 'wb') ac.tofile(f1) f1.close ad = array.array('B'...
0
2010-03-10T21:15:46Z
2,420,747
<p>One way is to have a,b,c,d,e,f in a dict. Then you'd just do something like:</p> <pre><code>for x in 'bcdef': t = array.array('B', map( operator.xor, mydict['a'], mydict[x] ) ) f1 = open(''.join('a',x),'wb') t.tofile(f1) f1.close() </code></pre>
1
2010-03-10T21:27:52Z
[ "python", "arrays", "variables", "introspection" ]
What's the VT100 escape code for the "esc" keyboard key itself
2,420,671
<p>I'm writing a script to navigate a text-based menu system, using python's telnetlib to access a serial connection.</p> <p>I can happily press the F-keys, using the escape codes. e.g. F9 = "\033OX", where "\033" is the escape sequence.</p> <p>How do I encode the "esc" keyboard key? I would have expected just "\03...
3
2010-03-10T21:19:03Z
2,420,715
<p>Put a small delay, say 1.5s, after sending the escape so that the other side realizes that it's an isolated escape and not part of a longer sequence.</p>
5
2010-03-10T21:24:14Z
[ "python", "escaping" ]
What's the VT100 escape code for the "esc" keyboard key itself
2,420,671
<p>I'm writing a script to navigate a text-based menu system, using python's telnetlib to access a serial connection.</p> <p>I can happily press the F-keys, using the escape codes. e.g. F9 = "\033OX", where "\033" is the escape sequence.</p> <p>How do I encode the "esc" keyboard key? I would have expected just "\03...
3
2010-03-10T21:19:03Z
3,219,355
<p>There is no such thing as an "escape sequence" for the ESC key on a VT-100 (or other terminals that used escape sequences).</p> <p>The escape character, ASCII 27, was used to indicate that the following sequences of characters had special meaning. This usually put the terminal into a simple state machine. In gene...
5
2010-07-10T13:27:39Z
[ "python", "escaping" ]
Install Trac on 64bits Windows 7
2,420,984
<p>I'm configuring a new Developing Server that came with Windows 7 64bits.</p> <p>It must have installed Trac with Subversion integration.</p> <p>I install Subversion with VisualSVN 2.1.1, clients with TortoiseSVN 1.6.7 and AnkhSVN 2.1.7 for Visual Studio 2008 SP1 integration.</p> <p>All works fine! my problem begu...
1
2010-03-10T22:06:30Z
2,421,274
<p>I would expect that <a href="http://trac.edgewall.org/wiki/TracOnWindows" rel="nofollow">Trac on Windows</a> instructions should work on x64, even if they're 32-bit packages. Have you tried this and failed?</p> <hr> <p>Subversion SWIG Python bindings:</p> <p><code>configure</code> is not meant to be run by Pytho...
1
2010-03-10T22:52:09Z
[ "python", "windows-7", "64bit", "bug-tracking", "trac" ]
Install Trac on 64bits Windows 7
2,420,984
<p>I'm configuring a new Developing Server that came with Windows 7 64bits.</p> <p>It must have installed Trac with Subversion integration.</p> <p>I install Subversion with VisualSVN 2.1.1, clients with TortoiseSVN 1.6.7 and AnkhSVN 2.1.7 for Visual Studio 2008 SP1 integration.</p> <p>All works fine! my problem begu...
1
2010-03-10T22:06:30Z
2,540,853
<p>Looks like I'm not the only one trying to install Trac on Win 7 64-bit, only to see the install crash and burn.</p> <p>One problem is the lack of installed registry entries for Python on Win x64, which I was able to find via a web search. The problem was identified months ago, but unfortunately no patch release has...
1
2010-03-29T19:59:32Z
[ "python", "windows-7", "64bit", "bug-tracking", "trac" ]
Install Trac on 64bits Windows 7
2,420,984
<p>I'm configuring a new Developing Server that came with Windows 7 64bits.</p> <p>It must have installed Trac with Subversion integration.</p> <p>I install Subversion with VisualSVN 2.1.1, clients with TortoiseSVN 1.6.7 and AnkhSVN 2.1.7 for Visual Studio 2008 SP1 integration.</p> <p>All works fine! my problem begu...
1
2010-03-10T22:06:30Z
16,122,975
<p>Just export Register from [HKEY_LOCAL_MACHINE\SOFTWARE\Python] to [HKEY_CURRENT_USER\Software\Python].</p> <p>It's happens because trac only see the [HKEY_CURRENT_USER\Software\Python] and you installed the python "For all users"</p>
3
2013-04-20T17:08:16Z
[ "python", "windows-7", "64bit", "bug-tracking", "trac" ]
Quickly implement a sortable table of objects in Django
2,421,006
<p>Hey all. I have a question on how to implement the following with Django. I'd like to display a tabular view of my objects with each column corresponding to a particular model field. I'd like to be able to have the user sort the columns or search through all of them. Basically just like the admin, but client facing ...
0
2010-03-10T22:10:06Z
2,421,266
<p>Alex Gaynor's <a href="http://github.com/alex/django-filter" rel="nofollow">django-filter</a> may be what you want.</p>
1
2010-03-10T22:50:21Z
[ "python", "django" ]
Quickly implement a sortable table of objects in Django
2,421,006
<p>Hey all. I have a question on how to implement the following with Django. I'd like to display a tabular view of my objects with each column corresponding to a particular model field. I'd like to be able to have the user sort the columns or search through all of them. Basically just like the admin, but client facing ...
0
2010-03-10T22:10:06Z
2,422,573
<p>Depending on how much you wanted to work with it, Yahoo YUI's DataTable control is pretty easy to get working with a JSON data source. See <a href="http://developer.yahoo.com/yui/datatable/" rel="nofollow">http://developer.yahoo.com/yui/datatable/</a></p>
0
2010-03-11T04:40:49Z
[ "python", "django" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,421,023
<p>If you just want to run web apps then use <code>mod_wsgi</code>. If you need to write a handler for the rest of httpd's request/response phases then use <code>mod_python</code>.</p>
4
2010-03-10T22:12:25Z
[ "python", "rest", "web-services", "apache2" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,421,036
<p><code>mod_wsgi</code> is more actively maintained and (I hear -- haven't benchmarked them myself!) better performing than <code>mod_python</code>. So unless you need exclusive features of <code>mod_python</code>, just to use a web app framework (or non-framework, like <a href="http://werkzeug.pocoo.org/">werkzeug</...
14
2010-03-10T22:14:10Z
[ "python", "rest", "web-services", "apache2" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,421,104
<p>Don't confuse what WSGI and mod_wsgi are. WSGI is an interface specification for hosting Python web applications on a server. The mod_wsgi module is an implementation of the WSGI specification using Apache as the underlying web server. Thus, Python and WSGI are not choices exactly, WSGI is just one way of being able...
5
2010-03-10T22:24:12Z
[ "python", "rest", "web-services", "apache2" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,421,190
<p>mod_wsgi is specifically tuned to run Python web apps that use WSGI in Apache. mod_python is for any kind of Python web app, including WSGI apps. mod_wsgi also has a lower memory footprint than mod_python.</p>
3
2010-03-10T22:37:24Z
[ "python", "rest", "web-services", "apache2" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,422,260
<ol> <li><p>Bug will be fixed periodically.</p> <p>Unless you're paying money, you cannot have any idea about this.</p></li> <li><p>Chosen by most developers.</p> <p>mod_wsgi</p></li> <li><p>Additional features like authentication tokens like AWS, can be supported out of the box.</p> <p>True for every framework.</p>...
0
2010-03-11T03:09:56Z
[ "python", "rest", "web-services", "apache2" ]
Apache2: mod_wsgi or mod_python, which one is better?
2,421,007
<p>I am planning to write web service in python. But, I found wsgi also does the similar thing. Which one can be preferred?</p> <p>Thank you<br> Bala</p> <blockquote> <p>Update</p> </blockquote> <p>I am still confused. Please help.</p> <p>Better in my sense means:<br> 1. Bug will be fixed periodically.<br> 2. Cho...
5
2010-03-10T22:10:07Z
2,422,564
<p>mod_wsgi is much more actively maintained than mod_python at this point. It also has a good bit of momentum, as it was somewhat recently adopted as the preferred deployment method on apache2 by Django. The author is also actively engaged with the Python community in regards to the future evolution of WSGI.</p>
1
2010-03-11T04:37:27Z
[ "python", "rest", "web-services", "apache2" ]
Django query with related models
2,421,064
<p>For the below models:</p> <pre><code>class Customer(models.Model): id = models.IntegerField(primary_key=True) class OrderA(models.Model): name = models.CharField(max_length=20) foo = models.FloatField() customer = models.ForeignKey(Customer) type = models.IntegerField() class OrderB(models.Mod...
2
2010-03-10T22:16:46Z
2,421,110
<p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related" rel="nofollow"><code>select_related()</code></a> will pre-populate the appropriate attributes:</p> <pre><code>Customer.objects.filter(ordera_set__type=1, orderb_set__type=1).select_related() </code></pre>
2
2010-03-10T22:26:04Z
[ "python", "django" ]
Django query with related models
2,421,064
<p>For the below models:</p> <pre><code>class Customer(models.Model): id = models.IntegerField(primary_key=True) class OrderA(models.Model): name = models.CharField(max_length=20) foo = models.FloatField() customer = models.ForeignKey(Customer) type = models.IntegerField() class OrderB(models.Mod...
2
2010-03-10T22:16:46Z
2,421,235
<p>You're right in your comment to Ignacio that <code>select_related</code> works in the opposite direction.</p> <p>I've written about a technique to do it in this direction <a href="http://blog.roseman.org.uk/2010/01/11/django-patterns-part-2-efficient-reverse-lookups/" rel="nofollow">on my blog</a> (sorry about the ...
0
2010-03-10T22:46:02Z
[ "python", "django" ]
Python Unicode strings and the Python interactive interpreter
2,421,145
<p>I'm trying to understand how python 2.5 deals with unicode strings. Although by now I think I have a good grasp of how I'm supposed to handle them in code, I don't fully understand what's going on behind the scenes, particularly when you type strings at the interpreter's prompt.</p> <p>So python pre 3.0 has two typ...
3
2010-03-10T22:30:17Z
2,421,175
<p>The interpreter uses your command prompt's native encoding for text entry. In your case it's CP437:</p> <pre><code>&gt;&gt;&gt; print '\xa4'.decode('cp437') ñ </code></pre>
3
2010-03-10T22:35:03Z
[ "python", "string", "unicode", "sublimetext" ]
Python Unicode strings and the Python interactive interpreter
2,421,145
<p>I'm trying to understand how python 2.5 deals with unicode strings. Although by now I think I have a good grasp of how I'm supposed to handle them in code, I don't fully understand what's going on behind the scenes, particularly when you type strings at the interpreter's prompt.</p> <p>So python pre 3.0 has two typ...
3
2010-03-10T22:30:17Z
2,421,258
<p>You're getting confused because the editor and the interpreter are using different encodings themselves. The python interpreter uses your system default (in this case, <code>cp437</code>), while your editor uses <code>utf-8</code>.</p> <p>Note, the difference disappears if you specify a unicode string, like so:</p...
0
2010-03-10T22:49:14Z
[ "python", "string", "unicode", "sublimetext" ]
Python Unicode strings and the Python interactive interpreter
2,421,145
<p>I'm trying to understand how python 2.5 deals with unicode strings. Although by now I think I have a good grasp of how I'm supposed to handle them in code, I don't fully understand what's going on behind the scenes, particularly when you type strings at the interpreter's prompt.</p> <p>So python pre 3.0 has two typ...
3
2010-03-10T22:30:17Z
2,421,327
<p>Let me expand Ignacio's reply: In both cases there is an extra layer between Python and you: in one case it is <em>Sublime Text</em> and in the other it's <code>cmd.exe</code>. The difference in behaviour you see is not due to Python but by the different encodings used by <em>Sublime Text</em> (utf-8, as it seems) a...
6
2010-03-10T23:01:32Z
[ "python", "string", "unicode", "sublimetext" ]
How to filter a query by property of user profile in Django?
2,421,221
<p>I have two models,<code>Design</code> and <code>Profile</code>. Profile is hooked up in settings.py as the profile to be used with the User model. So I can access it via <code>user.get_profile()</code>.</p> <p>And each <code>Design</code> instance has an <code>author</code> property that is a ForeignKey to User.</p...
9
2010-03-10T22:43:14Z
2,421,247
<p>If your profile class is named Profile, and you haven't customized the User &lt;-> Profile relation using the related_name property of the ForeignKey, then shouldn't you be accessing via:</p> <pre><code>designs = Design.objects.filter(author__user__profile__screenname__icontains=w) </code></pre> <p>The User -> Pro...
8
2010-03-10T22:47:41Z
[ "python", "django" ]
How to correctly call base class methods (and constructor) from inherited classes in Python?
2,421,307
<p>Suppose I have a <code>Base</code> class and a <code>Child</code> class that inherits from <code>Base</code>. What is the right way to call the constructor of base class from a child class in Python? Do I use <code>super</code>?</p> <p>Here is an example of what I have so far:</p> <pre><code>class Base(object): ...
24
2010-03-10T22:57:34Z
2,421,325
<p>That is correct. Note that you can also call the <code>__init__</code> method directly on the <code>Base</code> class, like so:</p> <pre><code>class Child(Base): def __init__(self, something_else): Base.__init__(self, value = 20) self.something_else = something_else </code></pre> <p>That's the...
30
2010-03-10T23:01:15Z
[ "python" ]
How to correctly call base class methods (and constructor) from inherited classes in Python?
2,421,307
<p>Suppose I have a <code>Base</code> class and a <code>Child</code> class that inherits from <code>Base</code>. What is the right way to call the constructor of base class from a child class in Python? Do I use <code>super</code>?</p> <p>Here is an example of what I have so far:</p> <pre><code>class Base(object): ...
24
2010-03-10T22:57:34Z
2,421,333
<p>Yes, that's correct. If you wanted to be able to pass <code>value</code> into the <code>Child</code> class you could do it this way</p> <pre><code>class Child(Base): def __init__(self, value, something_else): super(Child, self).__init__(value) self.something_else = something_else ... </code></pr...
8
2010-03-10T23:02:25Z
[ "python" ]
How to correctly call base class methods (and constructor) from inherited classes in Python?
2,421,307
<p>Suppose I have a <code>Base</code> class and a <code>Child</code> class that inherits from <code>Base</code>. What is the right way to call the constructor of base class from a child class in Python? Do I use <code>super</code>?</p> <p>Here is an example of what I have so far:</p> <pre><code>class Base(object): ...
24
2010-03-10T22:57:34Z
2,421,428
<p>If you're using Python 3.1, super is new and improved. It figures out the class and instance arguments for you. So you should call super without arguments:</p> <pre><code>class Child(Base): def __init__(self, value, something_else): super().__init__(value) self.something_else = something_else ...
14
2010-03-10T23:20:40Z
[ "python" ]
How do I modify a generator in Python?
2,421,355
<p>Is there a common interface in Python that I could derive from to modify behavior of a generator?</p> <p>For example, I want to modify an existing generator to insert some values in the stream and remove some other values.</p> <p>How do I do that?</p> <p>Thanks, Boda Cydo</p>
3
2010-03-10T23:06:08Z
2,421,376
<p>You can use the functions provided by <a href="http://docs.python.org/library/itertools.html">itertools</a> to take a generator and produce a new generator.</p> <p>For example, you can use <a href="http://docs.python.org/library/itertools.html#itertools.takewhile">takewhile</a> until a predicate is no longer fulfil...
5
2010-03-10T23:09:36Z
[ "python", "generator" ]
How do I modify a generator in Python?
2,421,355
<p>Is there a common interface in Python that I could derive from to modify behavior of a generator?</p> <p>For example, I want to modify an existing generator to insert some values in the stream and remove some other values.</p> <p>How do I do that?</p> <p>Thanks, Boda Cydo</p>
3
2010-03-10T23:06:08Z
2,421,382
<p>You can just wrap the generator in your own generator.</p> <pre><code>from itertools import count def odd_count(): for i in count(): if i % 2: yield i </code></pre>
3
2010-03-10T23:10:26Z
[ "python", "generator" ]
How to determine if the value is ONE-BUT-LAST in a Python generator?
2,421,368
<p>Since generator returns values lazily, how do I determine if the value returned from a generator is one-but-last? I spent like an hour on this and can't figure it out.</p> <p>Any help appreciated. Is it even possible??</p> <p>Thanks, Boda Cydo!</p>
2
2010-03-10T23:08:04Z
2,421,465
<p>You can wrap the generator in a generator that generates a sequence of pairs whose first element is a boolean telling you whether the element is the last-but-one:</p> <pre><code>def ending(generator): z2 = generator.next() z1 = generator.next() for x in generator: yield (False, z2) z2, z...
10
2010-03-10T23:29:28Z
[ "python", "generator" ]
How to determine if the value is ONE-BUT-LAST in a Python generator?
2,421,368
<p>Since generator returns values lazily, how do I determine if the value returned from a generator is one-but-last? I spent like an hour on this and can't figure it out.</p> <p>Any help appreciated. Is it even possible??</p> <p>Thanks, Boda Cydo!</p>
2
2010-03-10T23:08:04Z
2,421,537
<p>If you want to see arbitrary future values of an iterator without consuming them, you can wrap the iterator in a 'peekable' iterator, that can buffer future values. </p> <pre><code>import collections class PeekIter(object): def __init__(self, iterable): self._iter = iter(iterable) self._peekbu...
2
2010-03-10T23:43:54Z
[ "python", "generator" ]
How to determine if the value is ONE-BUT-LAST in a Python generator?
2,421,368
<p>Since generator returns values lazily, how do I determine if the value returned from a generator is one-but-last? I spent like an hour on this and can't figure it out.</p> <p>Any help appreciated. Is it even possible??</p> <p>Thanks, Boda Cydo!</p>
2
2010-03-10T23:08:04Z
11,040,950
<p>An itertools-based solution</p> <pre><code>from itertools import tee, islice, repeat, chain, izip def gen_with_offset(gen, offset): gen1, gen2 = tee(gen) gen2 = (False for x in gen2) gen2 = chain(islice(gen2, offset, None), [True], repeat(False)) for g, sentinel in izip(gen1, gen2): yield ...
1
2012-06-14T20:33:37Z
[ "python", "generator" ]
Best way to get back to using the power of lxml after having to use a regex to find something in an html document
2,421,396
<p>I am trying to rip some text out of a large number of html documents (numbers in the hundreds of thousands). The documents are really forms but they are prepared by a very large group of different organizations so there is significant variation in how they create the document. For example, the documents are divide...
2
2010-03-10T23:13:03Z
2,421,508
<p>The simplest thing it sounds like you could possibly do is iterate over tree.getroot().iterdescendants() looking for a node with <code>node.text</code> that matches your desired regular expression. From that point, you can pass the node to a function that uses some ad-hoc heuristics to determine where the text is. (...
1
2010-03-10T23:38:02Z
[ "python", "regex", "html-parsing", "lxml" ]
Best way to get back to using the power of lxml after having to use a regex to find something in an html document
2,421,396
<p>I am trying to rip some text out of a large number of html documents (numbers in the hundreds of thousands). The documents are really forms but they are prepared by a very large group of different organizations so there is significant variation in how they create the document. For example, the documents are divide...
2
2010-03-10T23:13:03Z
2,421,610
<p>Sometimes there is not a straight path to getting the content when dealing with poorly or inconsistently written HTML. </p> <p>You might want to look at using lynx or one of the text-based browsers to dump the page content, either into a file, or to pipe it into your code, and then process it. Or, you can use lxml ...
2
2010-03-10T23:58:25Z
[ "python", "regex", "html-parsing", "lxml" ]
Best way to get back to using the power of lxml after having to use a regex to find something in an html document
2,421,396
<p>I am trying to rip some text out of a large number of html documents (numbers in the hundreds of thousands). The documents are really forms but they are prepared by a very large group of different organizations so there is significant variation in how they create the document. For example, the documents are divide...
2
2010-03-10T23:13:03Z
2,466,719
<p>As I feared there is no systematic way to use lxml to identify and extract what I need. O h well I appreciate everyone chiming in. Note-this is not the fault of lxml, it is the fault of the inconsistent html coding. For instance. Because a chapter is a reasonable division of a document all the content in one cha...
1
2010-03-17T23:47:51Z
[ "python", "regex", "html-parsing", "lxml" ]
parsing words in string prefaced by 'password' with regex
2,421,529
<pre><code>a="aaaaaa password: GOD hello world password is G0D hello" match = re.match("^(?:.*(?:password\sis\s|password:\s)([a-zA-Z]*)\s.*)*$",a) print match.groups() </code></pre> <p>i want the output to be ('GOD','G0D') but all i get is ('G0D') i am trying to solve this with Regex only. the amount of times "passwo...
0
2010-03-10T23:42:23Z
2,421,553
<p>The <code>([a-zA-Z]*)</code> regular subexpression does not accept digits, you might have meant <code>([a-zA-Z0-9]+)</code> or another choice would be <code>(\S+)</code>.</p> <p>You have already used <code>\s</code>, are you aware of <code>\S</code>? Because you are using <code>\s</code> as the "delimiter" of your...
0
2010-03-10T23:46:31Z
[ "python", "regex" ]
parsing words in string prefaced by 'password' with regex
2,421,529
<pre><code>a="aaaaaa password: GOD hello world password is G0D hello" match = re.match("^(?:.*(?:password\sis\s|password:\s)([a-zA-Z]*)\s.*)*$",a) print match.groups() </code></pre> <p>i want the output to be ('GOD','G0D') but all i get is ('G0D') i am trying to solve this with Regex only. the amount of times "passwo...
0
2010-03-10T23:42:23Z
2,421,609
<p>I think you'll have to match the first occurrence and then continue matching possible more occurrences using the <code>global matching</code> feature of Pyhon (not sure how to do it, I know very little Python)</p> <p>In PHP for example we can use a preg_match_all to solve this:</p> <pre><code>$a="aaaaaa password: ...
0
2010-03-10T23:58:23Z
[ "python", "regex" ]
parsing words in string prefaced by 'password' with regex
2,421,529
<pre><code>a="aaaaaa password: GOD hello world password is G0D hello" match = re.match("^(?:.*(?:password\sis\s|password:\s)([a-zA-Z]*)\s.*)*$",a) print match.groups() </code></pre> <p>i want the output to be ('GOD','G0D') but all i get is ('G0D') i am trying to solve this with Regex only. the amount of times "passwo...
0
2010-03-10T23:42:23Z
2,421,681
<p>I'd use re.findall, and simplify the regex a bit.</p> <pre><code>&gt;&gt;&gt; re.findall(r"(?:password\sis\s+|password\:\s+)(\S+)", a) ['GOD', 'G0D'] </code></pre> <p>Edit: Changed from \w to \S in order to also capture punctuation, and remove list expression.</p>
1
2010-03-11T00:14:58Z
[ "python", "regex" ]
What is the Bash equivalent of Python's pass statement
2,421,586
<p>Is there a Bash equivalent to the Python's <code>pass</code> statement?</p>
53
2010-03-10T23:54:34Z
2,421,592
<p>You can use <code>:</code> for this.</p>
71
2010-03-10T23:55:25Z
[ "python", "bash", "language-comparisons" ]
What is the Bash equivalent of Python's pass statement
2,421,586
<p>Is there a Bash equivalent to the Python's <code>pass</code> statement?</p>
53
2010-03-10T23:54:34Z
2,421,637
<p><code>true</code> is a command that successfully does nothing.</p> <p>(<code>false</code> would, in a way, be the opposite: it doesn't do anything, but claims that a failure occurred.)</p>
15
2010-03-11T00:07:07Z
[ "python", "bash", "language-comparisons" ]
Similar to ``tabnanny``, how can I check that all the python code is using 4 spaces as an indent?
2,421,755
<p>Similar to <a href="http://docs.python.org/library/tabnanny.html" rel="nofollow">tabnanny</a>, is there a utility for python to check if a python file is using 4 spaces for indentation?</p>
0
2010-03-11T00:32:25Z
2,421,778
<p><a href="http://www.logilab.org/project/pylint" rel="nofollow">Pylint</a> can check this among many other things. Here's a warning it gave me with a test file:</p> <pre><code>W: 3: Bad indentation. Found 3 spaces, expected 4 </code></pre> <p>It's also possible to make it expect another indent type using this comm...
4
2010-03-11T00:39:57Z
[ "python", "tabs" ]
Similar to ``tabnanny``, how can I check that all the python code is using 4 spaces as an indent?
2,421,755
<p>Similar to <a href="http://docs.python.org/library/tabnanny.html" rel="nofollow">tabnanny</a>, is there a utility for python to check if a python file is using 4 spaces for indentation?</p>
0
2010-03-11T00:32:25Z
2,421,785
<p>You can try the reindent.py script, found in tools/scripts of your python install. </p> <blockquote> <p>Change Python (.py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files. Also ensure the last line ends with ...
4
2010-03-11T00:41:15Z
[ "python", "tabs" ]
Similar to ``tabnanny``, how can I check that all the python code is using 4 spaces as an indent?
2,421,755
<p>Similar to <a href="http://docs.python.org/library/tabnanny.html" rel="nofollow">tabnanny</a>, is there a utility for python to check if a python file is using 4 spaces for indentation?</p>
0
2010-03-11T00:32:25Z
2,423,116
<p>Pylint (http://www.logilab.org/project/pylint) checks this (and much more). </p> <p>Other Python code checkers (pep8, pyflakes, pychecker...) may do so too. </p>
1
2010-03-11T06:53:18Z
[ "python", "tabs" ]
Stani's python editor- change syntax coloring
2,421,793
<p>Looking at <a href="http://pythonide.blogspot.com/2008/02/spe-084c-python-ide-editor-released.html" rel="nofollow">Stani's Python IDE</a>, it definitely comes bundled with tons of useful features. Except it doesn't let me do custom syntax coloring. </p> <p>From the Q&amp;A on the author's site:</p> <p>"- changing ...
3
2010-03-11T00:43:09Z
2,465,873
<p>The code I referred to above basically solves the issue, so I'll close the issue.</p>
0
2010-03-17T21:00:36Z
[ "python", "editor", "syntax-highlighting", "customization" ]
Cannot fetch a web site with python urllib.urlopen() or any web browser other than Shiretoko
2,421,857
<p>Here is the URL of the site I want to fetch</p> <p><a href="https://salami.parc.com/spartag/GetRepository?friend=jmankoff&amp;keywords=antibiotic&amp;option=jmankoff%27s+tags" rel="nofollow">https://salami.parc.com/spartag/GetRepository?friend=jmankoff&amp;keywords=antibiotic&amp;option=jmankoff%27s+tags</a></p> <...
0
2010-03-11T01:03:06Z
2,421,873
<p>If you see the <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a> doc, it says</p> <pre><code>urllib2.build_opener([handler, ...])¶ ..... If the Python installation has SSL support (i.e., if the ssl module can be imported), HTTPSHandler will also be added. ..... </code>...
2
2010-03-11T01:08:12Z
[ "python", "beautifulsoup", "urllib" ]
Cannot fetch a web site with python urllib.urlopen() or any web browser other than Shiretoko
2,421,857
<p>Here is the URL of the site I want to fetch</p> <p><a href="https://salami.parc.com/spartag/GetRepository?friend=jmankoff&amp;keywords=antibiotic&amp;option=jmankoff%27s+tags" rel="nofollow">https://salami.parc.com/spartag/GetRepository?friend=jmankoff&amp;keywords=antibiotic&amp;option=jmankoff%27s+tags</a></p> <...
0
2010-03-11T01:03:06Z
2,421,969
<p>That's exactly what you get when you click on the link with a webbrowser. Maybe you are supposed to be logged in or have a cookie set or something</p> <p>I get the same message for firefox 3.5.8 (shiretoko) on linux</p>
0
2010-03-11T01:37:26Z
[ "python", "beautifulsoup", "urllib" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
2,425,463
<p>I'm not sure how extensive the RAW support in Python Imaging Library (PIL <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a>) is, but you may want to check that out.</p> <p>Otherwise, you could just call dcraw directly since it already solves this problem ni...
0
2010-03-11T14:00:52Z
[ "python", "image", "dng", "dcraw" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
6,226,506
<p>Try <a href="http://libopenraw.freedesktop.org/wiki/GettingTheCode" rel="nofollow">http://libopenraw.freedesktop.org/wiki/GettingTheCode</a></p> <p>Git repo: git://anongit.freedesktop.org/git/libopenraw.git</p> <p>There is a python directory in the source tree. ;-)</p>
1
2011-06-03T11:25:36Z
[ "python", "image", "dng", "dcraw" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
6,226,560
<p><a href="http://www.imagemagick.org/" rel="nofollow"><strong>ImageMagick</strong></a> supports <a href="http://www.imagemagick.org/script/formats.php" rel="nofollow">most RAW formats</a> and provides <a href="http://www.imagemagick.org/script/api.php#python" rel="nofollow">Python bindings</a>.</p> <p>As for dcraw b...
4
2011-06-03T11:30:22Z
[ "python", "image", "dng", "dcraw" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
16,842,398
<p>I found this: <a href="https://gitorious.org/dcraw-thumbnailer/mainline/blobs/master/dcraw-thumbnailer" rel="nofollow">https://gitorious.org/dcraw-thumbnailer/mainline/blobs/master/dcraw-thumbnailer</a></p> <p>It calls dcraw as a process from python and converts it to a PIL object.</p>
0
2013-05-30T17:27:05Z
[ "python", "image", "dng", "dcraw" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
28,138,102
<p>I wrote a pure-python library recently called <a href="https://github.com/photoshell/rawphoto" rel="nofollow"><code>rawphoto</code></a> for processing raw images in python. Currently it only supports Canon CR2 files (I'll be adding Nikon formats soon hopefully). It's also on <a href="https://pypi.python.org/pypi/raw...
1
2015-01-25T15:33:56Z
[ "python", "image", "dng", "dcraw" ]
RAW Image processing in Python
2,422,050
<p>Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg. </p> <p>Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well. </p>
22
2010-03-11T01:59:29Z
33,639,608
<p>A while ago I wrote a libraw/dcraw wrapper called <a href="https://pypi.python.org/pypi/rawpy" rel="nofollow">rawpy</a>. It is quite easy to use:</p> <pre><code>import rawpy import imageio raw = rawpy.imread('image.nef') rgb = raw.postprocess() imageio.imsave('default.tiff', rgb) </code></pre> <p>It works nativel...
3
2015-11-10T21:05:09Z
[ "python", "image", "dng", "dcraw" ]
How to Check if request.GET var is None?
2,422,055
<p>Hey, I'm getting into django and this is getting me a headache. I'm trying to get a simple GET variable. URL is site.com/search/?q=search-term</p> <p>My view is:</p> <pre><code>def search(request): if request.method == 'GET' and 'q' in request.GET: q = request.GET.get('q', None) if q is not None: r...
16
2010-03-11T02:00:29Z
2,422,156
<p>Thanks for the clarification by <a href="http://stackoverflow.com/users/145403/ned-deily">@Ned</a>. Found a complete explanation <a href="http://mail.python.org/pipermail/tutor/2002-April/013932.html" rel="nofollow">here</a>.</p> <p>Basically:</p> <blockquote> <p>'==' can be thought of as "value equality", that ...
1
2010-03-11T02:34:45Z
[ "python", "django" ]
How to Check if request.GET var is None?
2,422,055
<p>Hey, I'm getting into django and this is getting me a headache. I'm trying to get a simple GET variable. URL is site.com/search/?q=search-term</p> <p>My view is:</p> <pre><code>def search(request): if request.method == 'GET' and 'q' in request.GET: q = request.GET.get('q', None) if q is not None: r...
16
2010-03-11T02:00:29Z
2,422,422
<p>First, check if the <code>request.GET</code> dict contains a parameter named <code>q</code>. You're doing this properly already:</p> <pre><code>if request.method == 'GET' and 'q' in request.GET: </code></pre> <p>Next, check if the value of <code>q</code> is either <code>None</code> or the empty string. To do that,...
24
2010-03-11T03:54:42Z
[ "python", "django" ]
How to Check if request.GET var is None?
2,422,055
<p>Hey, I'm getting into django and this is getting me a headache. I'm trying to get a simple GET variable. URL is site.com/search/?q=search-term</p> <p>My view is:</p> <pre><code>def search(request): if request.method == 'GET' and 'q' in request.GET: q = request.GET.get('q', None) if q is not None: r...
16
2010-03-11T02:00:29Z
33,459,446
<pre><code>#initialize r = request.GET rg = request.GET.get #write simply as below if r.has_key('q') and rg('q') != '': #process </code></pre>
0
2015-11-01T05:14:49Z
[ "python", "django" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
2,422,202
<p>I don't think there's a built-in function to do multiple replacements in one pass, so you'll have to do it yourself.</p> <p>One way to do it:</p> <pre><code>&gt;&gt;&gt; src = (u'1',u'2',u'3',u'4',u'5',u'6',u'7',u'8',u'9',u'10') &gt;&gt;&gt; dst = ('1','2','3','4','5','6','7','8','9','0') &gt...
3
2010-03-11T02:49:46Z
[ "python", "unicode", "translation" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
2,422,234
<p>Using the <code>unicode.translate</code> method:</p> <pre><code>&gt;&gt;&gt; table = dict(zip(map(ord,u'0123456789'),map(ord,u'0123456789'))) &gt;&gt;&gt; print u'123'.translate(table) 123 </code></pre> <p>It requires a mapping of code points as <em>numbers</em>, not characters. Also, usi...
3
2010-03-11T03:00:20Z
[ "python", "unicode", "translation" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
2,422,245
<p>The built-in <code>unicodedata</code> module can do it:</p> <pre><code>&gt;&gt;&gt; import unicodedata &gt;&gt;&gt; foo = u'1234567890' &gt;&gt;&gt; unicodedata.normalize('NFKC', foo) u'1234567890' </code></pre> <p>The “NFKC” stands for “<a href="http://unicode.org/reports/tr15/" rel="nof...
7
2010-03-11T03:03:34Z
[ "python", "unicode", "translation" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
2,422,285
<p>Regex approach</p> <pre><code>&gt;&gt;&gt; re.sub(u"[\uff10-\uff19]",lambda x:chr(ord(x.group(0))-0xfee0),u"456") u'456' </code></pre>
0
2010-03-11T03:14:45Z
[ "python", "unicode", "translation" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
24,544,518
<p>In Python 3, cleanest is to use <a href="https://docs.python.org/3/library/stdtypes.html#str.translate" rel="nofollow">str.translate</a> and <a href="https://docs.python.org/3/library/stdtypes.html#str.maketrans" rel="nofollow">str.maketrans</a>:</p> <pre><code>FULLWIDTH_TO_HALFWIDTH = str.maketrans('1234ï¼...
1
2014-07-03T03:37:39Z
[ "python", "unicode", "translation" ]
Python: How can I replace full-width characters with half-width characters?
2,422,177
<p>If this was PHP, I would probably do something like this:</p> <pre><code>function no_more_half_widths($string){ $foo = array('1','2','3','4','5','6','7','8','9','10') $bar = array('1','2','3','4','5','6','7','8','9','10') return str_replace($foo, $bar, $string) } </code></pre> <p>I have...
3
2010-03-11T02:42:08Z
36,693,548
<p>In Python3, you can use the following snippet. It made a map between all ascii characters and its corresponding fullwidth character. Best of all, this doesn't need you to hard type ascii sequence, which is quite error prone.</p> <pre><code> #! /usr/bin/env python3 # -*- coding: utf-8 -*- FULL2HALF = dict((i...
1
2016-04-18T12:07:25Z
[ "python", "unicode", "translation" ]
Is there a python openid apps-discovery library to get appengine apps onto the apps marketplace
2,422,220
<p>I'm looking for info on howto get a google appengine app onto the newly announced google apps marketplace.</p> <p>The page at <a href="http://code.google.com/googleapps/marketplace/sso.html" rel="nofollow">http://code.google.com/googleapps/marketplace/sso.html</a> does not have a python openid apps-discovery libra...
4
2010-03-11T02:57:29Z
2,424,328
<p>The <a href="http://openidenabled.com/python-openid/" rel="nofollow">python-openid</a> library appears to support discovery.</p>
0
2010-03-11T10:59:22Z
[ "python", "google-app-engine", "marketplace" ]
Is there a python openid apps-discovery library to get appengine apps onto the apps marketplace
2,422,220
<p>I'm looking for info on howto get a google appengine app onto the newly announced google apps marketplace.</p> <p>The page at <a href="http://code.google.com/googleapps/marketplace/sso.html" rel="nofollow">http://code.google.com/googleapps/marketplace/sso.html</a> does not have a python openid apps-discovery libra...
4
2010-03-11T02:57:29Z
2,598,938
<p>I answered an almost the same question at <a href="http://stackoverflow.com/questions/2313573/google-apps-login-in-django/2575075#2575075">http://stackoverflow.com/questions/2313573/google-apps-login-in-django/2575075#2575075</a>. Check it out.</p> <p>Edited:</p> <p>Actually, your question can be separated into tw...
3
2010-04-08T10:01:46Z
[ "python", "google-app-engine", "marketplace" ]
How to "flush" the response in Pylons (similar to ASP Response.Write)
2,422,434
<p>I have a Pylons controller that is called via jQuery $.ajaxSubmit(). It executes a long-running operation and I want to have it return progress messages before the entire output is available. As a simple proof of concept I've tried this:</p> <pre><code>response.body_file.write('&lt;script&gt;OnExecutionProgress("St...
0
2010-03-11T03:57:29Z
2,422,512
<p>Natively, HTTP does not support the "streaming" you appear to desire -- it's a request/response protocol and there's no protocol-compliant way to send "part of a response". Rather, you may be looking for so-called <a href="http://en.wikipedia.org/wiki/Comet_%28programming%29" rel="nofollow">Comet</a> techniques. A...
1
2010-03-11T04:19:48Z
[ "python", "http", "streaming", "pylons" ]
How to "flush" the response in Pylons (similar to ASP Response.Write)
2,422,434
<p>I have a Pylons controller that is called via jQuery $.ajaxSubmit(). It executes a long-running operation and I want to have it return progress messages before the entire output is available. As a simple proof of concept I've tried this:</p> <pre><code>response.body_file.write('&lt;script&gt;OnExecutionProgress("St...
0
2010-03-11T03:57:29Z
2,496,060
<p>It's definitely a hack, but in pylons it works the same way as in ASP.NET. I've tested it on Paste server.</p> <p>As Alex Martelli said it's better to use Comet in this case. Feeding script chunk by chunk could lead to the following problems:</p> <ol> <li>it's unsupported and server implementation dependent;</li> ...
0
2010-03-22T21:56:00Z
[ "python", "http", "streaming", "pylons" ]
How to "flush" the response in Pylons (similar to ASP Response.Write)
2,422,434
<p>I have a Pylons controller that is called via jQuery $.ajaxSubmit(). It executes a long-running operation and I want to have it return progress messages before the entire output is available. As a simple proof of concept I've tried this:</p> <pre><code>response.body_file.write('&lt;script&gt;OnExecutionProgress("St...
0
2010-03-11T03:57:29Z
9,043,613
<p>You can "yield" your result chunk at a time. Try writing a generator that yields results chunk at a time and it will probably work. It uses <a href="http://en.wikipedia.org/wiki/Chunked_transfer_encoding" rel="nofollow">http://en.wikipedia.org/wiki/Chunked_transfer_encoding</a>.</p>
0
2012-01-28T07:10:34Z
[ "python", "http", "streaming", "pylons" ]
How do I create a list with 256 elements?
2,422,461
<p>I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. </p> <p>I need to generate a list of 256 elements in which each element is the value of <code>math.sin(2*i*pi/256)</code>. The problem is, I don't know how to generate a list init...
2
2010-03-11T04:05:42Z
2,422,476
<pre><code>my_list = [math.sin(2 * math.pi/256) for i in xrange(256)] </code></pre>
5
2010-03-11T04:08:25Z
[ "python" ]
How do I create a list with 256 elements?
2,422,461
<p>I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. </p> <p>I need to generate a list of 256 elements in which each element is the value of <code>math.sin(2*i*pi/256)</code>. The problem is, I don't know how to generate a list init...
2
2010-03-11T04:05:42Z
2,422,501
<p>Two answers have already shown you how to build your list at a single stroke, using the "list comprehension" (AKA "listcomp") construct.</p> <p>To answer your specific question, though,</p> <pre><code>mylist = [None] * 256 </code></pre> <p>is the simplest way to make a list with 256 items, all <code>None</code>, ...
7
2010-03-11T04:16:23Z
[ "python" ]
How do I create a list with 256 elements?
2,422,461
<p>I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. </p> <p>I need to generate a list of 256 elements in which each element is the value of <code>math.sin(2*i*pi/256)</code>. The problem is, I don't know how to generate a list init...
2
2010-03-11T04:05:42Z
2,422,505
<blockquote> <p>I need to generate a list of 256 elements in which each element is the value of math.sin(2*math.pi/256)</p> </blockquote> <p>To answer your question literally:</p> <pre><code>my_list=[math.sin(2*math.pi/256)]*256 </code></pre>
1
2010-03-11T04:17:35Z
[ "python" ]
How do I create a list with 256 elements?
2,422,461
<p>I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. </p> <p>I need to generate a list of 256 elements in which each element is the value of <code>math.sin(2*i*pi/256)</code>. The problem is, I don't know how to generate a list init...
2
2010-03-11T04:05:42Z
2,422,509
<p>You can also try:</p> <pre><code>l = [] for i in range(256): l.append(math.sin(2*math.pi/256)) </code></pre> <p>This is an iterative <code>for</code> loop that keeps adding the same value to the end of the list 256 times</p>
1
2010-03-11T04:18:30Z
[ "python" ]
How do I create a list with 256 elements?
2,422,461
<p>I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. </p> <p>I need to generate a list of 256 elements in which each element is the value of <code>math.sin(2*i*pi/256)</code>. The problem is, I don't know how to generate a list init...
2
2010-03-11T04:05:42Z
2,422,606
<p>Thanks for the help, everyone. I did make a mistake in the specification I posted for the question, in that the value of each element in the list needs to be the sin of the angle <i>incremented</i> by 2*pi/256 each time. The code that works for me in that case is:</p> <pre><code>li = [math.sin((2*math.pi/256)*i) ...
0
2010-03-11T04:49:21Z
[ "python" ]
Are PyArg_ParseTuple() "s" format specifiers useful in Python 3.x C API?
2,422,572
<p>I'm trying to write a Python C extension that processes byte strings, and I have something basically working for Python 2.x and Python 3.x.</p> <p>For the Python 2.x code, near the start of my function, I currently have a line:</p> <pre><code> if (!PyArg_ParseTuple(args, "s#:in_bytes", &amp;src_ptr, &amp;src_le...
3
2010-03-11T04:40:39Z
2,422,610
<p>I agree with you -- it's one of several spots where the C API migration of Python 3 was clearly not designed as carefully and thouroughly as the Python coder-visible parts. I do also agree that probably the best workaround for now is focusing on "buffer views", per that macro -- until and unless something better ge...
3
2010-03-11T04:50:52Z
[ "python", "python-3.x" ]
Filter across three tables using Django
2,422,668
<p>I have 3 django models, where the first has a foreign key to the second, and the second has a foreign key to the third. Like this:</p> <pre><code> class Book(models.Model): year_published = models.IntField() author = models.ForeignKey(Author) class Author(models.Model): author_id = models.AutoField(pri...
1
2010-03-11T05:07:14Z
2,422,764
<pre><code>LitAgent.objects.filter(author__book__year_published=2006) </code></pre>
9
2010-03-11T05:33:31Z
[ "python", "django" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
2,422,829
<p>to join a windows path, try</p> <pre><code>mypath=os.path.join('c:\\', 'sourcedir') </code></pre> <p>basically, you will need to escape the slash</p>
2
2010-03-11T05:45:09Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
2,422,847
<p>The reason <code>os.path.join('C:', 'src')</code> is not working as you expect is because of something in the documentation that you linked to:</p> <blockquote> <p>Note that on Windows, since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current dir...
7
2010-03-11T05:47:30Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
2,422,864
<p>Windows has a concept of current directory for each drive. Because of that, <code>"c:sourcedir"</code> means "sourcedir" inside the current C: directory, and you'll need to specify an absolute directory.</p> <p>Any of these should work and give the same result, but I don't have a Windows VM fired up at the moment ...
20
2010-03-11T05:52:34Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
7,435,335
<p>To be pedantic, it's probably not good to hardcode either / or \ as the path separator. Maybe this would be best?</p> <pre><code>mypath = os.path.join('c:%s' % os.sep, 'sourcedir') </code></pre> <p>or </p> <pre><code>mypath = os.path.join('c:' + os.sep, 'sourcedir') </code></pre>
8
2011-09-15T17:56:29Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
7,767,925
<p>To be even more pedantic, the most python doc consistent answer would be:</p> <pre><code>mypath = os.path.join('c:', os.sep, 'sourcedir') </code></pre> <p>Since you also need os.sep for the posix root path:</p> <pre><code>mypath = os.path.join(os.sep, 'usr', 'lib') </code></pre>
45
2011-10-14T12:56:25Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
17,399,914
<p>I'd say this is a (windows)python bug.</p> <p>Why bug? </p> <p>I think this statement should be <code>True</code></p> <pre><code>os.path.join(*os.path.dirname(os.path.abspath(__file__)).split(os.path.sep))==os.path.dirname(os.path.abspath(__file__)) </code></pre> <p>But it is <code>False</code> on windows machin...
3
2013-07-01T08:09:41Z
[ "python", "windows", "path-manipulation" ]
Python os.path.join on Windows
2,422,798
<p>I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the <a href="http://docs.python.org/library/os.path.html">docs</a> if I say:</p> <pre><code>os.path.join('c:', 'sourcedir') </code></pre> <p>I get <code>"C:sourcedir"</c...
45
2010-03-11T05:38:19Z
36,100,196
<p>Consent with @georg-</p> <p>I would say then why we need lame <code>os.path.join</code>- better to use <code>str.join</code> or <code>unicode.join</code> e.g.</p> <pre><code>sys.path.append('{0}'.join(os.path.dirname(__file__).split(os.path.sep)[0:-1]).format(os.path.sep)) </code></pre>
1
2016-03-19T09:49:43Z
[ "python", "windows", "path-manipulation" ]
Python: avoiding if condition?
2,422,905
<p>Which is better? <pre><code>if not var: var = get_var()</pre></code> (or)<br/></p> <blockquote> <p>var = var or get_var()</p> </blockquote> <p>Also, How do I know the better of the two?<br/> <b>edit:</b><br/>One more option from steve,</p> <pre><code>var = var if var else get_var()</code></pre>
4
2010-03-11T06:00:17Z
2,422,919
<p>The better is the one you like better. I would use first version with <code>if</code> but this is very personal.</p>
7
2010-03-11T06:02:35Z
[ "python", "variable-assignment", "condition" ]
Python: avoiding if condition?
2,422,905
<p>Which is better? <pre><code>if not var: var = get_var()</pre></code> (or)<br/></p> <blockquote> <p>var = var or get_var()</p> </blockquote> <p>Also, How do I know the better of the two?<br/> <b>edit:</b><br/>One more option from steve,</p> <pre><code>var = var if var else get_var()</code></pre>
4
2010-03-11T06:00:17Z
2,422,921
<p>Second one is more pythonic, and I normally use that.</p>
1
2010-03-11T06:03:02Z
[ "python", "variable-assignment", "condition" ]
Python: avoiding if condition?
2,422,905
<p>Which is better? <pre><code>if not var: var = get_var()</pre></code> (or)<br/></p> <blockquote> <p>var = var or get_var()</p> </blockquote> <p>Also, How do I know the better of the two?<br/> <b>edit:</b><br/>One more option from steve,</p> <pre><code>var = var if var else get_var()</code></pre>
4
2010-03-11T06:00:17Z
2,422,925
<p>the first version is more intuitive to me. But then again, its all about your own taste.</p>
2
2010-03-11T06:03:40Z
[ "python", "variable-assignment", "condition" ]
Python: avoiding if condition?
2,422,905
<p>Which is better? <pre><code>if not var: var = get_var()</pre></code> (or)<br/></p> <blockquote> <p>var = var or get_var()</p> </blockquote> <p>Also, How do I know the better of the two?<br/> <b>edit:</b><br/>One more option from steve,</p> <pre><code>var = var if var else get_var()</code></pre>
4
2010-03-11T06:00:17Z
2,422,926
<p>Neither is wrong.</p> <p>The former is clearer to understand for someone reading the code.</p> <p>Ask yourself if, when you are thinking about the problem you are trying to solve, the concepts that come to mind are closer to "if this, then that" or "a logical OR of two almost, but not quite, Boolean variables."</p...
1
2010-03-11T06:03:41Z
[ "python", "variable-assignment", "condition" ]
Python: avoiding if condition?
2,422,905
<p>Which is better? <pre><code>if not var: var = get_var()</pre></code> (or)<br/></p> <blockquote> <p>var = var or get_var()</p> </blockquote> <p>Also, How do I know the better of the two?<br/> <b>edit:</b><br/>One more option from steve,</p> <pre><code>var = var if var else get_var()</code></pre>
4
2010-03-11T06:00:17Z
2,422,929
<p>To me, the first idiom, the one using the explicit if, is preferable because more explicit.</p> <p>However I've seen the or construct being referenced as the preferred / more pythonic one.</p> <p>So, on the one hand, <code>Explicit is better than implicit</code> (Zen citation), on the other hand, the short expres...
2
2010-03-11T06:04:52Z
[ "python", "variable-assignment", "condition" ]