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
How to cutomize a modelform widget in Django 1.1?
2,528,195
<p>I'm trying to modify a <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> form to use a textarea instead of a normal input for the "address" field in my house form. The docs seem to imply this changed from Django 1.1 (which I'm using) to 1.2. But neither approach is working...
0
2010-03-27T05:04:29Z
2,528,282
<p>I think Textarea needs to be assigned as a widget.</p> <p>Try</p> <pre><code>class HouseForm(forms.ModelForm): address = forms.CharField(widget=forms.Textarea) class Meta: model = House </code></pre>
4
2010-03-27T05:44:47Z
[ "python", "django", "django-forms" ]
Need help parsing HTML with a regex in python
2,528,198
<pre><code>mystring = "&lt;tr&gt;&lt;td&gt;&lt;span class='para'&gt;&lt;b&gt;Total Amount : &lt;/b&gt;INR (Indian Rupees) 100.00&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;" </code></pre> <p>My problem here is I have to search and get the total amount </p> <pre><code>test = re.search("(Indian Rupees)(\d{2})(?:\D|$)", mystrin...
1
2010-03-27T05:04:45Z
2,528,203
<p>I strongly recommend using a real HTML parser for this, instead of a custom regular-expression.</p> <p>Here's an example with the <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> library:</p> <pre><code>from BeautifulSoup import BeautifulSoup str = r''' &lt;tr&gt;&lt;td&gt;...
7
2010-03-27T05:07:06Z
[ "python" ]
Need help parsing HTML with a regex in python
2,528,198
<pre><code>mystring = "&lt;tr&gt;&lt;td&gt;&lt;span class='para'&gt;&lt;b&gt;Total Amount : &lt;/b&gt;INR (Indian Rupees) 100.00&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;" </code></pre> <p>My problem here is I have to search and get the total amount </p> <pre><code>test = re.search("(Indian Rupees)(\d{2})(?:\D|$)", mystrin...
1
2010-03-27T05:04:45Z
2,528,324
<p>I second Eli's response - you'll be better off using an HTML parser.</p> <p>Personally I would highly recommend <code>lxml</code> library for parsing HTML: <a href="http://lxml.de/" rel="nofollow">http://lxml.de/</a></p> <p>It's extremely fast and feature-rich.</p> <pre><code>from lxml.html import fromstring s ...
3
2010-03-27T06:02:28Z
[ "python" ]
Need help parsing HTML with a regex in python
2,528,198
<pre><code>mystring = "&lt;tr&gt;&lt;td&gt;&lt;span class='para'&gt;&lt;b&gt;Total Amount : &lt;/b&gt;INR (Indian Rupees) 100.00&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;" </code></pre> <p>My problem here is I have to search and get the total amount </p> <pre><code>test = re.search("(Indian Rupees)(\d{2})(?:\D|$)", mystrin...
1
2010-03-27T05:04:45Z
2,528,348
<p>I agree that a parser is a great way to go, but since you asked how to do it with regex, here's a way:</p> <pre><code>mystring = """&lt;tr&gt;&lt;td&gt;&lt;span class='para'&gt;&lt;b&gt;Total Amount : &lt;/b&gt;INR (Indian Rupees) 100.00&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;""" test = re.search("\(Indian Rupees\) ([^...
1
2010-03-27T06:11:29Z
[ "python" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
2,528,297
<p>You need:</p> <p>1) A real deployment infrastructure, even if it's just a shell script, which does everything. Cloning/checking out an updated copy from source control is not a deployment strategy.</p> <p>2) Any deployment system should completely clean the directory structure. My usual preference is that each dep...
6
2010-03-27T05:52:20Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
2,528,326
<p>How about using an <a href="http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html">update hook</a> on the server side? Put this in the repository's <code>.hg</code> directory's <code>hgrc</code> file:</p> <pre><code>[hooks] update = find . -name '*.pyc' | xargs rm </code></pre> <p>That will d...
9
2010-03-27T06:04:28Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
2,528,509
<ol> <li>Do not store .pyc files in the repository.</li> <li>Automatize .pyc delete with: find . -name '*.pyc' -delete</li> <li>While develop use -B argument in Python.</li> </ol>
16
2010-03-27T07:22:31Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
2,528,767
<p>I use the <code>.hgignore</code> file to skip versionning of all my .pyc and .py~ (editor's temp files). For example, this is my version :</p> <pre><code># use glob syntax. syntax: glob .directory *.pyc *~ *.o *.tgz *.tbz2 *.gz *.bz2 </code></pre> <p>Also adding a hook on update to remove them is also a interesti...
1
2010-03-27T09:33:36Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
2,529,584
<p>What I have actually done:</p> <p>1) I am considering Nicholas Knight's suggestion about using a proper deployment strategy. I have been reading about <a href="http://buildout.org" rel="nofollow">Buildout</a> and <a href="http://plone.org/products/collective.hostout" rel="nofollow">Collective.hostout</a> to learn m...
3
2010-03-27T14:18:32Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
26,771,320
<p>Here's a unix one-liner that will delete .pyc files each time you run <code>hg update</code>. </p> <p>Add this to your hgrc file:</p> <pre><code>[hooks] preupdate.cleanpyc = hg status --no-status --removed --deleted --include "**.py" --rev .:$HG_PARENT1 --print0 | xargs -0 -I '{}' rm -f '{}c' </code></pre> <p>Th...
2
2014-11-06T03:38:45Z
[ "python", "mercurial" ]
Automatically deleting pyc files when corresponding py is moved (Mercurial)
2,528,283
<p>(I foresaw this problem might happen 3 months ago, and was told to be diligent to avoid it. Yesterday, I was bitten by it, hard, and now that it has cost me real money, I am keen to fix it.)</p> <p>If I move one of my Python source files into another directory, I need to remember to tell Mercurial that it moved (<c...
14
2010-03-27T05:46:16Z
32,214,881
<p>i use this script to delete the .pyc files in the current folder, this script could be used alone or include it in the exit function to delete the .pyc files when u exit.</p> <pre><code>import os files = [f for f in os.listdir('.') if os.path.isfile(f) and '.pyc' in str(f)] for f in files : os.unlink(os.getcwd()+'/...
0
2015-08-25T22:06:41Z
[ "python", "mercurial" ]
Modify python USB device driver to only use vendor_id and product_id, excluding BCD
2,528,359
<p>I'm trying to modify the Android device driver for calibre (an e-book management program) so that it identifies devices by only vendor id and product id, and excludes BCD. </p> <p>The driver is a fairly simply python plugin, and is currently set up to use all three numbers, but apparently, when Android devices use...
0
2010-03-27T06:16:17Z
2,528,549
<p>That is a data structure, it doesn't "match" anything per se. The change would have to happen in the code that uses that data structure to do the matching. Nothing you could do on the data structure itself would mean <em>"match all"</em> unless there's some kind of flag the matching code recognizes.</p>
0
2010-03-27T07:39:38Z
[ "android", "python", "usb", "calibre" ]
Number of elements in Python Set
2,528,513
<p>I have a list of phone numbers that have been dialed (nums_dialed). I also have a set of phone numbers which are the number in a client's office (client_nums) How do I efficiently figure out how many times I've called a particular client (total)</p> <p>For example:</p> <pre><code>&gt;&gt;&gt;nums_dialed=[1,2,2,3,3...
3
2010-03-27T07:23:28Z
2,528,515
<pre><code>&gt;&gt;&gt; client_nums = set([2, 3]) &gt;&gt;&gt; nums_dialed = [1, 2, 2, 3, 3] &gt;&gt;&gt; count = 0 &gt;&gt;&gt; for num in nums_dialed: ... if num in client_nums: ... count += 1 ... &gt;&gt;&gt; count 4 &gt;&gt;&gt; </code></pre> <p>Should be quite efficient even for the large numbers you quot...
1
2010-03-27T07:24:54Z
[ "python", "comparison", "dataset" ]
Number of elements in Python Set
2,528,513
<p>I have a list of phone numbers that have been dialed (nums_dialed). I also have a set of phone numbers which are the number in a client's office (client_nums) How do I efficiently figure out how many times I've called a particular client (total)</p> <p>For example:</p> <pre><code>&gt;&gt;&gt;nums_dialed=[1,2,2,3,3...
3
2010-03-27T07:23:28Z
2,528,526
<p>which client has <code>10^5</code> numbers in his office? Do you do work for an entire telephone company?</p> <p>Anyway:</p> <pre><code>print sum(1 for num in nums_dialed if num in client_nums) </code></pre> <p>That will give you as fast as possible the number. </p> <hr> <p>If you want to do it for multiple cli...
8
2010-03-27T07:29:48Z
[ "python", "comparison", "dataset" ]
Number of elements in Python Set
2,528,513
<p>I have a list of phone numbers that have been dialed (nums_dialed). I also have a set of phone numbers which are the number in a client's office (client_nums) How do I efficiently figure out how many times I've called a particular client (total)</p> <p>For example:</p> <pre><code>&gt;&gt;&gt;nums_dialed=[1,2,2,3,3...
3
2010-03-27T07:23:28Z
2,528,595
<p>Thats very popular way to do some combination of sorted lists in single pass:</p> <pre><code>nums_dialed = [1, 2, 2, 3, 3] client_nums = [2,3] nums_dialed.sort() client_nums.sort() c = 0 i = iter(nums_dialed) j = iter(client_nums) try: a = i.next() b = j.next() while True: if a &lt; b: ...
0
2010-03-27T08:04:12Z
[ "python", "comparison", "dataset" ]
Number of elements in Python Set
2,528,513
<p>I have a list of phone numbers that have been dialed (nums_dialed). I also have a set of phone numbers which are the number in a client's office (client_nums) How do I efficiently figure out how many times I've called a particular client (total)</p> <p>For example:</p> <pre><code>&gt;&gt;&gt;nums_dialed=[1,2,2,3,3...
3
2010-03-27T07:23:28Z
2,528,649
<p>Using collections.Counter from Python 2.7:</p> <pre><code>dialed_count = collections.Counter(nums_dialed) count = sum(dialed_count[t] for t in client_nums) </code></pre>
1
2010-03-27T08:31:42Z
[ "python", "comparison", "dataset" ]
How to replace openSSL calls with C# code?
2,528,810
<p>Hey there again! Today I ran into a problem when I was making a new theme creator for chrome. As you may know, Chrome uses a "new" file format, called CRX, to manage it's plugins and themes. It is a basic zip file, but a bit modified:</p> <p>"Cr24" + derkey + signature + zipFile</p> <p>And here comes the problem. ...
0
2010-03-27T09:54:57Z
3,902,968
<p>For Linux, there are a variety of utilities to do this - including one for bash - but it sounds like you want something for windows (guessing from your C# comment).</p> <p>I had tried to include links to all of them - but I am new stackoverflow user, and can only post 1 link..</p> <p>Anyway, all of those can work ...
0
2010-10-11T01:18:28Z
[ "c#", "python", "openssl" ]
Sorting and aligning the contents of a text file in Python
2,528,839
<p>In my program I have a text file that I read from and write to. However, I would like to display the contents of the text file in an aligned and sorted manner. The contents currently read:</p> <pre><code>Emily, 6 Sarah, 4 Jess, 7 </code></pre> <p>This is my code where the text file in read and printed:</p> <pre><...
2
2010-03-27T10:06:15Z
2,528,845
<p>You could use <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv</a> module, and then could use <code>sorted</code> to sort.</p> <p>Let's says, scores1.txt have following</p> <pre><code>Richard,100 Michael,200 Ricky,150 Chaung,100 </code></pre> <p>Test</p> <pre><code>import csv reader=csv.read...
5
2010-03-27T10:09:29Z
[ "python" ]
Sorting and aligning the contents of a text file in Python
2,528,839
<p>In my program I have a text file that I read from and write to. However, I would like to display the contents of the text file in an aligned and sorted manner. The contents currently read:</p> <pre><code>Emily, 6 Sarah, 4 Jess, 7 </code></pre> <p>This is my code where the text file in read and printed:</p> <pre><...
2
2010-03-27T10:06:15Z
2,528,847
<ol> <li>to sort stuff in Python, you can use <a href="http://wiki.python.org/moin/HowTo/Sorting" rel="nofollow">sort()/sorted()</a>.</li> <li>to print, you can use print with format specifiers, str.rjust/str.ljust, pprint etc</li> </ol>
0
2010-03-27T10:10:46Z
[ "python" ]
Sorting and aligning the contents of a text file in Python
2,528,839
<p>In my program I have a text file that I read from and write to. However, I would like to display the contents of the text file in an aligned and sorted manner. The contents currently read:</p> <pre><code>Emily, 6 Sarah, 4 Jess, 7 </code></pre> <p>This is my code where the text file in read and printed:</p> <pre><...
2
2010-03-27T10:06:15Z
2,529,782
<p>Looks like nobody's answered the "aligned" part of your request. Also, it's not clear whether you want the results sorted alphabetically by name, or rather by score. In the first case, alphabetical order (assuming Python 2.6):</p> <pre><code>with open("scores1.txt", 'r') as scoresFile: names_scores = [[x.strip(...
2
2010-03-27T15:15:09Z
[ "python" ]
How do I get minidom to ignore namespaces?
2,528,852
<p>I am using minidom in Python and I'd like getElementsByTagName() to match elements purely by tag-name and ignore any namespaces. The documents are being parsed by minidom.parseString(). Is it possible?</p>
9
2010-03-27T10:11:47Z
2,529,311
<p><code>getElementsByTagName</code> does match elements purely by tagName.</p> <p>Do you mean you want to match purely on localName? ie. the part of the tag name after the <code>:</code> (if any)? If so use the DOM Level 2 Core method <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBTNNS">getElements...
12
2010-03-27T12:52:59Z
[ "python", "xml" ]
Django foreign key question
2,528,867
<p>All,</p> <p>i have the following model defined,</p> <pre><code> class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(ma...
0
2010-03-27T10:19:12Z
2,528,881
<p>Given your:</p> <pre><code>p= header(title=name,created_by=id) p.save() </code></pre> <p>You can now:</p> <pre><code>c=criteria(details='some details', headerid=p) c.save() o=options(opt_details='more details', headerid=p) o.save() </code></pre> <p>Hope this helps.</p>
3
2010-03-27T10:23:52Z
[ "python", "django", "django-models", "django-templates", "django-views" ]
Django foreign key question
2,528,867
<p>All,</p> <p>i have the following model defined,</p> <pre><code> class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(ma...
0
2010-03-27T10:19:12Z
2,528,979
<p>Take advantage of <code>&lt;related&gt;_set</code> query managers, it's clearer and shorter than constructing and saving objects in separate operations.</p> <pre><code>h = header.objects.create(title=name,created_by=id) c = h.criteria_set.create(details='some details') o = h.options_set.create(opt_details='more det...
1
2010-03-27T10:52:45Z
[ "python", "django", "django-models", "django-templates", "django-views" ]
What is the difference between .get() and .fetch(1)
2,529,198
<p>I have written an app and part of it is uses a URL parser to get certain data in a ReST type manner. So if you put /foo/bar as the path it will find all the bar items and if you put /foo it will return all items below foo</p> <p>So my app has a query like</p> <pre><code>data = Paths.all().filter('path =', self.req...
4
2010-03-27T12:10:58Z
2,529,204
<p>get() requires (I think) that there be exactly one element, and returns it, while fetch() returns a <em>list</em> of the first <em>n</em> elements, where <em>n</em> happens to be 1 in this case.</p>
1
2010-03-27T12:14:14Z
[ "python", "google-app-engine", "gae-datastore" ]
What is the difference between .get() and .fetch(1)
2,529,198
<p>I have written an app and part of it is uses a URL parser to get certain data in a ReST type manner. So if you put /foo/bar as the path it will find all the bar items and if you put /foo it will return all items below foo</p> <p>So my app has a query like</p> <pre><code>data = Paths.all().filter('path =', self.req...
4
2010-03-27T12:10:58Z
2,529,314
<p>You're looking at the docs for the wrong get() - you want the <a href="http://code.google.com/appengine/docs/python/datastore/queryclass.html#Query_get">get() method on the Query object</a>. In a nutshell, .fetch() always returns a list, while .get() returns the first result, or None if there are no results.</p>
8
2010-03-27T12:53:48Z
[ "python", "google-app-engine", "gae-datastore" ]
want to add url links to .csv datafeed using python
2,529,238
<p>Hi all ive looked through the current related questions but have not managed to find anything similar to my needs.</p> <p>Im in the process of creating a affiliate store using zencart - now one of the issues is that zencart is not designed for redirects and affiliate stores but it can be done. I will be changin...
1
2010-03-27T12:26:06Z
2,529,256
<p>You could craft a python script using <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv</a> module like this:</p> <pre><code>&gt;&gt;&gt; import csv &gt;&gt;&gt; cartWriter = csv.writer(open('yourcart.csv', 'wb')) &gt;&gt;&gt; cartWriter.writerow(['Product', 'yourinfo', 'yourlink']) </code></pre>...
2
2010-03-27T12:32:29Z
[ "python", "url", "csv", "add", "datafeed" ]
want to add url links to .csv datafeed using python
2,529,238
<p>Hi all ive looked through the current related questions but have not managed to find anything similar to my needs.</p> <p>Im in the process of creating a affiliate store using zencart - now one of the issues is that zencart is not designed for redirects and affiliate stores but it can be done. I will be changin...
1
2010-03-27T12:26:06Z
2,529,306
<p>First, use the CSV module as systempuntoout told you, secondly, you will want to change your header to:</p> <pre><code>mimetype='text/csv' Content-Disposition = 'attachment; filename=name_of_your_file.csv' </code></pre> <p>The way to do it depends very much of your website implementation. In pure Python you would ...
0
2010-03-27T12:50:08Z
[ "python", "url", "csv", "add", "datafeed" ]
importing files in python
2,529,466
<p>I have that file structure-</p> <ol> <li><p>Blog\DataObjects\User.py</p></li> <li><p>Blog\index.py</p></li> </ol> <p>I want to import the function(say_hello) at User.py from index.py. I am trying this code -</p> <pre><code>from Blog.DataObjects.User import say_hello say_hello() </code></pre> <p>And I have tha...
1
2010-03-27T13:42:05Z
2,529,478
<pre><code>from DataObjects.User import say_hello </code></pre>
1
2010-03-27T13:45:21Z
[ "python", "package", "python-2.6" ]
importing files in python
2,529,466
<p>I have that file structure-</p> <ol> <li><p>Blog\DataObjects\User.py</p></li> <li><p>Blog\index.py</p></li> </ol> <p>I want to import the function(say_hello) at User.py from index.py. I am trying this code -</p> <pre><code>from Blog.DataObjects.User import say_hello say_hello() </code></pre> <p>And I have tha...
1
2010-03-27T13:42:05Z
2,529,485
<p>Python expects in every directory that should be importable, <a href="http://www.network-theory.co.uk/docs/pytut/Packages.html" rel="nofollow">a file <code>__init__.py</code></a>, which may be empty. So, if you correct your file structure to this:</p> <pre><code>Blog/__init__.py Blog/index.py Blog/DataObjects/User....
12
2010-03-27T13:47:05Z
[ "python", "package", "python-2.6" ]
How can I detect if the caller passed any variables to my function in Python?
2,529,491
<p>I guess the subject sounds pretty stupid, so I'll show some code:</p> <pre><code>def foo(**kwargs): # How can you detect the difference between (**{}) and ()? pass foo(**{}) foo() </code></pre> <p>Is there any way to detect inside of foo, how the method was called?</p> <h3>Update 1</h3> <p>Because there ...
0
2010-03-27T13:49:31Z
2,529,511
<p>This hack only works with CPython. </p> <pre><code>import traceback def foo(**kwargs): # stack is a list of 4-tuples: (filename, line number, function name, text) # see http://docs.python.org/library/traceback.html#module-traceback (filename,line_number,function_name,text)=traceback.extract_stack()[-2...
0
2010-03-27T13:56:28Z
[ "python", "inspect" ]
How can I detect if the caller passed any variables to my function in Python?
2,529,491
<p>I guess the subject sounds pretty stupid, so I'll show some code:</p> <pre><code>def foo(**kwargs): # How can you detect the difference between (**{}) and ()? pass foo(**{}) foo() </code></pre> <p>Is there any way to detect inside of foo, how the method was called?</p> <h3>Update 1</h3> <p>Because there ...
0
2010-03-27T13:49:31Z
2,529,679
<p>In your update to your original question you wrote you want to be able to do something like this:</p> <pre><code>def foo(self, fnord=42, *args, **kwargs): self.super(*args, **kwargs) </code></pre> <p>Does this do what you want?</p> <pre><code>def foo(self, fnord=42, *args, **kwargs): self.super(fnord=fnor...
0
2010-03-27T14:46:34Z
[ "python", "inspect" ]
How can I detect if the caller passed any variables to my function in Python?
2,529,491
<p>I guess the subject sounds pretty stupid, so I'll show some code:</p> <pre><code>def foo(**kwargs): # How can you detect the difference between (**{}) and ()? pass foo(**{}) foo() </code></pre> <p>Is there any way to detect inside of foo, how the method was called?</p> <h3>Update 1</h3> <p>Because there ...
0
2010-03-27T13:49:31Z
2,658,030
<p>So basically it is not possible to do that with the provided Python modules. I had to fall-back to plain-text regexes which work for me pretty well given the simplicity of my requirements.</p>
0
2010-04-17T10:24:09Z
[ "python", "inspect" ]
Can Django be used for non web apps?
2,529,497
<p>I noticed in the main Django introductin they show a feature that maps python objects to the database. This doesn't strike me as being mutually exclusive with with development, is there any reason why this can't be used for non web apps? Is it easy to separate out?</p>
4
2010-03-27T13:51:53Z
2,529,512
<p>The part you're mentioning is the ORM and yes, ORMs are useful besides web development. In theory you could use the Django ORM for non-web stuff. However this can be a bit complicated because it is not released separately so you'd have to extract the code yourself (or you have to include the whole django package).</...
6
2010-03-27T13:56:28Z
[ "python", "django", "django-models" ]
Python idiom for '... if ... else ...' expression
2,529,536
<p>How to write the expression shorter:</p> <pre><code>return '%.0f' % float_var if float_var else float_var </code></pre> <p>or</p> <pre><code>if float_var: return formatted_string else: return None </code></pre> <p>Thanks!</p>
1
2010-03-27T14:02:50Z
2,529,543
<p>The expression <code>&lt;value&gt; if &lt;condition&gt; else &lt;other_value&gt;</code> is pretty idiomatic already -- certainly more so than the other example, and is probably preferred whenever <code>&lt;value&gt;</code> is simple. This is Python's ternary operator, so if you were looking for something like <code>...
16
2010-03-27T14:06:30Z
[ "python", "idioms" ]
Python idiom for '... if ... else ...' expression
2,529,536
<p>How to write the expression shorter:</p> <pre><code>return '%.0f' % float_var if float_var else float_var </code></pre> <p>or</p> <pre><code>if float_var: return formatted_string else: return None </code></pre> <p>Thanks!</p>
1
2010-03-27T14:02:50Z
2,529,552
<p>If you are using are already using <code>v if c else u</code> you are already using the most readable and efficient ternary operator.</p> <p>There are <a href="http://www.python.org/doc/faq/programming/#is-there-an-equivalent-of-c-s-ternary-operator" rel="nofollow">other ways</a> but they suffer in readability.</p>...
1
2010-03-27T14:08:23Z
[ "python", "idioms" ]
Python idiom for '... if ... else ...' expression
2,529,536
<p>How to write the expression shorter:</p> <pre><code>return '%.0f' % float_var if float_var else float_var </code></pre> <p>or</p> <pre><code>if float_var: return formatted_string else: return None </code></pre> <p>Thanks!</p>
1
2010-03-27T14:02:50Z
2,529,615
<p>I would use brackets to make the expression more readable:</p> <pre><code>return ('%.0f' % float_var) if float_var else float_var </code></pre> <p>When I first saw it I read it as</p> <pre><code>return '%.0f' % (float_var if float_var else float_var) </code></pre> <p>which would be silly. I had to try it out to ...
2
2010-03-27T14:29:08Z
[ "python", "idioms" ]
Python idiom for '... if ... else ...' expression
2,529,536
<p>How to write the expression shorter:</p> <pre><code>return '%.0f' % float_var if float_var else float_var </code></pre> <p>or</p> <pre><code>if float_var: return formatted_string else: return None </code></pre> <p>Thanks!</p>
1
2010-03-27T14:02:50Z
2,530,221
<ul> <li><p>It is not clear what exactly you want to do. </p> <ol> <li><p>The most literal interpretation would have it work like this</p> <pre><code>&gt;&gt;&gt; float_var = 4.5 &gt;&gt;&gt; '%.0f' % float_var if float_var else float_var '5' # This is a string &gt;&gt;&gt; float_var = 0.0 &gt;&gt;&gt; '%.0f' % float...
1
2010-03-27T17:28:59Z
[ "python", "idioms" ]
Python idiom for '... if ... else ...' expression
2,529,536
<p>How to write the expression shorter:</p> <pre><code>return '%.0f' % float_var if float_var else float_var </code></pre> <p>or</p> <pre><code>if float_var: return formatted_string else: return None </code></pre> <p>Thanks!</p>
1
2010-03-27T14:02:50Z
2,530,510
<pre><code>float_var and "%.0f" % float_vav </code></pre> <p>Isn't it awesome?</p>
0
2010-03-27T18:51:35Z
[ "python", "idioms" ]
Refresh decorator
2,529,592
<p>I'm trying to write a decorator that 'refreshes' after being called, but where the refreshing only occurs once after the last function exits. Here is an example:</p> <pre><code>@auto_refresh def a(): print "In a" @auto_refresh def b(): print "In b" a() </code></pre> <p>If <code>a()</code> is called, I...
1
2010-03-27T14:22:05Z
2,529,669
<p>I think it might be simpler to maintain a "nested-refresh count" that is incremented before each refresh-decorated call and decremented after (in a finally block so that the count doesn't get messed up); run the refresh routine whenever the count hits zero.</p>
1
2010-03-27T14:45:21Z
[ "python", "algorithm", "decorator" ]
Refresh decorator
2,529,592
<p>I'm trying to write a decorator that 'refreshes' after being called, but where the refreshing only occurs once after the last function exits. Here is an example:</p> <pre><code>@auto_refresh def a(): print "In a" @auto_refresh def b(): print "In b" a() </code></pre> <p>If <code>a()</code> is called, I...
1
2010-03-27T14:22:05Z
2,529,844
<p>To count the number of "nestings", in a thread-safe way, is a good example of using <em><a href="http://docs.python.org/library/threading.html?highlight=threading.local#threading.local" rel="nofollow">thread-local storage</a></em>:</p> <pre><code>import threading mydata = threading.local() mydata.nesting = 0 class...
5
2010-03-27T15:36:32Z
[ "python", "algorithm", "decorator" ]
Refresh decorator
2,529,592
<p>I'm trying to write a decorator that 'refreshes' after being called, but where the refreshing only occurs once after the last function exits. Here is an example:</p> <pre><code>@auto_refresh def a(): print "In a" @auto_refresh def b(): print "In b" a() </code></pre> <p>If <code>a()</code> is called, I...
1
2010-03-27T14:22:05Z
2,529,845
<p>It's not clear to me exactly what you're attempting to use this design for, and because of that, whether it's a good idea or not. Consider whether or not it's the right approach.</p> <p>However, I think this does what you requested. A common object (named <code>auto_refresh</code> in this case) is shared by all 'de...
0
2010-03-27T15:37:11Z
[ "python", "algorithm", "decorator" ]
google app engine - auto increment
2,529,620
<p>I am new to Google App Engine, I have this entites User class - <br> user_id - integer<br> user_name - string <br> password - string <br></p> <p>I want to do auto increment for the user_id,How I can do this?</p>
5
2010-03-27T14:30:37Z
2,529,655
<p>You don't need to declare user_id, GAE will create a unique key id every time you insert a new row.</p> <pre><code>class User(db.Model): user_name = db.StringProperty() password = db.StringProperty() </code></pre> <p>and to store a new user you will do:</p> <pre><code>user = User() user.user_name = "Username" use...
18
2010-03-27T14:41:40Z
[ "python", "google-app-engine", "gae-datastore" ]
google app engine - auto increment
2,529,620
<p>I am new to Google App Engine, I have this entites User class - <br> user_id - integer<br> user_name - string <br> password - string <br></p> <p>I want to do auto increment for the user_id,How I can do this?</p>
5
2010-03-27T14:30:37Z
2,529,674
<p>Every entity in the AppEngine already has a unique key and id (see the <a href="http://code.google.com/appengine/docs/python/datastore/keyclass.html#Introduction" rel="nofollow">documentation</a>):</p> <pre><code>user().key().id() </code></pre> <p>You would be better off using that instead.</p> <p>To do the conve...
3
2010-03-27T14:45:47Z
[ "python", "google-app-engine", "gae-datastore" ]
Faster or more memory-efficient solution in Python for this Codejam problem
2,529,727
<p>I tried my hand at this <a href="http://code.google.com/codejam/contest/dashboard?c=438101#s=p0&amp;a=0" rel="nofollow">Google Codejam Africa</a> problem (the contest is already finished, I just did it to improve my programming skills).</p> <blockquote> <p><strong>The Problem:</strong></p> <p>You are hosting...
3
2010-03-27T14:59:17Z
2,529,753
<p>Consider this:</p> <pre><code>codes = map(int, lines[i+1].split(' ')) </code></pre> <p>Why resplit the line for each value of <code>guest</code>? The line won't change.</p> <p>Also, consider this:</p> <pre><code>for guest in range(G): codes = map(int, lines[i+1].split(' ')) alone = (c for c in codes if ...
2
2010-03-27T15:07:30Z
[ "python", "puzzle" ]
Faster or more memory-efficient solution in Python for this Codejam problem
2,529,727
<p>I tried my hand at this <a href="http://code.google.com/codejam/contest/dashboard?c=438101#s=p0&amp;a=0" rel="nofollow">Google Codejam Africa</a> problem (the contest is already finished, I just did it to improve my programming skills).</p> <blockquote> <p><strong>The Problem:</strong></p> <p>You are hosting...
3
2010-03-27T14:59:17Z
2,529,755
<p>I don't know about python, but the problem itself is a classic. Given <code>2K - 1</code> numbers, each except one appearing an even number of times, find the one appearing an odd number of times.</p> <p>Needed formulas:</p> <ol> <li><code>x xor x == 0 for all x</code></li> <li><code>x xor y == y xor x for all x a...
5
2010-03-27T15:08:01Z
[ "python", "puzzle" ]
Faster or more memory-efficient solution in Python for this Codejam problem
2,529,727
<p>I tried my hand at this <a href="http://code.google.com/codejam/contest/dashboard?c=438101#s=p0&amp;a=0" rel="nofollow">Google Codejam Africa</a> problem (the contest is already finished, I just did it to improve my programming skills).</p> <blockquote> <p><strong>The Problem:</strong></p> <p>You are hosting...
3
2010-03-27T14:59:17Z
2,529,798
<p>This finishes instantly for me with the same results:</p> <pre><code>src = open('A-large-practice.in') dst = open('A-large-practice.out', 'w') n = int(src.readline().rstrip()) for i in xrange(n): src.readline() # skip g nums = src.readline().split() seen = set() for n in nums: if n in seen:...
1
2010-03-27T15:18:08Z
[ "python", "puzzle" ]
Faster or more memory-efficient solution in Python for this Codejam problem
2,529,727
<p>I tried my hand at this <a href="http://code.google.com/codejam/contest/dashboard?c=438101#s=p0&amp;a=0" rel="nofollow">Google Codejam Africa</a> problem (the contest is already finished, I just did it to improve my programming skills).</p> <blockquote> <p><strong>The Problem:</strong></p> <p>You are hosting...
3
2010-03-27T14:59:17Z
2,529,821
<p>My machine's slower than yours -- your code (put in a <code>main</code> function) took 19 seconds on my machine. The obvious optimization of removing the useless inner <code>for</code> cuts this to 0.46 seconds; changing the heart of the code to</p> <pre><code> alone = 0 for c in codes: alone ^= c </cod...
4
2010-03-27T15:26:45Z
[ "python", "puzzle" ]
Faster or more memory-efficient solution in Python for this Codejam problem
2,529,727
<p>I tried my hand at this <a href="http://code.google.com/codejam/contest/dashboard?c=438101#s=p0&amp;a=0" rel="nofollow">Google Codejam Africa</a> problem (the contest is already finished, I just did it to improve my programming skills).</p> <blockquote> <p><strong>The Problem:</strong></p> <p>You are hosting...
3
2010-03-27T14:59:17Z
2,529,827
<p>Yes, as the analysis page explains, you can use constant memory, although any approach will run in O(n) time. Here's how the constant memory solution would work in Python:</p> <pre><code>numbers = [1, 1, 2, 2, 3, 3, 4, 4, 12345] missingOne = 0 for number in numbers: missingOne = missingOne ^ number assert missi...
1
2010-03-27T15:28:04Z
[ "python", "puzzle" ]
Get parent function
2,529,859
<p>Is there a way to find what function called the current function? So for example:</p> <pre><code>def first(): second() def second(): # print out here what function called this one </code></pre> <p>Any ideas?</p>
6
2010-03-27T15:41:43Z
2,529,884
<p>You can use the traceback module's <a href="http://docs.python.org/library/traceback.html#traceback.extract_stack" rel="nofollow">extract_stack</a> function.</p> <pre><code>import traceback def first(): second() def second(): print traceback.extract_stack(limit=2)[-2][2] </code></pre>
2
2010-03-27T15:49:39Z
[ "python" ]
Get parent function
2,529,859
<p>Is there a way to find what function called the current function? So for example:</p> <pre><code>def first(): second() def second(): # print out here what function called this one </code></pre> <p>Any ideas?</p>
6
2010-03-27T15:41:43Z
2,529,888
<p>The <a href="http://docs.python.org/library/inspect.html?highlight=inspect#module-inspect" rel="nofollow">inspect</a> module allows for many forms of introspection including this one, but note that it's only recommended to use such information for purposes such as debugging, not as part of your production code's fun...
1
2010-03-27T15:50:26Z
[ "python" ]
Get parent function
2,529,859
<p>Is there a way to find what function called the current function? So for example:</p> <pre><code>def first(): second() def second(): # print out here what function called this one </code></pre> <p>Any ideas?</p>
6
2010-03-27T15:41:43Z
2,529,895
<pre><code>import inspect def first(): return second() def second(): return inspect.getouterframes( inspect.currentframe() )[1] first()[3] # 'first' </code></pre>
4
2010-03-27T15:51:19Z
[ "python" ]
Get parent function
2,529,859
<p>Is there a way to find what function called the current function? So for example:</p> <pre><code>def first(): second() def second(): # print out here what function called this one </code></pre> <p>Any ideas?</p>
6
2010-03-27T15:41:43Z
2,530,062
<p>These work well for quickly adding minimal where-am-I debugging aids when you don't want to import yet another module. (CPython only, for debugging only.)</p> <pre><code>def LINE( back = 0 ): return sys._getframe( back + 1 ).f_lineno def FILE( back = 0 ): return sys._getframe( back + 1 ).f_code.co_filename ...
1
2010-03-27T16:44:50Z
[ "python" ]
Python beautifulsoup trying to remove html tags 'span'
2,529,978
<p>I am trying to remove</p> <pre><code>[&lt;span class="street-address"&gt; 510 E Airline Way &lt;/span&gt;] </code></pre> <p>and I have used this clean function to remove the one that is in between <code>&lt; &gt;</code></p> <pre><code>def clean(val): if type(val) is not StringType: val = s...
0
2010-03-27T16:19:23Z
2,530,064
<p>Using re:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s='[&lt;span class="street-address"&gt;\n 510 E Airline Way\n &lt;/span&gt;]' &gt;&gt;&gt; re.sub(r'\[|\]|\s*&lt;[^&gt;]*&gt;\s*', '', s) '510 E Airline Way' </code></pre> <p>Using BeautifulSoup:</p> <pre><code>&gt;&gt;&gt; from Bea...
9
2010-03-27T16:45:50Z
[ "python", "regex", "beautifulsoup" ]
Django Foreign key queries
2,530,158
<p>In the following model:</p> <pre><code>class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(max_length = 255) headerid = ...
10
2010-03-27T17:12:08Z
2,530,236
<p>First of all, don't use <code>id</code> in the names, because it is confusing. That field isn't the ID, it is the object itself. (If you have a field <code>ref</code> it automatically creates a field <code>ref_id</code>)</p> <pre><code>options.objects.filter(header=a_header) </code></pre> <p>You query it like any ...
8
2010-03-27T17:34:36Z
[ "python", "django", "django-views", "django-queryset" ]
Django Foreign key queries
2,530,158
<p>In the following model:</p> <pre><code>class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(max_length = 255) headerid = ...
10
2010-03-27T17:12:08Z
2,530,367
<p>I would suggest trying to us a <a href="http://docs.djangoproject.com/en/dev/internals/contributing/#model-style" rel="nofollow">coding style</a> and naming convention that is more like you see in the Django documentation for <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#topics-db-models" rel="nofo...
3
2010-03-27T18:13:11Z
[ "python", "django", "django-views", "django-queryset" ]
Django Foreign key queries
2,530,158
<p>In the following model:</p> <pre><code>class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(max_length = 255) headerid = ...
10
2010-03-27T17:12:08Z
2,530,376
<p>Ironfroggy is right, but there is another more obvious way to get the relevant <code>options</code> and <code>criteria</code> objects. Django automatically creates a 'reverse relation' for every foreign key pointing at a model, and that is usually the name of the related model plus <code>_set</code>. So:</p> <pre><...
19
2010-03-27T18:15:33Z
[ "python", "django", "django-views", "django-queryset" ]
Django Foreign key queries
2,530,158
<p>In the following model:</p> <pre><code>class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length = 255) def __unicode__(self): return self.id() class criteria(models.Model): details = models.CharField(max_length = 255) headerid = ...
10
2010-03-27T17:12:08Z
2,530,386
<p>Sounds like you are looking for <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects">Following relationships "backward"</a>.</p> <p>You can get the header object you want to filter by, and use something like</p> <pre><code>obj = Header.objects.get(title="value-mart", "created...
5
2010-03-27T18:18:19Z
[ "python", "django", "django-views", "django-queryset" ]
Why eclipse + pydev print() output look strange with two strings?
2,530,387
<p>hay all, I just did the following:</p> <pre><code>a = input("give a word: ") b = input("give another word: ") c = a + " " + b print("result is", c) </code></pre> <p>and get the output as follows:</p> <pre><code>give a word: name give another word: word result is name word </code></pre> <p>my question is why th...
1
2010-03-27T18:18:20Z
2,530,419
<p>That's very strange.</p> <p>Are you getting an extra newline after word? (you can check by issuing another print command). </p> <p>Eclipse is always weird on console input. I would not be surprised if somehow it keeps a CR or a LF (or both) in the string, so that when you print each of them, you would get a line b...
0
2010-03-27T18:26:49Z
[ "python", "python-3.x", "pydev", "eclipse-3.5" ]
Why eclipse + pydev print() output look strange with two strings?
2,530,387
<p>hay all, I just did the following:</p> <pre><code>a = input("give a word: ") b = input("give another word: ") c = a + " " + b print("result is", c) </code></pre> <p>and get the output as follows:</p> <pre><code>give a word: name give another word: word result is name word </code></pre> <p>my question is why th...
1
2010-03-27T18:18:20Z
2,530,768
<p>It seems to me that Eclipse + PyDev is storing the newline character in the string as well. There are a few variants of the newline character depending on the operating system: \n, \r, \r\n.</p> <p>In any case, I think the following should fix your problem:</p> <pre><code>a = raw_input("give a word: ").strip() b =...
1
2010-03-27T20:11:40Z
[ "python", "python-3.x", "pydev", "eclipse-3.5" ]
Help getting frame rate (fps) up in Python + Pygame
2,530,478
<p>I am working on a little card-swapping world-travel game that I sort of envision as a cross between Bejeweled and the 10 Days geography board games. So far the coding has been going okay, but the frame rate is pretty bad... currently I'm getting low 20's on my Core 2 Duo. This is a problem since I'm creating the gam...
9
2010-03-27T18:43:18Z
2,530,745
<p><strong>Let events come to you with event.wait</strong></p> <p>Do you really need to do processing every tick? If not, use <code>pygame.event.wait</code> for your event loop to only process when an event comes in, and <code>pygame.time.set_timer</code> if you need periodic events like your <code>SecondEvent</code>...
7
2010-03-27T20:06:15Z
[ "python", "performance", "pygame", "frame-rate" ]
Help getting frame rate (fps) up in Python + Pygame
2,530,478
<p>I am working on a little card-swapping world-travel game that I sort of envision as a cross between Bejeweled and the 10 Days geography board games. So far the coding has been going okay, but the frame rate is pretty bad... currently I'm getting low 20's on my Core 2 Duo. This is a problem since I'm creating the gam...
9
2010-03-27T18:43:18Z
2,530,820
<p>On your profile results:</p> <blockquote> <p>I recently found out that you should only update the areas of the screen that have changed, but I'm still foggy on how that accomplished exactly... could this be a huge performance issue?</p> </blockquote> <p>Yes. <code>display.update</code> and <code>Surface.blit</c...
2
2010-03-27T20:31:06Z
[ "python", "performance", "pygame", "frame-rate" ]
Help getting frame rate (fps) up in Python + Pygame
2,530,478
<p>I am working on a little card-swapping world-travel game that I sort of envision as a cross between Bejeweled and the 10 Days geography board games. So far the coding has been going okay, but the frame rate is pretty bad... currently I'm getting low 20's on my Core 2 Duo. This is a problem since I'm creating the gam...
9
2010-03-27T18:43:18Z
20,252,490
<p>I would say that a simple wait of 5-10ms is enough to seriously tone down the CPU usage that constantly re-rendering the screen causes.</p>
0
2013-11-27T20:28:06Z
[ "python", "performance", "pygame", "frame-rate" ]
Python unit-testing with nose: Making sequential tests
2,530,747
<p>I am just learning how to do unit-testing. I'm on Python / nose / Wing IDE.</p> <p>(<a href="http://garlicsim.org" rel="nofollow">The project</a> that I'm writing tests for is a simulations framework, and among other things it lets you run simulations both synchronously and asynchronously, and the results of the si...
3
2010-03-27T20:06:40Z
2,530,840
<p>In general, I'd recommend <em>not</em> making one test depend upon another. Do the synchronous_test, do the asynchronous_test, compare them each to the expected correct output, not to each other.</p> <p>So something like:</p> <pre><code>class TestSimulate(TestCase): def setup(self): self.simpack = Sim...
5
2010-03-27T20:38:29Z
[ "python", "unit-testing", "nose" ]
Python unit-testing with nose: Making sequential tests
2,530,747
<p>I am just learning how to do unit-testing. I'm on Python / nose / Wing IDE.</p> <p>(<a href="http://garlicsim.org" rel="nofollow">The project</a> that I'm writing tests for is a simulations framework, and among other things it lets you run simulations both synchronously and asynchronously, and the results of the si...
3
2010-03-27T20:06:40Z
2,530,916
<p>You can add tests that need to calculate once per class to the "setup" of that class. As an example:</p> <pre><code>from nose.tools import * class Test_mysim(): def setup(self): self.ans = calculate_it_once() def test_sync(self): ans=calculate_it_sync() assert_equal(ans,self.ans) ...
6
2010-03-27T20:58:49Z
[ "python", "unit-testing", "nose" ]
python MySQLdb got invalid syntax when trying to INSERT INTO table
2,530,770
<pre><code>## COMMENT OUT below just for reference "" cursor.execute (""" CREATE TABLE yellowpages ( business_id BIGINT(20) NOT NULL AUTO_INCREMENT, categories_name VARCHAR(255), business_name VARCHAR(500) NOT NULL, business_address1 VARCHAR(500), business_city VARC...
1
2010-03-27T20:11:54Z
2,530,780
<p>I think your problem is here:</p> <pre><code>''gas-stations'' </code></pre> <p>This gives a syntax error. You probably want to use one set of quotes:</p> <pre><code>'gas-stations' </code></pre> <p>If you want to insert the value <code>'gas-stations'</code> into the database including the quotes then you can eith...
2
2010-03-27T20:14:45Z
[ "python", "mysql", "insert" ]
python MySQLdb got invalid syntax when trying to INSERT INTO table
2,530,770
<pre><code>## COMMENT OUT below just for reference "" cursor.execute (""" CREATE TABLE yellowpages ( business_id BIGINT(20) NOT NULL AUTO_INCREMENT, categories_name VARCHAR(255), business_name VARCHAR(500) NOT NULL, business_address1 VARCHAR(500), business_city VARC...
1
2010-03-27T20:11:54Z
2,530,781
<p>You can't use doubled single-quotes (i.e. <code>''gas-stations''</code>) - use either just single single-quotes (<code>'gas-stations'</code>), or actual double quotes (<code>"gas-stations"</code>).</p>
0
2010-03-27T20:15:03Z
[ "python", "mysql", "insert" ]
python MySQLdb got invalid syntax when trying to INSERT INTO table
2,530,770
<pre><code>## COMMENT OUT below just for reference "" cursor.execute (""" CREATE TABLE yellowpages ( business_id BIGINT(20) NOT NULL AUTO_INCREMENT, categories_name VARCHAR(255), business_name VARCHAR(500) NOT NULL, business_address1 VARCHAR(500), business_city VARC...
1
2010-03-27T20:11:54Z
2,531,227
<p>For your second problem, you need to lose all those single-quote characters in your VALUES clause ... should look like <code>VALUES (%s,%s)</code> not like <code>VALUES ('%s','%s')</code>.</p> <p>The general rules are very simple: for each parameter, have one place-marker (in the case of mySQLdb this is <code>%s</c...
1
2010-03-27T22:50:27Z
[ "python", "mysql", "insert" ]
python MySQLdb got invalid syntax when trying to INSERT INTO table
2,530,770
<pre><code>## COMMENT OUT below just for reference "" cursor.execute (""" CREATE TABLE yellowpages ( business_id BIGINT(20) NOT NULL AUTO_INCREMENT, categories_name VARCHAR(255), business_name VARCHAR(500) NOT NULL, business_address1 VARCHAR(500), business_city VARC...
1
2010-03-27T20:11:54Z
32,871,921
<p>I also got such error and I solved it by replacing '%s' by %s under values. </p> <pre><code> VALUES(%s,%s) </code></pre>
0
2015-09-30T17:07:24Z
[ "python", "mysql", "insert" ]
Python regex group clarification
2,530,794
<p>I have 0 experience with python, very little with regex and I'm trying to figure out what this small snippet of python regex would give back from a http response header Set-Cookie entry:</p> <pre><code>REGEX_COOKIE = '([A-Z]+=[^;]+;)' resp = urllib2.urlopen(req) re.search(REGEX_COOKIE, resp.info()['Set-Cookie']).gr...
1
2010-03-27T20:20:24Z
2,530,799
<p>A <a href="http://en.wikipedia.org/wiki/HTTP_cookie" rel="nofollow">Set-Cookie</a> is a list of name value pairs, separated with semi-colons:</p> <pre> HTTP/1.1 200 OK Content-type: text/html Set-Cookie: RMID=732423sdfs73242; expires=Fri, 31-Dec-2010 23:59:59 GMT (content of page) </pre> <p>The regular expression...
4
2010-03-27T20:22:54Z
[ "python", "regex" ]
Python: How to transfer varrying length arrays over a network connection
2,530,865
<p>I need to transfer an array of varying length in which each element is a tuple of two integers. As an example:</p> <pre><code>path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] </code></pre> <p>I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such ...
5
2010-03-27T20:44:59Z
2,530,892
<p>If you include message length as part of the message, then you will know how much data to read. So the entire string should be read across the network.</p> <p>In any case, perhaps it would help if you posted some of the code you are using to send data across the network, or at least provided more of a description.<...
0
2010-03-27T20:51:03Z
[ "python", "arrays", "networking", "unpack", "pack" ]
Python: How to transfer varrying length arrays over a network connection
2,530,865
<p>I need to transfer an array of varying length in which each element is a tuple of two integers. As an example:</p> <pre><code>path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] </code></pre> <p>I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such ...
5
2010-03-27T20:44:59Z
2,530,894
<p>Pack and unpack are mandatory? If not, you could use <a href="http://it.wikipedia.org/wiki/JSON" rel="nofollow">JSON</a> and <a href="http://en.wikipedia.org/wiki/YAML" rel="nofollow">YAML</a>.</p> <p>Don't use <a href="http://docs.python.org/library/pickle" rel="nofollow">pickle</a> because is not secure.</p>
0
2010-03-27T20:52:04Z
[ "python", "arrays", "networking", "unpack", "pack" ]
Python: How to transfer varrying length arrays over a network connection
2,530,865
<p>I need to transfer an array of varying length in which each element is a tuple of two integers. As an example:</p> <pre><code>path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] </code></pre> <p>I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such ...
5
2010-03-27T20:44:59Z
2,530,899
<p>While you can use pack and unpack, I'd recommend using something like <a href="http://yaml.org/" rel="nofollow">YAML</a> or <a href="http://www.json.org/" rel="nofollow">JSON</a> to transfer your data.</p> <ul> <li>Pack and unpack can lead to difficult to debug errors and incompatibilities if you change your interf...
7
2010-03-27T20:53:43Z
[ "python", "arrays", "networking", "unpack", "pack" ]
Python: How to transfer varrying length arrays over a network connection
2,530,865
<p>I need to transfer an array of varying length in which each element is a tuple of two integers. As an example:</p> <pre><code>path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] </code></pre> <p>I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such ...
5
2010-03-27T20:44:59Z
2,530,910
<p>You want some sort of serialization protocol. <code>twisted.spread</code> provides one such (see <a href="http://twistedmatrix.com/documents/current/core/specifications/banana.html" rel="nofollow">the Banana specification</a> or <a href="http://twistedmatrix.com/documents/current/core/howto/index.html" rel="nofollo...
1
2010-03-27T20:57:03Z
[ "python", "arrays", "networking", "unpack", "pack" ]
Python: How to transfer varrying length arrays over a network connection
2,530,865
<p>I need to transfer an array of varying length in which each element is a tuple of two integers. As an example:</p> <pre><code>path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] </code></pre> <p>I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such ...
5
2010-03-27T20:44:59Z
2,530,990
<p>Take a look at <a href="http://docs.python.org/library/xdrlib.html" rel="nofollow">xdrlib</a>, it might help. It's part of the standard library, and:</p> <blockquote> <p>The xdrlib module supports the External Data Representation Standard as described in <a href="http://www.rfc-editor.org/in-notes/rfc1014.txt" re...
0
2010-03-27T21:26:04Z
[ "python", "arrays", "networking", "unpack", "pack" ]
How do I translate Ruby's IO.popen calls into Python's subprocess.Popen calls?
2,530,906
<p>I've read the documentation and I've tried lots of things in the REPL, and Googled, but I can't for the life of me understand how <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a>.Popen works in Python.</p> <p>Here is some Ruby code I am using:</p> <pre><code>IO.popen("some-pro...
0
2010-03-27T20:55:53Z
2,531,215
<p>Probably the simplest "close relative" of your Ruby code in Python:</p> <pre><code>&gt;&gt;&gt; import subprocess &gt;&gt;&gt; io = subprocess.Popen('ls', stdout=subprocess.PIPE).stdout &gt;&gt;&gt; for line in io: print(line.strip()) </code></pre>
2
2010-03-27T22:44:59Z
[ "python", "ruby", "subprocess", "popen", "io" ]
How do I translate Ruby's IO.popen calls into Python's subprocess.Popen calls?
2,530,906
<p>I've read the documentation and I've tried lots of things in the REPL, and Googled, but I can't for the life of me understand how <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a>.Popen works in Python.</p> <p>Here is some Ruby code I am using:</p> <pre><code>IO.popen("some-pro...
0
2010-03-27T20:55:53Z
2,531,238
<pre><code>import subprocess process = subprocess.Popen(['ls',], stdout=subprocess.PIPE) print process.communicate()[0] </code></pre>
0
2010-03-27T22:53:18Z
[ "python", "ruby", "subprocess", "popen", "io" ]
Matplotlib canvas drawing
2,531,333
<p>Let's say I define a few functions to do certain <code>matplotlib</code> actions, such as</p> <pre><code>def dostuff(ax): ax.scatter([0.],[0.]) </code></pre> <p>Now if I launch <code>ipython</code>, I can load these functions and start a new figure:</p> <pre><code>In [1]: import matplotlib.pyplot as mpl In [...
0
2010-03-27T23:28:51Z
2,531,346
<p>Why doesn't my answer to <a href="http://stackoverflow.com/questions/2529592/refresh-decorator/2529844#2529844">this SO question of yours</a> about "refresh decorator" make it simple? I showed exactly what to do what you're <strong>again</strong> requesting here (by keeping a count of nestings -- incidentally, one ...
1
2010-03-27T23:37:28Z
[ "python", "algorithm", "matplotlib" ]
CentOS: make python 2.6 see django
2,531,364
<p>In a harrowing attempt to get mod_wsgi to run on CentOS 5.4, I've added python 2.6 as an optional library following the <a href="http://binarysushi.com/blog/2009/aug/19/CentOS-5-3-python-2-5-virtualevn-mod-wsgi-and-mod-rpaf/" rel="nofollow">instructions here</a>. The configuration seems fine except that when trying ...
1
2010-03-27T23:43:58Z
2,531,387
<p>You need to install Django specifically with/for the Python version that's meant to use it -- installs for 2.4 and 2.6 are always going to be separate (they have to be -- there are incompatibilities in binary and bytecode formats!). I don't know what, if any, possibilities CentOS offers for that -- I'd get Django's...
0
2010-03-27T23:52:13Z
[ "python", "django", "centos", "mod-wsgi" ]
CentOS: make python 2.6 see django
2,531,364
<p>In a harrowing attempt to get mod_wsgi to run on CentOS 5.4, I've added python 2.6 as an optional library following the <a href="http://binarysushi.com/blog/2009/aug/19/CentOS-5-3-python-2-5-virtualevn-mod-wsgi-and-mod-rpaf/" rel="nofollow">instructions here</a>. The configuration seems fine except that when trying ...
1
2010-03-27T23:43:58Z
2,577,566
<p>I created a write up <a href="http://blog.timc3.com/2010/03/26/django-on-redhat-or-centos/" rel="nofollow">link text</a> of my experiences of getting Django working on Redhat and and CentOS. I upgraded the version of python that I was using and started with init.d scripts.</p>
0
2010-04-05T08:48:49Z
[ "python", "django", "centos", "mod-wsgi" ]
Convert binary information to regular data type without outside modules in python
2,531,439
<p>I'm tasked with reading a poorly formatted binary file and taking in the variables. Although I need to do it in C++ (ROOT, specifically), I've decided to do it in python because python makes sense to me, but my plan is to get it working in python and then tackle re-writing in in C++, so using easy to use python modu...
1
2010-03-28T00:14:16Z
2,531,448
<p>The equivalent to the Python <a href="http://docs.python.org/library/struct.html" rel="nofollow"><code>struct</code></a> module is a C <code>struct</code> and/or <code>union</code>, so being afraid to use it is silly.</p>
1
2010-03-28T00:20:54Z
[ "python", "binary" ]
Convert binary information to regular data type without outside modules in python
2,531,439
<p>I'm tasked with reading a poorly formatted binary file and taking in the variables. Although I need to do it in C++ (ROOT, specifically), I've decided to do it in python because python makes sense to me, but my plan is to get it working in python and then tackle re-writing in in C++, so using easy to use python modu...
1
2010-03-28T00:14:16Z
2,531,452
<p>You're basically computing a "number-in-base-256", which is a polynomial, so, by Horner's method:</p> <pre><code>&gt;&gt;&gt; v = 0 &gt;&gt;&gt; for c in someval: v = v * 256 + ord(c) </code></pre> <p>More typical would be to use equivalent bit-operations rather than arithmetic -- the following's equivalent:</p> ...
2
2010-03-28T00:23:03Z
[ "python", "binary" ]
Convert binary information to regular data type without outside modules in python
2,531,439
<p>I'm tasked with reading a poorly formatted binary file and taking in the variables. Although I need to do it in C++ (ROOT, specifically), I've decided to do it in python because python makes sense to me, but my plan is to get it working in python and then tackle re-writing in in C++, so using easy to use python modu...
1
2010-03-28T00:14:16Z
2,531,456
<p>I'm not exactly sure how the format of the data is you want to extract, but maybe you better just write a couple of generic utility functions to extract the different data type you need:</p> <pre><code>def int1b(data, i): return ord(data[i]) def int2b(data, i): return (int1b(data, i) &lt;&lt; 8) + int1b(data...
0
2010-03-28T00:23:28Z
[ "python", "binary" ]
Convert binary information to regular data type without outside modules in python
2,531,439
<p>I'm tasked with reading a poorly formatted binary file and taking in the variables. Although I need to do it in C++ (ROOT, specifically), I've decided to do it in python because python makes sense to me, but my plan is to get it working in python and then tackle re-writing in in C++, so using easy to use python modu...
1
2010-03-28T00:14:16Z
2,531,550
<pre><code>import struct result, = struct.unpack('&gt;H', some_value) </code></pre>
2
2010-03-28T01:07:23Z
[ "python", "binary" ]
Convert binary information to regular data type without outside modules in python
2,531,439
<p>I'm tasked with reading a poorly formatted binary file and taking in the variables. Although I need to do it in C++ (ROOT, specifically), I've decided to do it in python because python makes sense to me, but my plan is to get it working in python and then tackle re-writing in in C++, so using easy to use python modu...
1
2010-03-28T00:14:16Z
2,531,882
<p>Your <code>int(''.join([str(ord(i)) for i in some_value]))</code> works ONLY when all bytes except the last byte are zero. Examples:<br> <code>'\x01I'</code> should be 1 * 256 + 73 == 329; you get 173<br> <code>'\x01\x02'</code> should be 1 * 256 + 2 == 258; you get 12<br> <code>'\x01\x00'</code> should be 1 * 256 ...
2
2010-03-28T04:19:18Z
[ "python", "binary" ]
Hide deprecated methods from tab completion
2,531,479
<p>I would like to control which methods appear when a user uses tab-completion on a custom object in ipython - in particular, I want to hide functions that I have deprecated. I still want these methods to be callable, but I don't want users to see them and start using them if they are inspecting the object. Is this so...
3
2010-03-28T00:35:05Z
2,531,535
<p>The <code>DeprecationWarning</code> isn't emitted until the method is called, so you'd have to have a separate attribute on the class that stores the names of deprecated methods, then check that before suggesting a completion.</p> <p>Alternatively, you could walk the AST for the method looking for <code>Deprecation...
0
2010-03-28T01:01:17Z
[ "python", "ipython" ]
Hide deprecated methods from tab completion
2,531,479
<p>I would like to control which methods appear when a user uses tab-completion on a custom object in ipython - in particular, I want to hide functions that I have deprecated. I still want these methods to be callable, but I don't want users to see them and start using them if they are inspecting the object. Is this so...
3
2010-03-28T00:35:05Z
2,586,600
<p>Partial answer for you. I'll post the example code and then explain why its only a partial answer.<br> Code:</p> <pre><code>class hidden(object): # or whatever its parent class is def __init__(self): self.value = 4 def show(self): return self.value def change(self,n): self.value...
4
2010-04-06T16:44:13Z
[ "python", "ipython" ]
Hide deprecated methods from tab completion
2,531,479
<p>I would like to control which methods appear when a user uses tab-completion on a custom object in ipython - in particular, I want to hide functions that I have deprecated. I still want these methods to be callable, but I don't want users to see them and start using them if they are inspecting the object. Is this so...
3
2010-03-28T00:35:05Z
2,610,405
<p>About the completion mechanism in IPython, it is documented here:</p> <p><a href="http://ipython.scipy.org/doc/manual/html/api/generated/IPython.core.completer.html#ipcompleter" rel="nofollow">http://ipython.scipy.org/doc/manual/html/api/generated/IPython.core.completer.html#ipcompleter</a></p> <p>But a really int...
0
2010-04-09T19:43:25Z
[ "python", "ipython" ]
Hide deprecated methods from tab completion
2,531,479
<p>I would like to control which methods appear when a user uses tab-completion on a custom object in ipython - in particular, I want to hide functions that I have deprecated. I still want these methods to be callable, but I don't want users to see them and start using them if they are inspecting the object. Is this so...
3
2010-03-28T00:35:05Z
2,610,617
<p>Seems like there is a special <a href="http://docs.python.org/library/functions.html#dir" rel="nofollow">magic method</a> for the introcpection which is called by dir(): <code>__dir__()</code>. Isn't it what you are lookin for?</p>
0
2010-04-09T20:17:36Z
[ "python", "ipython" ]
Apply relative URL to an absolute URL
2,531,538
<p>I have an absolute URL, and the URL that a link on that page points to. Is there a builtin function to apply a relative URL to an absolute URL?</p> <p>Ie. "http://example.com/some/url", "/some/url/I/want/to/go/to" => "http://example.com/some/url/I/want/to/go/to"</p>
9
2010-03-28T01:03:05Z
2,531,554
<p><a href="http://docs.python.org/library/urlparse.html#urlparse.urljoin"><code>urlparse.urljoin()</code></a> does just this.</p>
9
2010-03-28T01:09:46Z
[ "python", "url" ]
I am having issues with django test
2,531,658
<p>I have this test case</p> <pre><code>def setUp(self): self.user = User.objects.create(username="tauri", password='gaul') def test_loginin_student_control_panel(self): c = Client() c.login(username="tauri", password="gaul") response = c.get('/student/') self.assertEqual(response.status_code, 200) </...
0
2010-03-28T02:10:06Z
2,531,763
<p>Did you make sure to create the user entry in your setUp function?</p> <p><code>User.objects.create_user(username="tauri", password="gual")</code></p>
1
2010-03-28T03:11:18Z
[ "python", "django", "unit-testing" ]
I am having issues with django test
2,531,658
<p>I have this test case</p> <pre><code>def setUp(self): self.user = User.objects.create(username="tauri", password='gaul') def test_loginin_student_control_panel(self): c = Client() c.login(username="tauri", password="gaul") response = c.get('/student/') self.assertEqual(response.status_code, 200) </...
0
2010-03-28T02:10:06Z
2,531,982
<p>The problem is the way you create your User object.</p> <p>Django does not store your password in plain text in the database, it stores its hash value. But in your code password is set in plain text.</p> <p>So when you use <code>c.login(...)</code> internally Django will make a call to <code>check_password</code> ...
4
2010-03-28T05:19:04Z
[ "python", "django", "unit-testing" ]
In Python, what are some examples of when decorators greatly simplify a task?
2,531,696
<p>Trying to find examples of when decorators might be really beneficial, and when not so much. Sample code is appreciated.</p>
5
2010-03-28T02:31:54Z
2,531,705
<p>The usual example is using the <code>@property</code> decorator to make a read-only property:</p> <pre><code>@property def count(self): return self._events </code></pre> <p>instead of:</p> <pre><code>def _get_count(self): return self._events count = property(_get_count) </code></pre>
4
2010-03-28T02:36:06Z
[ "python", "decorator" ]
In Python, what are some examples of when decorators greatly simplify a task?
2,531,696
<p>Trying to find examples of when decorators might be really beneficial, and when not so much. Sample code is appreciated.</p>
5
2010-03-28T02:31:54Z
2,531,716
<p>In the AppEngine API, there's the nice <a href="http://code.google.com/appengine/docs/python/tools/webapp/utilmodule.html" rel="nofollow"><code>@login_required</code></a> decorator, which can clean up code quite a bit:</p> <pre><code>class MyPage(webapp.RequestHandler): @login_required def get(self): ...
1
2010-03-28T02:44:28Z
[ "python", "decorator" ]
In Python, what are some examples of when decorators greatly simplify a task?
2,531,696
<p>Trying to find examples of when decorators might be really beneficial, and when not so much. Sample code is appreciated.</p>
5
2010-03-28T02:31:54Z
2,531,719
<p>Decorators are simple syntax for a specific way to call higher-order functions, so if you're focusing just on the syntax it's unlikely to make a <strong>great</strong> difference. IOW, wherever you can say</p> <pre><code>@mydecorator def f(...): # body of f </code></pre> <p>you could identically say</p> <pre><...
8
2010-03-28T02:44:41Z
[ "python", "decorator" ]
In Python, what are some examples of when decorators greatly simplify a task?
2,531,696
<p>Trying to find examples of when decorators might be really beneficial, and when not so much. Sample code is appreciated.</p>
5
2010-03-28T02:31:54Z
2,531,749
<p>The easiest way to understand the usefulness of decorators is to see some examples. Here is one, for instance:</p> <p>Suppose you are studying some code and wish to understand when and how a function is called. You can use a decorator to alter the function so it prints some debugging information each time the fun...
4
2010-03-28T03:03:46Z
[ "python", "decorator" ]
In Python, what are some examples of when decorators greatly simplify a task?
2,531,696
<p>Trying to find examples of when decorators might be really beneficial, and when not so much. Sample code is appreciated.</p>
5
2010-03-28T02:31:54Z
2,531,767
<p>Decorators are for design choices where you are merging two concepts, like "Logging" and "Inventory Management" or "is registered user" and "View Lastest Messages". </p> <ul> <li>One of those concepts is wrapping the other, controlling how it is called. That concept is the decorator.</li> <li>The second concept ...
1
2010-03-28T03:13:26Z
[ "python", "decorator" ]
Key word extraction in Python
2,531,717
<p>I'm building a website in django that needs to extract key words from short (twitter-like) messages.</p> <p>I've looked at packages like topia.textextract and nltk - but both seem to be overkill for what I need to do. All I need to do is filter words like "and", "or", "not" while keeping nouns and verbs that aren't...
1
2010-03-28T02:44:31Z
2,531,724
<p>You can make a set <code>sw</code> of the "stop words" you want to eliminate (maybe <em>copy</em> it once and for all from the stop words corpus of NLTK, depending how familiar you are with the various natural languages you need to support), then apply it very simply.</p> <p>E.g., if you have a list of words <code>...
3
2010-03-28T02:47:35Z
[ "python", "django", "keyword" ]
Key word extraction in Python
2,531,717
<p>I'm building a website in django that needs to extract key words from short (twitter-like) messages.</p> <p>I've looked at packages like topia.textextract and nltk - but both seem to be overkill for what I need to do. All I need to do is filter words like "and", "or", "not" while keeping nouns and verbs that aren't...
1
2010-03-28T02:44:31Z
2,531,927
<p>Abbreviations like NO for navigation officer or OR for operations room need a little care lest you cause a SNAFU ;-) One suspects that better results could be obtained from "Find the NO and send her to the OR" by tagging the words with parts of speech using the context ... hint 1: "the OR" should result in "the [nou...
1
2010-03-28T04:47:47Z
[ "python", "django", "keyword" ]
Multiple Unpacking Assignment in Python when you don't know the sequence length
2,531,776
<p>The textbook examples of multiple unpacking assignment are something like:</p> <pre><code>import numpy as NP M = NP.arange(5) a, b, c, d, e = M # so of course, a = 0, b = 1, etc. M = NP.arange(20).reshape(5, 4) # numpy 5x4 array a, b, c, d, e = M # here, a = M[0,:], b = M[1,:], etc. (ie, a single row of M is a...
5
2010-03-28T03:17:54Z
2,531,790
<p>Python 3.x can do this easily:</p> <pre><code>a, b, *c = someseq </code></pre> <p>Python 2.x needs a bit more work:</p> <pre><code>(a, b), c = someseq[:2], someseq[2:] </code></pre>
10
2010-03-28T03:23:49Z
[ "python", "variable-assignment" ]
Multiple Unpacking Assignment in Python when you don't know the sequence length
2,531,776
<p>The textbook examples of multiple unpacking assignment are something like:</p> <pre><code>import numpy as NP M = NP.arange(5) a, b, c, d, e = M # so of course, a = 0, b = 1, etc. M = NP.arange(20).reshape(5, 4) # numpy 5x4 array a, b, c, d, e = M # here, a = M[0,:], b = M[1,:], etc. (ie, a single row of M is a...
5
2010-03-28T03:17:54Z
2,531,792
<p>Syntax for this is added to Python 3</p> <pre><code>&gt;&gt;&gt; # Python 3.x only &gt;&gt;&gt; a, b, *c = range(10) &gt;&gt;&gt; a 0 &gt;&gt;&gt; b 1 &gt;&gt;&gt; c [2, 3, 4, 5, 6, 7, 8, 9] </code></pre> <p>but no similar solution exists in Python 2. </p> <p>You can of course do</p> <pre><code>&gt;&gt;&gt; s = ...
6
2010-03-28T03:25:07Z
[ "python", "variable-assignment" ]