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
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?
1,646,641
<p>I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example:</p> <pre><code>small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] </code></pre> <p>I tried usi...
4
2009-10-29T21:23:55Z
1,646,720
<p><strong>Edit: Leaving the answer here but I failed to note the requirement that they be in the same order. This does not meet that requirement</strong></p> <p>Quick and dirty answer. Based it off of the answer for <a href="http://stackoverflow.com/questions/642763/python-intersection-of-two-lists">Python - Intersec...
1
2009-10-29T21:36:45Z
[ "python" ]
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?
1,646,641
<p>I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example:</p> <pre><code>small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] </code></pre> <p>I tried usi...
4
2009-10-29T21:23:55Z
1,646,729
<p>you could use sets</p> <pre><code>from sets import Set small_set = set(small_list) big_set = set(big_list) small_set &lt;= big_set </code></pre> <p>&lt;= is the subset operator</p>
0
2009-10-29T21:38:04Z
[ "python" ]
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?
1,646,641
<p>I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example:</p> <pre><code>small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] </code></pre> <p>I tried usi...
4
2009-10-29T21:23:55Z
1,646,777
<p>Hmm, maybe it's overkill, but you can use the SequenceMatcher class from difflib:</p> <pre><code>from difflib import SequenceMatcher small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] print SequenceMatcher(None, small_list, big_list).get_matching_blocks() </code></pre> <p><a href="http://docs.python.o...
4
2009-10-29T21:47:47Z
[ "python" ]
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?
1,646,641
<p>I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example:</p> <pre><code>small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] </code></pre> <p>I tried usi...
4
2009-10-29T21:23:55Z
1,647,558
<p>If you know a reasonable bound of your numbers, you can convert them to a Python type whose 'in' operator does this automatically. The two I know are <code>str</code> and <code>unicode</code>.</p> <p>Then you ask the strings if the smaller is in the larger, this does a substring comparison:</p> <pre><code>&gt;&gt;...
1
2009-10-30T01:33:08Z
[ "python" ]
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?
1,646,641
<p>I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example:</p> <pre><code>small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] </code></pre> <p>I tried usi...
4
2009-10-29T21:23:55Z
1,650,046
<p>If you want to use the "in" keyword to do what you want, you can override <strong>contains</strong> using one of the solutions mentioned in the answers here:</p> <pre><code>class mylist(list): def __contains__(self, lst): return ':'.join(map(str, lst)) in ':'.join(map(str, self)) small_list = mylist([4...
0
2009-10-30T14:14:43Z
[ "python" ]
problem when re-running program
1,646,747
<p>I have a fairly simple python loop that calls a few functions, and writes the output to a file. To do this is creates a folder, and saves the file in this folder.</p> <p>When I run the program the first time with a unique file name, it runs fine. However, if I try to run it again, it will not work and I do not unde...
1
2009-10-29T21:41:45Z
1,647,106
<p>I can't see how the file name in the error message blahblah\buff1.shp can arise from your code.</p> <pre><code>for i in range(0,1): buffer_shp = newpath + "buff" + str(i) + ".shp" gp.Buffer_analysis(center_services, buffer_shp, etc etc) </code></pre> <p>should produce <code>blahblah\buff0.shp</code> not <c...
2
2009-10-29T23:09:24Z
[ "python", "file", "python-2.5" ]
problem when re-running program
1,646,747
<p>I have a fairly simple python loop that calls a few functions, and writes the output to a file. To do this is creates a folder, and saves the file in this folder.</p> <p>When I run the program the first time with a unique file name, it runs fine. However, if I try to run it again, it will not work and I do not unde...
1
2009-10-29T21:41:45Z
3,781,598
<p>I'd be tempted to look again at </p> <p>path = "C:\LEED\Cities_20_Oct\services\"</p> <p>Surely you want double front slashes, not double back slashes?</p>
0
2010-09-23T18:54:48Z
[ "python", "file", "python-2.5" ]
problem when re-running program
1,646,747
<p>I have a fairly simple python loop that calls a few functions, and writes the output to a file. To do this is creates a folder, and saves the file in this folder.</p> <p>When I run the program the first time with a unique file name, it runs fine. However, if I try to run it again, it will not work and I do not unde...
1
2009-10-29T21:41:45Z
15,118,012
<p>I see this is a 3 year old posting, but for others will add:</p> <p>As I generate python script to work with Arc, I always include right after my import:</p> <pre><code>arcpy.env.overwriteOutput=True # This allows the script to overwrite files. </code></pre> <p>Also you mentioned you delete your "folder"?. Tha...
1
2013-02-27T17:07:41Z
[ "python", "file", "python-2.5" ]
referencing a key/value in django-templates after applying a filter
1,646,757
<p>say I have the following list that I provide to a django template</p> <pre><code>stuff= [ { 'a':2 , 'b':4 } , { 'a',7} ] </code></pre> <p>I want to access the 'a' attribute of the first element. I can't quite get the syntax right.</p> <pre><code>{{stuff|first}} </code></pre> <p>gives me the first element, but</p...
1
2009-10-29T21:43:31Z
1,646,820
<p>This is off the top of my head, but I think it is</p> <pre><code>{{ stuff.0.a }} </code></pre>
4
2009-10-29T21:55:29Z
[ "python", "django", "django-templates" ]
Adapt an existing database to a django app
1,646,786
<p>I have a Postgresql databese with data. I want to create a django app with that database.</p> <p>How can i import the tables to django models and/or views?</p>
6
2009-10-29T21:49:02Z
1,646,799
<p>Read this: <a href="http://docs.djangoproject.com/en/dev/howto/legacy-databases/">http://docs.djangoproject.com/en/dev/howto/legacy-databases/</a></p> <p>There is a utility to generate models from your existing database. It works pretty well.</p>
14
2009-10-29T21:51:36Z
[ "python", "database", "postgresql", "django-models", "django-views" ]
Adapt an existing database to a django app
1,646,786
<p>I have a Postgresql databese with data. I want to create a django app with that database.</p> <p>How can i import the tables to django models and/or views?</p>
6
2009-10-29T21:49:02Z
1,647,019
<p>If your database is not very simple -- or very well designed -- you'll find it a poor fit with Django.</p> <p>While the <a href="http://docs.djangoproject.com/en/dev/howto/legacy-databases/" rel="nofollow">reverse engineering</a> works well, you may find that the original database design was flawed and you have lo...
3
2009-10-29T22:42:37Z
[ "python", "database", "postgresql", "django-models", "django-views" ]
How can I use Microsoft Word's spelling/grammar checker programmatically?
1,646,801
<p>I want to process a medium to large number of text snippets using a spelling/grammar checker to get a <em>rough</em> approximation and ranking of their "quality." Speed is not really of concern either, so I think the easiest way is to write a script that passes off the snippets to Microsoft Word (2007) and runs its...
6
2009-10-29T21:52:04Z
1,647,718
<p>It took some digging, but I think I found a useful solution. Following the advice at <a href="http://www.nabble.com/Edit-a-Word-document-programmatically-td19974320.html">http://www.nabble.com/Edit-a-Word-document-programmatically-td19974320.html</a> I'm using the <a href="http://sourceforge.net/projects/pywin32/">...
8
2009-10-30T02:40:36Z
[ "python", "com", "ms-word", "word-2007", "win32com" ]
Correct way to access related objects
1,647,043
<p>I have the following models</p> <pre><code>class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job = model.Charfield(max_length=200) class PhoneNumber(models.Model): person = models.ForeignKey(Person) </code></pre> <p>How do I access the PhoneNumbers associated...
2
2009-10-29T22:49:02Z
1,647,067
<p>You could do:</p> <pre><code>employees = Employee.objects.filter(id=your_id).select_related() if employees.count() == 1: phone_numbers = employees[0].phonenumber_set.all() </code></pre> <p>That should get you all your phone numbers in one db query.</p> <p>By default you can access models related through a for...
4
2009-10-29T22:57:13Z
[ "python", "django", "django-models" ]
Correct way to access related objects
1,647,043
<p>I have the following models</p> <pre><code>class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job = model.Charfield(max_length=200) class PhoneNumber(models.Model): person = models.ForeignKey(Person) </code></pre> <p>How do I access the PhoneNumbers associated...
2
2009-10-29T22:49:02Z
1,647,514
<p>You can (and should) filter without knowing the foreign key field:</p> <pre><code>PhoneNumber.objects.filter(employee=your_employee).all() </code></pre>
5
2009-10-30T01:10:43Z
[ "python", "django", "django-models" ]
Python question on elementwise operation
1,647,112
<p>I have two srtings of integer a=[-1,0,-1,0,1] and b=[1] and i want to subtract b from a as elementwise operation but the answer shoud be string contaning element -1 or 0 or 1 </p>
-2
2009-10-29T23:10:47Z
1,647,936
<p>Maybe you mean this:</p> <pre><code>def elementwise_subtraction_of_strings_of_integer(a, b): c = b * (len(a) // len(b)) return [aa - bb for aa, bb in zip(a, c)] if __name__ == '__main__': a=[-1,0,-1,0,1] b=[1] print elementwise_subtraction_of_strings_of_integer(a, b) </code></pre> <p>It produc...
2
2009-10-30T03:54:26Z
[ "python" ]
Getting Easting & Northing Values from geopy
1,647,408
<p>I have a table full of longitude/ latitude pairs in decimal format (e.g., -41.547, 23.456). I want to display the values in <a href="http://en.wikipedia.org/wiki/Easting%5Fand%5Fnorthing" rel="nofollow">"Easting and Northing"</a>/ <a href="http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM" rel="nofollow">UTM</a>...
1
2009-10-30T00:37:56Z
1,647,653
<p>Nope. You need to reproject your points, and geopy isn't going to do that for you.</p> <p>What you need is <a href="http://www.gdal.org/" rel="nofollow">libgdal</a> and some Python bindings. I always use the bindings in GeoDjango, but there are <a href="http://trac.osgeo.org/gdal/wiki/GdalOgrInPython" rel="nofollow...
2
2009-10-30T02:16:22Z
[ "python", "geocoding", "geopy", "formats" ]
Getting Easting & Northing Values from geopy
1,647,408
<p>I have a table full of longitude/ latitude pairs in decimal format (e.g., -41.547, 23.456). I want to display the values in <a href="http://en.wikipedia.org/wiki/Easting%5Fand%5Fnorthing" rel="nofollow">"Easting and Northing"</a>/ <a href="http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM" rel="nofollow">UTM</a>...
1
2009-10-30T00:37:56Z
1,682,836
<p>I think I may have over-complicated things. All I wanted was the dms values (so 42.519540, -70.896716 becomes 42º31'10.34" N 70º53'48.18" W). You can get this by creating a geopy point object with your long and lat, then calling format(). However, as of this writing, format() is broken and requires the <a href="ht...
0
2009-11-05T19:03:57Z
[ "python", "geocoding", "geopy", "formats" ]
How to encode an RSA key using PKCS12 in Python?
1,647,568
<p>I'm using Python (under Google App Engine), and I have some RSA private keys that I need to export in PKCS#12 format. Is there anything out there that will assist me with this? I'm using PyCrypto/KeyCzar, and I've figured out how to import/export RSA keys in PKCS8 format, but I really need it in PKCS12.</p> <p>Can ...
2
2009-10-30T01:35:30Z
1,647,585
<p>The standard tool for the job is typically <a href="http://www.openssl.org/" rel="nofollow">OpenSSL</a>.</p> <p>See the <a href="http://www.openssl.org/docs/apps/pkcs12.html#" rel="nofollow"><code>openssl pkcs12</code></a> command.</p>
0
2009-10-30T01:41:46Z
[ "python", "google-app-engine", "cryptography", "rsa", "pkcs#12" ]
How to encode an RSA key using PKCS12 in Python?
1,647,568
<p>I'm using Python (under Google App Engine), and I have some RSA private keys that I need to export in PKCS#12 format. Is there anything out there that will assist me with this? I'm using PyCrypto/KeyCzar, and I've figured out how to import/export RSA keys in PKCS8 format, but I really need it in PKCS12.</p> <p>Can ...
2
2009-10-30T01:35:30Z
1,647,590
<p>This mailing list posting tends to suggest that PKCS12 is not planned for a future feature of that package, and is not currently implemented.</p> <p><a href="http://lists.dlitz.net/pipermail/pycrypto/2009q2/000104.html" rel="nofollow">http://lists.dlitz.net/pipermail/pycrypto/2009q2/000104.html</a></p>
0
2009-10-30T01:44:29Z
[ "python", "google-app-engine", "cryptography", "rsa", "pkcs#12" ]
How to encode an RSA key using PKCS12 in Python?
1,647,568
<p>I'm using Python (under Google App Engine), and I have some RSA private keys that I need to export in PKCS#12 format. Is there anything out there that will assist me with this? I'm using PyCrypto/KeyCzar, and I've figured out how to import/export RSA keys in PKCS8 format, but I really need it in PKCS12.</p> <p>Can ...
2
2009-10-30T01:35:30Z
1,648,617
<p>If you can handle some ASN.1 generation, you can relatively easily convert a PKCS#8-file into a PKCS#12-file. A PKCS#12-file is basically a wrapper around a PKCS#8 and a certificate, so to make a PKCS#12-file, you just have to add some additional data around your PKCS#8-file and your certificate.</p> <p>Usually a P...
2
2009-10-30T08:29:58Z
[ "python", "google-app-engine", "cryptography", "rsa", "pkcs#12" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
1,647,596
<p>If you're binding to the instance, you shouldn't include the self argument:</p> <pre><code>&gt;&gt;&gt; class foo(object): ... pass ... &gt;&gt;&gt; def donothing(): ... pass ... &gt;&gt;&gt; f = foo() &gt;&gt;&gt; f.x = donothing &gt;&gt;&gt; f.x() &gt;&gt;&gt; </code></pre> <p>You do need the self argu...
4
2009-10-30T01:49:32Z
[ "python" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
1,647,610
<p>Your example is kind of twisted and complex, and I don't quite see what it has to do with your question. Feel free to clarify if you like.</p> <p>However, it's pretty easy to do what you're looking to do, assuming I'm reading your question right.</p> <pre><code>class Foo(object): def bar(self): print('...
0
2009-10-30T01:58:38Z
[ "python" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
1,647,616
<p><strong>Everything you wanted to know about <a href="http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html" rel="nofollow">Python Attributes and Methods</a>.</strong></p> <p>Yes, this is an indirect answer, but it demonstrates a number of techniques and explains some of the ...
13
2009-10-30T02:01:55Z
[ "python" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
1,647,794
<p>If you ever need to do it for a <em>special</em> method (which, for a new-style class -- which is what you should always be using and the only kind in Python 3 -- is looked up on the class, not the instance), you can just make a per-instance class, e.g....:</p> <pre><code>self.foo = Foo() meths = {'__str__': lambda...
4
2009-10-30T03:06:55Z
[ "python" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
1,649,014
<p>Do Not Do This.</p> <p>Changing one instance's methods is just wrong.</p> <p>Here are the rules of OO Design.</p> <ol> <li><p>Avoid Magic.</p></li> <li><p>If you can't use inheritance, use delegation.</p></li> </ol> <p>That means that every time you think you need something magic, you should have been writing a ...
1
2009-10-30T10:26:39Z
[ "python" ]
Is it possible to change an instance's method implementation without changing all other instances of the same class?
1,647,586
<p>I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go:</p> <p>I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementati...
9
2009-10-30T01:42:06Z
12,022,621
<p>Since Python 2.6, you should use the <code>types</code> module's <code>MethodType</code> class:</p> <pre><code>from types import MethodType class A(object): def m(self): print 'aaa' a = A() def new_m(self): print 'bbb' a.m = MethodType(new_m, a) </code></pre> <p>As another answer pointed out, h...
5
2012-08-18T22:15:34Z
[ "python" ]
How can I send an iCalendar email attachment with Django?
1,647,597
<p>I want to send an iCalendar <a href="http://en.wikipedia.org/wiki/ICalendar" rel="nofollow">http://en.wikipedia.org/wiki/ICalendar</a> email attachment using Django. Is there an open source library to build an iCalendar file in Python and/or available for Django?</p>
3
2009-10-30T01:49:37Z
1,647,623
<p>I've used MaxM's <a href="http://pypi.python.org/pypi/icalendar/" rel="nofollow">icalendar</a> module. It can build and parse iCalendar files. </p>
4
2009-10-30T02:05:46Z
[ "python", "django", "icalendar" ]
How can I send an iCalendar email attachment with Django?
1,647,597
<p>I want to send an iCalendar <a href="http://en.wikipedia.org/wiki/ICalendar" rel="nofollow">http://en.wikipedia.org/wiki/ICalendar</a> email attachment using Django. Is there an open source library to build an iCalendar file in Python and/or available for Django?</p>
3
2009-10-30T01:49:37Z
1,648,397
<p>There's also <a href="http://pypi.python.org/pypi/vobject/" rel="nofollow">vobject</a> which was developed for the Chandler project and seems to be more actively maintained. It's also BSD-licensed which might be important for your use case.</p>
3
2009-10-30T07:01:24Z
[ "python", "django", "icalendar" ]
How can I send an iCalendar email attachment with Django?
1,647,597
<p>I want to send an iCalendar <a href="http://en.wikipedia.org/wiki/ICalendar" rel="nofollow">http://en.wikipedia.org/wiki/ICalendar</a> email attachment using Django. Is there an open source library to build an iCalendar file in Python and/or available for Django?</p>
3
2009-10-30T01:49:37Z
1,649,799
<p>As stated before, there is <a href="http://vobject.skyhouseconsulting.com/">vobject</a>, that is working fine (I have used it recently). </p> <p>You can find good information about ical, vobject and django in this blog post : </p> <p><a href="http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/">h...
7
2009-10-30T13:24:35Z
[ "python", "django", "icalendar" ]
Multi Language Starter Templates
1,647,614
<p>I'm currently working through some code katas in multiple languages (Ruby, Perl, Python)/frameworks (Rails, Django, Mojo). It seems every time I start a new project from scratch I end up tweaking files to my liking, even after using things like newgem, module-starter, script/generate, startapp, etc.</p> <p>For thos...
0
2009-10-30T02:01:19Z
1,647,672
<p>Just use the templating capabilities of your editor.</p> <p>For vim, check out <a href="http://vim.wikia.com/wiki/Snippets%5Ffor%5FJavaScript,%5FHTML%5Fand%5FPython" rel="nofollow">this example</a>.</p> <h2>Update:</h2> <p>Which editor? The choice of editor is too deeply personal and reliant on individual prefere...
2
2009-10-30T02:20:40Z
[ "python", "ruby", "perl", "templates", "starter-kits" ]
Python PyQT4 - Adding an unknown number of QComboBox widgets to QGridLayout
1,647,664
<p>I want to retrieve a list of people's names from a queue and, for each person, place a checkbox with their name to a QGridLayout using the addWidget() function. I can successfully place the items in a QListView, but they just write over the top of each other rather than creating a new row. Does anyone have any thoug...
0
2009-10-30T02:18:25Z
1,647,754
<p>I can't tell you the solution in PyQt but the structure you need to follow is the following. The QListView can do what you need, you don't need to create separate checkboxes. Create a subclass of <a href="http://doc.trolltech.com/4.5/qabstractitemmodel.html" rel="nofollow"><code>QAbstractItemModel</code></a> or <a h...
0
2009-10-30T02:53:01Z
[ "python", "pyqt", "qcombobox", "qlistview" ]
Python PyQT4 - Adding an unknown number of QComboBox widgets to QGridLayout
1,647,664
<p>I want to retrieve a list of people's names from a queue and, for each person, place a checkbox with their name to a QGridLayout using the addWidget() function. I can successfully place the items in a QListView, but they just write over the top of each other rather than creating a new row. Does anyone have any thoug...
0
2009-10-30T02:18:25Z
1,648,142
<p>This line:</p> <pre><code>QtGui.QCheckBox('%s' % item, self.chk_People) </code></pre> <p>Doesn't add the check box to the list view, it only creates it with the list view as the parent, and there's a big difference. </p> <p>The simplest way to use a list view is the <code>QListWidget</code> convenience class. For...
1
2009-10-30T05:21:34Z
[ "python", "pyqt", "qcombobox", "qlistview" ]
mod_python django logging problem
1,647,974
<p>I use logging settings as below in the settings.py file:</p> <p><hr /></p> <p>logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT);</p> <p>handler = logging.handlers.RotatingFileHandler( LOG_FILE_PATH, 'a', LOG_FILE_SIZE,LOG_FILE_NUM );</p> <p>formatter = logging.Formatter ( LOG_FORMAT );</p> <p>handler.setF...
0
2009-10-30T04:10:00Z
1,648,183
<p><code>RotatingFileHandler</code> is not designed to work in multiprocess system. Each process you have notice that file is too large and starts new log, so you get up to 5 new logs. It's not as easy to implement it properly: you have to obtain interprocess lock before creating new file and inform each process to reo...
1
2009-10-30T05:36:54Z
[ "python", "django", "logging" ]
Is there a rails.vim equivalent for Django?
1,648,214
<p>I <em>love</em> Tim Pope's <a href="http://rails.vim.tpope.net/" rel="nofollow">rails.vim</a>, and I'm wondering if there's an equivalent vim plugin for Django. I'm especially looking for easy navigation of the Django file structure via vim command mode.</p>
4
2009-10-30T05:52:28Z
1,648,323
<p>Theres nothing as well structured as that plugin.</p> <p>As far as quick navigation goes I have this in my vimrc</p> <p><a href="http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings" rel="nofollow">http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings</a> (That whole doc will give you some good ...
2
2009-10-30T06:31:41Z
[ "python", "django", "vim" ]
Is there a rails.vim equivalent for Django?
1,648,214
<p>I <em>love</em> Tim Pope's <a href="http://rails.vim.tpope.net/" rel="nofollow">rails.vim</a>, and I'm wondering if there's an equivalent vim plugin for Django. I'm especially looking for easy navigation of the Django file structure via vim command mode.</p>
4
2009-10-30T05:52:28Z
1,648,331
<p>I use <a href="http://www.vim.org/scripts/script.php?script%5Fid=1487" rel="nofollow">django.vim</a> for Django Templates</p>
3
2009-10-30T06:35:43Z
[ "python", "django", "vim" ]
Is there a rails.vim equivalent for Django?
1,648,214
<p>I <em>love</em> Tim Pope's <a href="http://rails.vim.tpope.net/" rel="nofollow">rails.vim</a>, and I'm wondering if there's an equivalent vim plugin for Django. I'm especially looking for easy navigation of the Django file structure via vim command mode.</p>
4
2009-10-30T05:52:28Z
1,869,065
<p>I've created a repo that I want to add a lot of branches to for vim config (django/python centric). There are already a few branches and some path-hacking for settings.py. Feel free to fork/branch and share!</p> <p><a href="http://github.com/skyl/vim-config-python-ide" rel="nofollow">http://github.com/skyl/vim-co...
1
2009-12-08T18:51:52Z
[ "python", "django", "vim" ]
Is there a rails.vim equivalent for Django?
1,648,214
<p>I <em>love</em> Tim Pope's <a href="http://rails.vim.tpope.net/" rel="nofollow">rails.vim</a>, and I'm wondering if there's an equivalent vim plugin for Django. I'm especially looking for easy navigation of the Django file structure via vim command mode.</p>
4
2009-10-30T05:52:28Z
11,597,963
<p>The django wiki page on using vim now lists the <a href="https://github.com/rainerborene/vim-pony" rel="nofollow">pony.vim</a> plugin, which seems like it gives similar things to rails.vim, including the ability to jump between models, views, templates, etc per app, as well as run some of the django commands right f...
1
2012-07-22T05:31:51Z
[ "python", "django", "vim" ]
Is there a rails.vim equivalent for Django?
1,648,214
<p>I <em>love</em> Tim Pope's <a href="http://rails.vim.tpope.net/" rel="nofollow">rails.vim</a>, and I'm wondering if there's an equivalent vim plugin for Django. I'm especially looking for easy navigation of the Django file structure via vim command mode.</p>
4
2009-10-30T05:52:28Z
11,957,015
<p>** Update 10/8/2013 **</p> <p>I'm now using a jedi driven python vim configuration (along with some tmux config)</p> <p><a href="https://github.com/JarrodCTaylor/imt_dotfiles" rel="nofollow">https://github.com/JarrodCTaylor/imt_dotfiles</a></p> <hr> <p>I also have a fairly complete vim config for django developm...
0
2012-08-14T16:45:30Z
[ "python", "django", "vim" ]
Common errors when moving a django app from dev to prod?
1,648,349
<p>I am developping a django app on Windows, SQLite and the django dev server . I have deployed it to my host server which is running Linux, Apache, FastCgi, MySQL.</p> <p>Unfortunately, I have an error returned by the server on the prod while everything ok on the dev machine. I've asked my provider for a pre-producti...
5
2009-10-30T06:42:15Z
1,648,406
<p>Problems I typically have include:</p> <ol> <li>Misconfigured productions settings, whether in my production localsettings.py, wsgi/cgi, or apache site files in /etc/sites-available</li> <li>Database differences. I use <a href="http://south.aeracode.org/" rel="nofollow">South</a> for migrations and have run into so...
7
2009-10-30T07:03:38Z
[ "python", "django", "production-environment" ]
Common errors when moving a django app from dev to prod?
1,648,349
<p>I am developping a django app on Windows, SQLite and the django dev server . I have deployed it to my host server which is running Linux, Apache, FastCgi, MySQL.</p> <p>Unfortunately, I have an error returned by the server on the prod while everything ok on the dev machine. I've asked my provider for a pre-producti...
5
2009-10-30T06:42:15Z
1,648,578
<p>Regarding your case, I can think of 2 simple things that may help you:</p> <ol> <li>You can enable Django to send messages when exceptions occur giving details about them. Look at <a href="http://docs.djangoproject.com/en/dev/howto/error-reporting/" rel="nofollow">here</a> for details.</li> <li>You'll be better off...
1
2009-10-30T08:17:44Z
[ "python", "django", "production-environment" ]
Common errors when moving a django app from dev to prod?
1,648,349
<p>I am developping a django app on Windows, SQLite and the django dev server . I have deployed it to my host server which is running Linux, Apache, FastCgi, MySQL.</p> <p>Unfortunately, I have an error returned by the server on the prod while everything ok on the dev machine. I've asked my provider for a pre-producti...
5
2009-10-30T06:42:15Z
1,649,923
<p>I believe these were the podcasts I listened to recently (from Pycon 2009):</p> <blockquote> <p>Locate Django in the Real World (PyCon 2009):</p> <p><a href="http://advocacy.python.org/podcasts/pycon.rss" rel="nofollow">http://advocacy.python.org/podcasts/pycon.rss</a></p> <p>Parts 1 to 3</p> </blockquo...
0
2009-10-30T13:49:29Z
[ "python", "django", "production-environment" ]
ConfigParser with Unicode items
1,648,517
<p>my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt overriding <code>optionxform</code> could help:</p> <pre><code>-- configfi...
14
2009-10-30T07:52:14Z
1,648,865
<p>The <code>ConfigParser.readfp()</code> method can take a file object, have you tried opening the file object with the correct encoding using the codecs module before sending it to ConfigParser like below:</p> <pre><code>cfg.readfp(codecs.open("myconfig", "r", "utf8")) </code></pre> <p>For Python 3.2 or above, <a h...
17
2009-10-30T09:44:13Z
[ "python", "unicode", "configparser" ]
ConfigParser with Unicode items
1,648,517
<p>my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt overriding <code>optionxform</code> could help:</p> <pre><code>-- configfi...
14
2009-10-30T07:52:14Z
8,525,875
<p>The config module is broken when reading and writing unicode strings as values. I tried to fix it, but got caught up in the odd way the parser works.</p>
0
2011-12-15T20:01:35Z
[ "python", "unicode", "configparser" ]
ConfigParser with Unicode items
1,648,517
<p>my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt overriding <code>optionxform</code> could help:</p> <pre><code>-- configfi...
14
2009-10-30T07:52:14Z
35,141,031
<p>Seems to be a problem with the ConfigParser version for python 2x, and version for 3x is free of this problem. In <a href="http://bugs.python.org/issue11597" rel="nofollow">this issue of the Python Bug Tracker</a>, the status is Closed + WONTFIX.</p> <p>I've fixed it editing the ConfigParser.py file. In the write m...
0
2016-02-01T21:49:59Z
[ "python", "unicode", "configparser" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,570
<p>I think the best way to approach this would be to use python's built-in <a href="http://docs.python.org/library/csv.html">csv</a> module.</p> <p>Because the csv module only <a href="http://docs.python.org/library/csv.html#csv-fmt-params">allows</a> a one character <code>quotechar</code>, you would need to do a repl...
5
2009-10-30T08:14:45Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,611
<p>I certainly agree with @Wogan above, that using the CSV moudle is a good approach. Having said that if you still want to try a regex solution give this a try, but you will have to adapt it to Python dialect</p> <pre><code>string.split(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/) </code></pre> <p>HTH</p>
0
2009-10-30T08:28:16Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,626
<p>One way to do it is to use <code>findall</code> with a regex that greedily matches things that can go between separators. eg:</p> <pre><code>&gt;&gt;&gt; s = "Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" &gt;&gt;&gt; r = re.compile(r'(?:[^,(]|\([^)]*\))+') &gt;&gt;&gt;...
13
2009-10-30T08:34:22Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,628
<p>My answer will not use regex.</p> <p>I think simple character scanner with state "<code>in_actor_name</code>" should work. Remember then state "<code>in_actor_name</code>" is terminated either by ')' or by comma in this state.</p> <p>My try:</p> <pre><code>s = 'Wilbur Smith (Billy, son of John), Eddie Murphy (Joh...
1
2009-10-30T08:35:24Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,664
<p>split by ")"</p> <pre><code>&gt;&gt;&gt; s="Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" &gt;&gt;&gt; s.split(")") ['Wilbur Smith (Billy, son of John', ', Eddie Murphy (John', ', Elvis Presley, Jane Doe (Jane Doe', ''] &gt;&gt;&gt; for i in s.split(")"): ... print i....
0
2009-10-30T08:47:48Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,648,745
<pre><code>s = re.split(r',\s*(?=[^)]*(?:\(|$))', x) </code></pre> <p>The lookahead matches everything up to the next open-parenthesis or to the end of the string, <strong>iff</strong> there's no close-parenthesis in between. That ensures that the comma is not inside a set of parentheses.</p>
4
2009-10-30T09:13:23Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,649,114
<p>An attempt on human-readable regex:</p> <pre><code>import re regex = re.compile(r""" # name starts and ends on word boundary # no '(' or commas in the name (?P&lt;name&gt;\b[^(,]+\b) \s* # everything inside parentheses is a role (?:\( (?P&lt;role&gt;[^)]+) \))? # role is optional ...
2
2009-10-30T10:48:22Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,653,602
<p>Here's a general technique I've used in the past for such cases:</p> <p>Use the <code>sub</code> function of the <code>re</code> module with a function as replacement argument. The function keeps track of opening and closing parens, brackets and braces, as well as single and double quotes, and performs a replacemen...
0
2009-10-31T06:23:17Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
1,654,652
<p>None of the answers above are correct if there are any errors or noise in your data.</p> <p>It's easy to come up with a good solution if you know the data is right every time. But what happens if there are formatting errors? What do you want to have happen?</p> <p>Suppose there are nesting parentheses? Suppose ...
-1
2009-10-31T15:06:48Z
[ "python", "regex", "split" ]
How to split a string by commas positioned outside of parenthesis?
1,648,537
<p>I got a string of such format: </p> <pre><code>"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" </code></pre> <p>so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly ...
16
2009-10-30T08:02:09Z
13,573,834
<p>This post helped me a lot. I was looking to split a string by commas positioned outside quotes. I used this as a starter. My final line of code was <code>regEx = re.compile(r'(?:[^,"]|"[^"]*")+')</code> This did the trick. Thanks a ton.</p>
1
2012-11-26T21:56:10Z
[ "python", "regex", "split" ]
Watching sockets with Glib on Windows puts them in non-blocking mode
1,648,631
<p>The following code does not work correctly on Windows (but does on Linux):</p> <pre><code> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(True) sock.connect(address) gobject.io_add_watch( sock.fileno(), gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HU...
3
2009-10-30T08:36:02Z
1,733,028
<p>Is there a problem with doing non-blocking I/O? It seems kind of strange to use polling loops if you're using blocking I/O.</p> <p>When I write programs like this I tend to do the following:</p> <ul> <li><p>Buffer the bytes I want to send to the file descriptor.</p></li> <li><p>Only ask for <code>IO_OUT</code> (o...
1
2009-11-14T02:28:29Z
[ "python", "windows", "pygtk", "glib", "gio" ]
Watching sockets with Glib on Windows puts them in non-blocking mode
1,648,631
<p>The following code does not work correctly on Windows (but does on Linux):</p> <pre><code> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(True) sock.connect(address) gobject.io_add_watch( sock.fileno(), gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HU...
3
2009-10-30T08:36:02Z
1,763,387
<p>I'm not sure if this helps (I'm not proficient with the poll function or the MFC sockets and don't know the polling is a requirement of your program structure), so take this with a grain of salt: </p> <p>But to avoid a blocking or EAGAIN on write, we use select, i.e. add the socket to the write set that is passed t...
0
2009-11-19T13:43:35Z
[ "python", "windows", "pygtk", "glib", "gio" ]
Watching sockets with Glib on Windows puts them in non-blocking mode
1,648,631
<p>The following code does not work correctly on Windows (but does on Linux):</p> <pre><code> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(True) sock.connect(address) gobject.io_add_watch( sock.fileno(), gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HU...
3
2009-10-30T08:36:02Z
4,062,426
<p><a href="http://library.gnome.org/devel/gio/unstable/index.html" rel="nofollow">GIO</a> contains <a href="http://library.gnome.org/devel/gio/unstable/GSocket.html" rel="nofollow">GSocket</a>, a "lowlevel network socket object" since 2.22. However this is yet to be ported to <a href="http://ftp.gnome.org/pub/GNOME/bi...
1
2010-10-31T08:46:25Z
[ "python", "windows", "pygtk", "glib", "gio" ]
Watching sockets with Glib on Windows puts them in non-blocking mode
1,648,631
<p>The following code does not work correctly on Windows (but does on Linux):</p> <pre><code> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(True) sock.connect(address) gobject.io_add_watch( sock.fileno(), gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HU...
3
2009-10-30T08:36:02Z
5,939,893
<p>You could use <a href="http://twistedmatrix.com/" rel="nofollow">Twisted</a>, which includes <a href="http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#auto11" rel="nofollow">support for GTK</a> (even on Windows) and will handle all the <a href="http://itamarst.org/writings/win32sockets.htm...
0
2011-05-09T16:41:12Z
[ "python", "windows", "pygtk", "glib", "gio" ]
Python logging using a decorator
1,648,707
<p>This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like.</p> <p>A simple decorator named LOG. It should work like this:</p> <pre><code>@LOG def f(a, b=2, *c, **d): pass </code></pre> <p>And the result should be something like:</p> <pre><code>f(1, ...
23
2009-10-30T09:02:59Z
1,649,195
<p>The only thing I noticed is that the <code>dict((varList[i], v) for i, v in enumerate(argt))</code> construct you used twice is actually <code>dict(zip(varList,argt))</code>. </p> <p>Other than that i only have meta-criticism: None of the above belong in a logfile. </p> <p>Instead of going trough the logs to</p> ...
5
2009-10-30T11:06:42Z
[ "python", "logging", "introspection", "decorator" ]
Python logging using a decorator
1,648,707
<p>This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like.</p> <p>A simple decorator named LOG. It should work like this:</p> <pre><code>@LOG def f(a, b=2, *c, **d): pass </code></pre> <p>And the result should be something like:</p> <pre><code>f(1, ...
23
2009-10-30T09:02:59Z
1,649,299
<p>Everyhing is ok in your function. You seem to be lost with positional vs variable&amp;keyword arguments.</p> <p>Let me explain: positional arguments, <code>a</code> and <code>b</code> in your case, are obligatory (and may have default values). Other arguments are optional. If you want to make an argument obligatory...
1
2009-10-30T11:33:34Z
[ "python", "logging", "introspection", "decorator" ]
Python logging using a decorator
1,648,707
<p>This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like.</p> <p>A simple decorator named LOG. It should work like this:</p> <pre><code>@LOG def f(a, b=2, *c, **d): pass </code></pre> <p>And the result should be something like:</p> <pre><code>f(1, ...
23
2009-10-30T09:02:59Z
39,640,530
<p>I found your nice solution can slightly be improved upon, if you take into account that a general function theoretically can return an iterable, in which case an error is thrown.</p> <p>Here is a solution for this:</p> <blockquote> <p>Wrap <code>print 'return: %s' % ret</code> into an if statement:<br> <code>i...
0
2016-09-22T13:32:27Z
[ "python", "logging", "introspection", "decorator" ]
Given a latitude and longitude, and distance, I want to find a bounding box
1,648,917
<p>Given a latitude and longitude, and distance, I want to find a bounding box where the distances are less than the given distance.</p> <p>This questions was asked here: <a href="http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location">http://stackoverflow.com/questio...
4
2009-10-30T10:01:38Z
1,648,932
<p>That line is converting the bounding box units from kilometres to metres.</p>
2
2009-10-30T10:05:58Z
[ "python", "geocoding", "bounding-box" ]
Given a latitude and longitude, and distance, I want to find a bounding box
1,648,917
<p>Given a latitude and longitude, and distance, I want to find a bounding box where the distances are less than the given distance.</p> <p>This questions was asked here: <a href="http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location">http://stackoverflow.com/questio...
4
2009-10-30T10:01:38Z
7,110,219
<p>This code didn't quite work, it jumps between KM and M.</p> <p>Fixed code, made names more PEP8 style, and added a simple box object:</p> <pre><code>class BoundingBox(object): def __init__(self, *args, **kwargs): self.lat_min = None self.lon_min = None self.lat_max = None self.l...
7
2011-08-18T15:44:08Z
[ "python", "geocoding", "bounding-box" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
1,648,978
<p>Try</p> <pre><code> count = sum(map(lambda x: 0 if x is None else 1, (foo, bar, baz))) if count &gt; 1: raise Ex() </code></pre> <p>That turns <code>None</code> into 0 and everything into 1 and then sums everything up.</p>
4
2009-10-30T10:17:55Z
[ "python" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
1,648,982
<p>How about:</p> <pre><code> initialisers = [foo, bar, baz] if initialisers.count(None) &lt; len(initialisers) - 1: raise Ex() </code></pre> <p>It simply counts how many <code>None</code> are present. If they're all <code>None</code> or only one isn't then fine, otherwise it raises the exception.</p>
9
2009-10-30T10:18:39Z
[ "python" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
1,648,998
<p>Like this.</p> <pre><code>def func( self, **kw ): assert len(kw) == 1, "Too Many Arguments" assert kw.keys[0] in ( 'foo', 'bar', 'baz' ), "Argument not foo, bar or baz" </code></pre>
-1
2009-10-30T10:21:59Z
[ "python" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
1,650,145
<pre><code>if len(filter(lambda x: x != None, locals().values())) &gt; 1: raise Exception() </code></pre> <p>Edited to address Alex's point.</p>
1
2009-10-30T14:31:17Z
[ "python" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
1,650,660
<p><code>x!=None</code> returns <code>True</code> (whose numeric value is <code>1</code>!) for non-Nones, <code>False</code> (whose numeric value is 0) for Nones. So,</p> <pre><code>sum(x!=None for x in (foo, bar, baz)) </code></pre> <p>is the simplest way to count how many of those identifiers are bound to non-None...
6
2009-10-30T15:55:48Z
[ "python" ]
How to assert that zero or only one of N given arguments is passed
1,648,956
<p>I have a definition like this</p> <pre><code>def bar(self, foo=None, bar=None, baz=None): pass </code></pre> <p>I want to make sure a maximum of one of foo, bar, baz is passed. I can do </p> <pre><code>if foo and bar: raise Ex() if foo and baz: raise Ex() .... </code></pre> <p>But there got be somet...
4
2009-10-30T10:11:55Z
3,408,573
<p>I have even shorter answer, with my favorite python feature - decorators:</p> <pre><code>def single_keyword(func): def single_keyword_dec(*args, **kw): if len(kw) &gt; 1: raise Exception("More than one initializer passed: {0}".format(kw.keys())) return func(*args, **kw) return si...
2
2010-08-04T18:26:52Z
[ "python" ]
Python library path
1,649,186
<p>I have a python file "testHTTPAuth.py" which uses module deliciousapi and is kept in "deliciousapi.py". </p> <p>I have kept the files like </p> <pre><code>testHTTPAuth.py lib deliciousapi.py </code></pre> <p>But when i run: "python testHTTPAuth.py" it's giving error</p> <pre><code> import deliciousapi Impo...
1
2009-10-30T11:04:27Z
1,649,202
<p>If you add an empty <code>__init__.py</code> to your lib directory, you can change your import statement to:</p> <pre><code>from lib import deliciousapi </code></pre>
1
2009-10-30T11:07:50Z
[ "python", "google-app-engine", "shared-libraries" ]
Python library path
1,649,186
<p>I have a python file "testHTTPAuth.py" which uses module deliciousapi and is kept in "deliciousapi.py". </p> <p>I have kept the files like </p> <pre><code>testHTTPAuth.py lib deliciousapi.py </code></pre> <p>But when i run: "python testHTTPAuth.py" it's giving error</p> <pre><code> import deliciousapi Impo...
1
2009-10-30T11:04:27Z
1,649,218
<p>You need to add the 'lib' directory to your path - otherwise, Python can't find your source. The following (included in a module such as testHTTPAuth.py) will do that:</p> <pre><code>sys.path.append(os.path.join(os.path.dirname(__file__), 'lib') </code></pre> <p>Ned's suggestion of changing your imports may work, ...
9
2009-10-30T11:11:57Z
[ "python", "google-app-engine", "shared-libraries" ]
Overriding Django views with decorators
1,649,351
<p>I have a situation that requires redirecting users who are already logged in away from the login page to another page. I have seen mention that this can be accomplished with decorators which makes sense, but I am fairly new to using them. However, I am using the django login and a third party view (from django-reg...
2
2009-10-30T11:50:56Z
1,649,395
<p>If you have the decorator function and you know which view in django-registration you want to decorate, you could just do</p> <pre><code>registration.view_func = decorator_func(registration.view_func) </code></pre> <p>where <code>registration</code> is the module in django-registration which contains the view func...
2
2009-10-30T12:01:43Z
[ "python", "django", "django-views" ]
Overriding Django views with decorators
1,649,351
<p>I have a situation that requires redirecting users who are already logged in away from the login page to another page. I have seen mention that this can be accomplished with decorators which makes sense, but I am fairly new to using them. However, I am using the django login and a third party view (from django-reg...
2
2009-10-30T11:50:56Z
1,649,487
<p>Three more ways to do it, though you'll need to use your own urlconf for these:</p> <ol> <li><p>Add the decorator to the view directly in the urlconf:</p> <pre><code>... (regexp, decorator(view)), ... </code></pre> <p>You need to import the view and the decorator into the urlconf though, which is why I don't like...
6
2009-10-30T12:21:38Z
[ "python", "django", "django-views" ]
Is it still Python 2.6 versus Python 3?
1,649,391
<p>G'day,</p> <p>I'm wanting to go back to Python after not using it for a while and I saw this question <a href="http://stackoverflow.com/questions/345255/python-version-for-a-newbie">"Python Version for a Newbie"</a> while wondering about getting back into Python 2.6 or Python 3.</p> <p>Almost all of the questions'...
8
2009-10-30T12:00:54Z
1,649,406
<p>If you want to use only standard library then try Python 3.1. If you want to use others libraries/frameworks then they dictate the version to use. For example web2py framework will work best on 2.5.</p>
2
2009-10-30T12:03:46Z
[ "python", "python-3.x", "version" ]
Is it still Python 2.6 versus Python 3?
1,649,391
<p>G'day,</p> <p>I'm wanting to go back to Python after not using it for a while and I saw this question <a href="http://stackoverflow.com/questions/345255/python-version-for-a-newbie">"Python Version for a Newbie"</a> while wondering about getting back into Python 2.6 or Python 3.</p> <p>Almost all of the questions'...
8
2009-10-30T12:00:54Z
1,649,408
<p>The problem is, if you started with 2.4 or more it is better if you start from there, so you'll get on track faster, after some time when you feel comfortable with you code you can try 3.0 and find out what did they change and learn the new style.</p> <p>I for once still code in 2.6 style and follow those guideline...
1
2009-10-30T12:03:57Z
[ "python", "python-3.x", "version" ]
Is it still Python 2.6 versus Python 3?
1,649,391
<p>G'day,</p> <p>I'm wanting to go back to Python after not using it for a while and I saw this question <a href="http://stackoverflow.com/questions/345255/python-version-for-a-newbie">"Python Version for a Newbie"</a> while wondering about getting back into Python 2.6 or Python 3.</p> <p>Almost all of the questions'...
8
2009-10-30T12:00:54Z
1,649,416
<p>Depends on the amount of libraries you're going to use.</p> <ul> <li><p>Raw Python, or all libs are available for Py3k - go for it without any doubts.</p></li> <li><p>Python code distributed as standalone app (using PyInstaller), relying on some GUI lib, XML-lib, win32api etc - double check if all libs are availabl...
3
2009-10-30T12:04:48Z
[ "python", "python-3.x", "version" ]
Is it still Python 2.6 versus Python 3?
1,649,391
<p>G'day,</p> <p>I'm wanting to go back to Python after not using it for a while and I saw this question <a href="http://stackoverflow.com/questions/345255/python-version-for-a-newbie">"Python Version for a Newbie"</a> while wondering about getting back into Python 2.6 or Python 3.</p> <p>Almost all of the questions'...
8
2009-10-30T12:00:54Z
1,649,418
<p>Yes. Virtually all live production systems will use 2.5/2.6 for a long time yet. There's no point learning 3.0, only to have to downgrade it because your host doesn't support it.</p> <p>95% of what you will learn in 2.5/2.6 is applicable to 3 anyway.</p>
9
2009-10-30T12:05:16Z
[ "python", "python-3.x", "version" ]
Is it still Python 2.6 versus Python 3?
1,649,391
<p>G'day,</p> <p>I'm wanting to go back to Python after not using it for a while and I saw this question <a href="http://stackoverflow.com/questions/345255/python-version-for-a-newbie">"Python Version for a Newbie"</a> while wondering about getting back into Python 2.6 or Python 3.</p> <p>Almost all of the questions'...
8
2009-10-30T12:00:54Z
1,652,844
<p>I would say that Python 2.4 is the safest to learn, but the changes from 2.4->2.5->2.6 make some small progress towards Python 3.x, even if they may never make it (if I recall there will be some more steps?).</p> <p>Python 3.1 can be used if you own a dedicated server and intend to build your own applications from ...
2
2009-10-30T23:50:51Z
[ "python", "python-3.x", "version" ]
How to handle multiple Set-Cookie header in HTTP response
1,649,401
<p>I'm trying to write simple proxy server for some purpose. In it I use httplib to access remote web-server. But there's one problem: web server returns TWO Set-Cookie headers in one response, and httplib mangles them together in httplib.HTTPResponse.getheaders(), effectively joining cookies with comma [which is stran...
4
2009-10-30T12:03:07Z
1,649,579
<p><code>HTTPResponse.getheaders()</code> returns a list of combined headers (actually my calling <code>dict.items()</code>). The only place where incoming headers are stored untouched is <code>HTTPResponse.msg.headers</code>.</p>
4
2009-10-30T12:37:25Z
[ "python", "httplib" ]
Problem compiling Python 2.6.4 on AIX 5.3
1,649,412
<p>I'm trying to build Python 2.6.4 on AIX 5.3. I'm running configure like this:</p> <pre> ./configure --prefix=/home/chenf/python --disable-ipv6 --disable-shared --with-libs='/usr/lib/libncurses.a' --without-threads --disable-threads --with-ncurses=/utv/sad/ncurses/lib/libncurses.a </pre> <p>I seem to be having link...
0
2009-10-30T12:04:30Z
1,650,283
<p>It looks like bzip2 isn't able to find itself, either -- sometimes you see weird Python build errors when you wander too far from GCC. My first gut recommendation would be to compile with GCC, GNU binutils, and GNU make, and see if the problem persists.</p> <p>Also, when you're talking to <code>configure</code>, i...
1
2009-10-30T14:52:56Z
[ "python", "compilation", "aix", "ncurses" ]
Problem compiling Python 2.6.4 on AIX 5.3
1,649,412
<p>I'm trying to build Python 2.6.4 on AIX 5.3. I'm running configure like this:</p> <pre> ./configure --prefix=/home/chenf/python --disable-ipv6 --disable-shared --with-libs='/usr/lib/libncurses.a' --without-threads --disable-threads --with-ncurses=/utv/sad/ncurses/lib/libncurses.a </pre> <p>I seem to be having link...
0
2009-10-30T12:04:30Z
1,661,609
<p>Thanks to Jed Smith's suggestions, I've managed to get this to work. This is what I did accomplish this:</p> <ul> <li><p><strong>Step one:</strong> First, I edited "Makefile.pre.in". I replaced the line "CC= @CC@" with "CC= gcc". As far as I can tell, this forced the compilation to use gcc instead of whatever o...
0
2009-11-02T14:27:32Z
[ "python", "compilation", "aix", "ncurses" ]
Problem compiling Python 2.6.4 on AIX 5.3
1,649,412
<p>I'm trying to build Python 2.6.4 on AIX 5.3. I'm running configure like this:</p> <pre> ./configure --prefix=/home/chenf/python --disable-ipv6 --disable-shared --with-libs='/usr/lib/libncurses.a' --without-threads --disable-threads --with-ncurses=/utv/sad/ncurses/lib/libncurses.a </pre> <p>I seem to be having link...
0
2009-10-30T12:04:30Z
9,372,135
<p>This is so old problem(2009 ??)..but I meet the same problem today!! For other AIX users like me...I will leave my case</p> <p>OK..first, Check your environmental variable OBJECT_MODE.</p> <p>In my case, OBJECT_MODE was 64, but the archive file libcurses.a contains only 32bit object files!!</p> <p>After changing...
1
2012-02-21T04:20:39Z
[ "python", "compilation", "aix", "ncurses" ]
Strange Problem with RPy2
1,649,503
<p>After installing RPy2 from </p> <p><a href="http://rpy.sourceforge.net/rpy2.html" rel="nofollow">http://rpy.sourceforge.net/rpy2.html</a></p> <p>I'm trying to use it in Python 2.6 IDLE but I'm getting this error:</p> <pre><code>&gt;&gt;&gt; import rpy2.robjects as robjects &gt;&gt;&gt; robjects.r['pi'] &lt;RVect...
2
2009-10-30T12:24:28Z
1,650,315
<p>In the Python interactive interpreter if an expression returns a value then that value is automatically printed. For example if you create a dictionary and extract a value from it the value is automatically printed, but if this was in an executing script this would not be the case. Look at the following simple examp...
1
2009-10-30T14:58:01Z
[ "python", "python-idle" ]
Strange Problem with RPy2
1,649,503
<p>After installing RPy2 from </p> <p><a href="http://rpy.sourceforge.net/rpy2.html" rel="nofollow">http://rpy.sourceforge.net/rpy2.html</a></p> <p>I'm trying to use it in Python 2.6 IDLE but I'm getting this error:</p> <pre><code>&gt;&gt;&gt; import rpy2.robjects as robjects &gt;&gt;&gt; robjects.r['pi'] &lt;RVect...
2
2009-10-30T12:24:28Z
1,650,359
<p>Have you tried looking at the vector that's returned?</p> <pre><code> &gt;&gt;&gt; pi = robjects.r['pi'] &gt;&gt;&gt; pi[0] 3.14159265358979 </code></pre>
7
2009-10-30T15:06:09Z
[ "python", "python-idle" ]
Strange Problem with RPy2
1,649,503
<p>After installing RPy2 from </p> <p><a href="http://rpy.sourceforge.net/rpy2.html" rel="nofollow">http://rpy.sourceforge.net/rpy2.html</a></p> <p>I'm trying to use it in Python 2.6 IDLE but I'm getting this error:</p> <pre><code>&gt;&gt;&gt; import rpy2.robjects as robjects &gt;&gt;&gt; robjects.r['pi'] &lt;RVect...
2
2009-10-30T12:24:28Z
1,651,151
<p>To expand on Shane's answer. rpy2 uses the following Python objects to represent the basic R types:</p> <ul> <li>RVector: R scalars and vectors, R Lists are represented as RVectors with names, see below</li> <li>RArray: an R matrix, essentially the RVector with a dimension </li> <li>RDataFrame: an R data.frame</l...
5
2009-10-30T17:15:40Z
[ "python", "python-idle" ]
Strange Problem with RPy2
1,649,503
<p>After installing RPy2 from </p> <p><a href="http://rpy.sourceforge.net/rpy2.html" rel="nofollow">http://rpy.sourceforge.net/rpy2.html</a></p> <p>I'm trying to use it in Python 2.6 IDLE but I'm getting this error:</p> <pre><code>&gt;&gt;&gt; import rpy2.robjects as robjects &gt;&gt;&gt; robjects.r['pi'] &lt;RVect...
2
2009-10-30T12:24:28Z
2,645,673
<p>This is not an error, it's simply the 'repr' of the returned robject:</p> <pre><code>&gt;&gt;&gt; r['pi'] &lt;RVector - Python:0x2c14bd8 / R:0x3719538&gt; &gt;&gt;&gt; repr(r['pi']) '&lt;RVector - Python:0x4b77908 / R:0x3719538&gt;' &gt;&gt;&gt; str(r['pi']) '[1] 3.141593' &gt;&gt;&gt; print r['pi'] [1] 3.141593 </...
1
2010-04-15T13:32:34Z
[ "python", "python-idle" ]
Strange Problem with RPy2
1,649,503
<p>After installing RPy2 from </p> <p><a href="http://rpy.sourceforge.net/rpy2.html" rel="nofollow">http://rpy.sourceforge.net/rpy2.html</a></p> <p>I'm trying to use it in Python 2.6 IDLE but I'm getting this error:</p> <pre><code>&gt;&gt;&gt; import rpy2.robjects as robjects &gt;&gt;&gt; robjects.r['pi'] &lt;RVect...
2
2009-10-30T12:24:28Z
3,878,545
<p>I found this as the only sensible, short discussion of how to go back and forth from R objects and python. naufraghi's solution prompted the following approach to converting a data.frame, which retains the nicer slicing capabilities of the dataframe:</p> <pre><code>In [69]: import numpy as np In [70]: import rpy2....
0
2010-10-07T03:52:38Z
[ "python", "python-idle" ]
Generating a dynamic time delta: python
1,649,753
<p>Here's my situation:</p> <pre><code>import foo, bar, etc frequency = ["hours","days","weeks"] class geoProcessClass(): def __init__(self,geoTaskHandler,startDate,frequency,frequencyMultiple=1,*args): self.interval = self.__determineTimeDelta(frequency,frequencyMultiple) def __determineTimeDelta(...
1
2009-10-30T13:12:30Z
1,649,804
<p>You can call a function with dynamic arguments using syntax like <code>func(**kwargs)</code> where <code>kwargs</code> is dictionary of name/value mappings for the named arguments.</p> <p>I also renamed the global <code>frequency</code> list to <code>frequencies</code> since the line <code>if frequency in frequency...
4
2009-10-30T13:26:05Z
[ "python", "datetime", "eval", "timedelta" ]
Generating a dynamic time delta: python
1,649,753
<p>Here's my situation:</p> <pre><code>import foo, bar, etc frequency = ["hours","days","weeks"] class geoProcessClass(): def __init__(self,geoTaskHandler,startDate,frequency,frequencyMultiple=1,*args): self.interval = self.__determineTimeDelta(frequency,frequencyMultiple) def __determineTimeDelta(...
1
2009-10-30T13:12:30Z
1,649,806
<p>Your use of <code>print eval(...)</code> looks a bit over-complicated (and wrong, as you mention).</p> <p>If you want to pass a keyword argument to a function, just do it:</p> <pre><code>interval = datetime.timedelta(frequency = str(frequencyMultiple) </code></pre> <p>I don't see a keyword argument called <code>f...
0
2009-10-30T13:26:20Z
[ "python", "datetime", "eval", "timedelta" ]
Swampy.1.1 with Python 3
1,650,095
<p>I am reading the book <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">Think Python</a> by Allen Downey. For chapter 4, one has to use a suite of modules called <a href="http://www.greenteapress.com/thinkpython/swampy/" rel="nofollow">Swampy</a>. I have downloaded and installed it.</p> <p>The prob...
3
2009-10-30T14:24:29Z
1,650,126
<p>Many important third-party libraries have not yet been rewritten for Python 3; you'll have to stick to Python 2.x for now. There is no way around it. As it says on the <a href="http://www.python.org/download/" rel="nofollow">official Python download page</a>,</p> <blockquote> <p>If you don't know which version to...
3
2009-10-30T14:28:24Z
[ "python", "python-3.x" ]
Swampy.1.1 with Python 3
1,650,095
<p>I am reading the book <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">Think Python</a> by Allen Downey. For chapter 4, one has to use a suite of modules called <a href="http://www.greenteapress.com/thinkpython/swampy/" rel="nofollow">Swampy</a>. I have downloaded and installed it.</p> <p>The prob...
3
2009-10-30T14:24:29Z
1,650,135
<p>There is a conversion tool for converting Python 2 code to work with Python 3: <a href="http://svn.python.org/view/sandbox/trunk/2to3/" rel="nofollow">http://svn.python.org/view/sandbox/trunk/2to3/</a></p> <p>Not sure how this extends to 3rd party libraries but it might be worth passing this over the swampy code.</...
0
2009-10-30T14:29:21Z
[ "python", "python-3.x" ]
Swampy.1.1 with Python 3
1,650,095
<p>I am reading the book <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">Think Python</a> by Allen Downey. For chapter 4, one has to use a suite of modules called <a href="http://www.greenteapress.com/thinkpython/swampy/" rel="nofollow">Swampy</a>. I have downloaded and installed it.</p> <p>The prob...
3
2009-10-30T14:24:29Z
10,375,365
<p>It looks like tkinter is finally catching up with Python 3 - tkFont has become tkinter.font</p> <p><a href="http://docs.pythonsprints.com/python3_porting/py-porting.html">http://docs.pythonsprints.com/python3_porting/py-porting.html</a></p> <pre><code>#!/usr/bin/env python3.2 # -*- coding: utf-8 -*- # # fon...
5
2012-04-29T19:44:12Z
[ "python", "python-3.x" ]
Swampy.1.1 with Python 3
1,650,095
<p>I am reading the book <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">Think Python</a> by Allen Downey. For chapter 4, one has to use a suite of modules called <a href="http://www.greenteapress.com/thinkpython/swampy/" rel="nofollow">Swampy</a>. I have downloaded and installed it.</p> <p>The prob...
3
2009-10-30T14:24:29Z
17,641,515
<p>FOR MAC USERS: I'm a Python newbie and came across the exact same problem. I'm writing this so others don't waste several hours trying to figure this out. Here's what you do: </p> <ul> <li>Do NOT install Python 3 for the above reasons, i.e. to avoid having to change all the Swampy code. Instead, download the latest...
1
2013-07-14T16:56:17Z
[ "python", "python-3.x" ]
Convert & to &amp; in Python
1,650,160
<p>I'm working on a simple crawler in Python. The aim is to create a sitemap.xml. (you can find the very alpha version here: <a href="http://code.google.com/p/sitemappy/" rel="nofollow">http://code.google.com/p/sitemappy/</a>) I noticed that if I generate the xml with URLs containing non HTML entities (such as &amp;), ...
1
2009-10-30T14:33:02Z
1,650,176
<p><a href="http://docs.python.org/library/cgi.html#cgi.escape"><code>cgi.escape</code></a> to the rescue:</p> <blockquote> <p><code>cgi.escape(s[, quote])</code></p> <p>Convert the characters '&amp;', '&lt;' and '>' in string s to HTML-safe sequences. Use this if you need to display text that might contain suc...
4
2009-10-30T14:36:11Z
[ "python", "xml", "sitemap", "urlencode" ]
Convert & to &amp; in Python
1,650,160
<p>I'm working on a simple crawler in Python. The aim is to create a sitemap.xml. (you can find the very alpha version here: <a href="http://code.google.com/p/sitemappy/" rel="nofollow">http://code.google.com/p/sitemappy/</a>) I noticed that if I generate the xml with URLs containing non HTML entities (such as &amp;), ...
1
2009-10-30T14:33:02Z
1,650,192
<p><a href="http://docs.python.org/library/xml.sax.utils.html" rel="nofollow">Saxutils</a> has an escaping function for XML entities:</p> <pre><code>&gt;&gt;&gt; from xml.sax import saxutils &gt;&gt;&gt; saxutils.escape("&amp;") '&amp;amp;' </code></pre>
4
2009-10-30T14:38:08Z
[ "python", "xml", "sitemap", "urlencode" ]
Doctest failing inspite of having correct output
1,650,184
<p>My function is</p> <pre><code>def validate_latitude(lat): """Enforce latitude is in range &gt;&gt;&gt; validate_latitude(65) 65 &gt;&gt;&gt; validate_latitude(91) 90 &gt;&gt;&gt; validate_latitude(-91) -90 """ lat = min(lat, 90) lat = max(lat, -90) return lat </code><...
0
2009-10-30T14:37:01Z
1,650,207
<p>Whitespace?</p> <p>If I highlight your output, I can see additional whitespace following the "Expected" value. Not sure whether this is relevant or not.</p>
3
2009-10-30T14:40:10Z
[ "python", "doctest" ]
Doctest failing inspite of having correct output
1,650,184
<p>My function is</p> <pre><code>def validate_latitude(lat): """Enforce latitude is in range &gt;&gt;&gt; validate_latitude(65) 65 &gt;&gt;&gt; validate_latitude(91) 90 &gt;&gt;&gt; validate_latitude(-91) -90 """ lat = min(lat, 90) lat = max(lat, -90) return lat </code><...
0
2009-10-30T14:37:01Z
1,650,553
<p>In these two lines:</p> <pre><code>&gt;&gt;&gt; validate_latitude(-91) -90 </code></pre> <p>You have a Tab character before the <code>-</code> in <code>-90</code>, and four space characters after the <code>0</code>. When doctests runs this code the extra whitespace is of course not produced, so the equality compar...
3
2009-10-30T15:36:46Z
[ "python", "doctest" ]
Regular expression to extract "Boolean" and "MessageString" from {'result':(Boolean, MessageString)}
1,650,244
<p>How to parse the string <code>" {'result':(Boolean, MessageString)} "</code> using Python regular expressions to get <code>Boolean</code> and the <code>MessageString</code> separated into variables?</p>
-2
2009-10-30T14:48:19Z
1,650,298
<p>It looks like a dictionary+tuple in Python syntax, so eval() would also work (if you trust the source!!!)</p>
1
2009-10-30T14:55:35Z
[ "python", "regex" ]
Regular expression to extract "Boolean" and "MessageString" from {'result':(Boolean, MessageString)}
1,650,244
<p>How to parse the string <code>" {'result':(Boolean, MessageString)} "</code> using Python regular expressions to get <code>Boolean</code> and the <code>MessageString</code> separated into variables?</p>
-2
2009-10-30T14:48:19Z
1,650,344
<p>Depending on what you need there can be other solution than regular expression. For this particular example the following code will work:</p> <pre><code>&gt;&gt;&gt; compile("{'result':(Boolean, MessageString)}", '&lt;expr&gt;', 'eval').co_names ('Boolean', 'MessageString') </code></pre> <p>There is also <a href="...
0
2009-10-30T15:03:16Z
[ "python", "regex" ]
Regular expression to extract "Boolean" and "MessageString" from {'result':(Boolean, MessageString)}
1,650,244
<p>How to parse the string <code>" {'result':(Boolean, MessageString)} "</code> using Python regular expressions to get <code>Boolean</code> and the <code>MessageString</code> separated into variables?</p>
-2
2009-10-30T14:48:19Z
1,650,364
<p>This works:</p> <pre><code>&gt;&gt;&gt; x = re.search('\((.*),\s*(.*)\)', " {'result':(Boolean, MessageString)} ") &gt;&gt;&gt; x.group(1) 'Boolean' &gt;&gt;&gt; x.group(2) 'MessageString' </code></pre>
2
2009-10-30T15:06:55Z
[ "python", "regex" ]