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 |
|---|---|---|---|---|---|---|---|---|---|
Get HTML links within a specified <table> using minidom | 2,051,270 | <p>I'm looking to use Python and xml.dom.minidom to get a list of links within a particular <code><table></code> specified by the table id. Based on some <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">excellent advice</a>, I'm trying to ... | 1 | 2010-01-12T18:15:27Z | 2,051,598 | <p>The problem is that minidom is a non-external-entity-reading XML parser. That means it doesn't even look at the DTD, so it doesn't know that in HTML the attribute with the name <code>id</code> corresponds to an <code>ID</code> schema type.</p>
<p>A further consequence of this is that minidom won't know about the HT... | 4 | 2010-01-12T19:09:08Z | [
"python",
"minidom"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 2,051,499 | <p><code>ForeignKey</code> is implemented as <code>IntegerField</code> in the database, so you save little to nothing at the cost of crippling your model.</p>
<p><strong>Edit:</strong>
And for pete's sake, keep it in one table and use indexes as appropriate.</p>
| 8 | 2010-01-12T18:50:00Z | [
"python",
"django",
"django-models",
"django-database"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 2,051,563 | <p>I'm not familiar with Django, but I have a general understanding of DB.</p>
<p>When you have large databases, it's pretty normal to <a href="http://en.wikipedia.org/wiki/Index_%28database%29" rel="nofollow">index your database</a>. That way, retrieving data, should be pretty quick.</p>
<p>When it comes to associat... | 0 | 2010-01-12T19:02:51Z | [
"python",
"django",
"django-models",
"django-database"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 2,051,607 | <p>Are you having performance problems? If so, you might need to <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#db-index" rel="nofollow">add a few indexes</a>. </p>
<p>One way to get an idea where an index would help is by looking at your db server's query log (<a href="http://dev.mysql.com/doc/refma... | 0 | 2010-01-12T19:10:05Z | [
"python",
"django",
"django-models",
"django-database"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 2,051,657 | <p>A common approach to this type of problem is <a href="http://en.wikipedia.org/wiki/Shard_%28database_architecture%29" rel="nofollow">Sharding</a>. Unfortunately it's mostly up to the ORM to implement it (Hibernate does it wonderfully) and Django does not support this. However, I'm not sure 4 million rows is really a... | 0 | 2010-01-12T19:16:38Z | [
"python",
"django",
"django-models",
"django-database"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 2,052,058 | <p>Like many have said, it's a bit premature to split your table up into smaller tables (horizontal partitioning or even sharding). Databases are made to handle tables of this size, so your performance problem is probably somewhere else. </p>
<p>Indexes are the first step, it sounds like you've done this though. 4 mil... | 10 | 2010-01-12T20:20:11Z | [
"python",
"django",
"django-models",
"django-database"
] |
Django Table with Million of rows | 2,051,481 | <p>I have a project with 2 applications ( books and reader ).</p>
<p>Books application has a table with 4 milions of rows with this fields:</p>
<pre><code> book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
</code></pre>
<p>To avoid to query the database with 4 milions ... | 7 | 2010-01-12T18:47:30Z | 9,565,934 | <p>You haven't mentioned which database you're using. Some databases - like MySQL and PostgreSQL - have extremely conservative settings out-of-the-box, which are basically unusable for anything except tiny databases on tiny servers.</p>
<p>If you tell us which database you're using, and what hardware it's running on, ... | 1 | 2012-03-05T11:35:02Z | [
"python",
"django",
"django-models",
"django-database"
] |
PyQt4 Drag & Drop | 2,051,488 | <p>Qt4 has support for Drag & Drop actions and I've used them like in the <a href="http://zetcode.com/tutorials/pyqt4/dragdrop/" rel="nofollow">tutorial</a>. Now I want to be able to drag external elements (files) into the GUI form and perform actions based on that (like get the full path and copy it somewhere). </... | 1 | 2010-01-12T18:48:23Z | 2,052,153 | <p>Most file managers provide drag-and-drop data using the <code>text/uri-list</code> target.</p>
<p>Regarding the linked tutorial, first you need to set the widget to accept dropping <code>text/uri-list</code> data, then you can retrieve the URIs by calling <code>event.mimeData().urls()</code>. The return value is a ... | 3 | 2010-01-12T20:34:11Z | [
"python",
"qt4",
"pyqt4"
] |
"Optional" backreferences in regular expression | 2,051,552 | <p>I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference <em>only</em> if it matched? In all cases, I'm wanting to match <strong>spam.eggs.com</strong></p>
<p>Example:</p>
<pre><code>import re
monitorName = re.compile(r"HQ01 : HTTP Service - ... | 1 | 2010-01-12T18:59:53Z | 2,051,561 | <pre><code>m = monitorName.search(t)
g = m.groups()
print g[0] or g[1]
</code></pre>
| 1 | 2010-01-12T19:02:32Z | [
"python",
"regex"
] |
"Optional" backreferences in regular expression | 2,051,552 | <p>I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference <em>only</em> if it matched? In all cases, I'm wanting to match <strong>spam.eggs.com</strong></p>
<p>Example:</p>
<pre><code>import re
monitorName = re.compile(r"HQ01 : HTTP Service - ... | 1 | 2010-01-12T18:59:53Z | 2,051,565 | <p>Use <code>m.group(1) or m.group(2)</code>.</p>
| 1 | 2010-01-12T19:03:02Z | [
"python",
"regex"
] |
"Optional" backreferences in regular expression | 2,051,552 | <p>I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference <em>only</em> if it matched? In all cases, I'm wanting to match <strong>spam.eggs.com</strong></p>
<p>Example:</p>
<pre><code>import re
monitorName = re.compile(r"HQ01 : HTTP Service - ... | 1 | 2010-01-12T18:59:53Z | 2,051,567 | <p>The <code>|</code> operator has early precedence so it applies to <em>everything</em> before it (<em>from the beginning of your regex</em> in this case) OR everything after it. In your regex, if there is no "srv04.example.com", it isn't checking if the string contains "HTTP Service"!</p>
<p>Your two capturing group... | 2 | 2010-01-12T19:03:15Z | [
"python",
"regex"
] |
"Optional" backreferences in regular expression | 2,051,552 | <p>I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference <em>only</em> if it matched? In all cases, I'm wanting to match <strong>spam.eggs.com</strong></p>
<p>Example:</p>
<pre><code>import re
monitorName = re.compile(r"HQ01 : HTTP Service - ... | 1 | 2010-01-12T18:59:53Z | 2,051,659 | <p>I will rewrite the regular expression to be</p>
<pre><code>monitorName = re.compile(r"HQ01 : HTTP Service - (?:(?i)SRV\d+\.\w+\.com:)?(\w+\.\w+\.(?:net|com|org))")
</code></pre>
<p>Produces</p>
<pre><code>('spam.eggs.com',)
('spam.eggs.com',)
('spam.eggs.com',)
('spam.eggs.com',)
</code></pre>
<p>You can make gr... | 0 | 2010-01-12T19:16:47Z | [
"python",
"regex"
] |
"Optional" backreferences in regular expression | 2,051,552 | <p>I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference <em>only</em> if it matched? In all cases, I'm wanting to match <strong>spam.eggs.com</strong></p>
<p>Example:</p>
<pre><code>import re
monitorName = re.compile(r"HQ01 : HTTP Service - ... | 1 | 2010-01-12T18:59:53Z | 2,051,662 | <p>Did you consider this?</p>
<pre><code>HQ01 : HTTP Service - (?:[Ss][Rr][Vv]\d+\.\w+\.com:)?(\w+\.\w+\.(?:net|com|org))
</code></pre>
| 0 | 2010-01-12T19:17:41Z | [
"python",
"regex"
] |
django combine models.DecimalField with forms -> error: quantize result has too many digits for current context | 2,051,575 | <p>I want to combine a model decimal field with a forms choice field.</p>
<p>The field in the model:</p>
<pre><code>sum = models.DecimalField(max_digits=2, decimal_places=2)
</code></pre>
<p>The field in the form:</p>
<pre><code>sum = forms.ChoiceField(choices=WORK_HOUR_CHOICES, label='Sum Working Hours', required=... | 5 | 2010-01-12T19:04:48Z | 2,051,674 | <p>It's just a guess, but I bet you need to put Decimals in there: </p>
<pre><code>WORK_HOUR_CHOICES = (
(Decimal("0"), '0'),
(Decimal("0.5"), '0.5'),
(Decimal("1"), '1'),
(Decimal("1.5"), '1.5'),
(Decimal("2"), '2'),
(Decimal("2.5"), '2.5')
)
</code></pre>
<p>You can't initialize a Decimal wi... | 6 | 2010-01-12T19:19:39Z | [
"python",
"django"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 2,052,203 | <p>Use <a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis">matplotlib.pyplot.axis()</a></p>
<p><code>axis([xmin, xmax, ymin, ymax])</code></p>
<p>So you could add something like this at the end:</p>
<pre><code>plt.axis([min(x_arr), max(x_arr), max(y_arr), 0])
</code></pre>
<p>Alth... | 9 | 2010-01-12T20:42:39Z | [
"python",
"matplotlib"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 2,052,799 | <p><a href="http://stackoverflow.com/questions/2051744/pyplot-reverse-y-axis/2052203#2052203">DisplacedAussie</a>'s answer is correct, but usually a shorter method is just to reverse the single axis in question:</p>
<pre><code>plt.scatter(x_arr, y_arr)
ax = plt.gca()
ax.set_ylim(ax.get_ylim()[::-1])
</code></pre>
<p>... | 22 | 2010-01-12T22:04:08Z | [
"python",
"matplotlib"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 8,280,500 | <p>There is a new API that makes this even simpler.</p>
<pre><code>plt.gca().invert_xaxis()
</code></pre>
<p>and/or</p>
<pre><code>plt.gca().invert_yaxis()
</code></pre>
| 204 | 2011-11-26T18:12:42Z | [
"python",
"matplotlib"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 12,842,043 | <p>If you're in ipython in <code>pylab</code> mode, then</p>
<pre><code>plt.gca().invert_yaxis()
show()
</code></pre>
<p>the <code>show()</code> is required to make it update the current figure.</p>
| 8 | 2012-10-11T14:34:13Z | [
"python",
"matplotlib"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 30,475,813 | <p>Another similar method to those described above is to use <code>plt.ylim</code> for example:</p>
<pre><code>plt.ylim(max(y_array), min(y_array))
</code></pre>
<p>This method works for me when I'm attempting to compound multiple datasets on Y1 and/or Y2</p>
| 3 | 2015-05-27T07:26:31Z | [
"python",
"matplotlib"
] |
Reverse Y-Axis in PyPlot | 2,051,744 | <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_arr.append... | 88 | 2010-01-12T19:31:47Z | 32,502,481 | <p>Alternatively, you can use the <a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis" rel="nofollow">matplotlib.pyplot.axis()</a> function, which allows you inverting any of the plot axis</p>
<pre><code>ax = matplotlib.pyplot.axis()
matplotlib.pyplot.axis((ax[0],ax[1],ax[3],ax[2]))
<... | 1 | 2015-09-10T12:53:13Z | [
"python",
"matplotlib"
] |
How to remove expired items from database with Scrapy | 2,051,842 | <p>I am using spidering a video site that expires content frequently. I am considering using <a href="http://scrapy.org/" rel="nofollow">scrapy</a> to do my spidering, but am not sure how to delete expired items.</p>
<p>Strategies to detect if an item is expired are:</p>
<ol>
<li>Spider the site's "delete.rss".</li>... | 3 | 2010-01-12T19:44:47Z | 2,083,814 | <p>If you have a HTTP URL which you suspect might not be valid at all any more (because you found it in a "deleted" feed, or just because you haven't checked it in a while), the simplest, fastest way to check is to send an HTTP <code>HEAD</code> request for that URL. In Python, that's best done with the <a href="http:... | 0 | 2010-01-18T03:55:30Z | [
"python",
"screen-scraping",
"scrapy"
] |
How to remove expired items from database with Scrapy | 2,051,842 | <p>I am using spidering a video site that expires content frequently. I am considering using <a href="http://scrapy.org/" rel="nofollow">scrapy</a> to do my spidering, but am not sure how to delete expired items.</p>
<p>Strategies to detect if an item is expired are:</p>
<ol>
<li>Spider the site's "delete.rss".</li>... | 3 | 2010-01-12T19:44:47Z | 2,084,107 | <p><strong>I haven't tested this!</strong><br>
I have to confess that I haven't tried using the Django models in Scrapy, but here goes:</p>
<p>The simplest way I imagine would be to create a new spider for the <code>deleted.rss</code> file by extending the XMLFeedSpider (<em>Copied from the scrapy documentation, then ... | 4 | 2010-01-18T05:45:11Z | [
"python",
"screen-scraping",
"scrapy"
] |
creating 2 foreign keys that relate to one another | 2,051,895 | <pre><code>class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 127)
def __unicode__(self):
return self.name
class ProductLot(models.Model):
product = models.ForeignKey(Product)
code = mo... | 0 | 2010-01-12T19:54:44Z | 2,051,919 | <p>if you have two FK to one model you need to give different related names:</p>
<pre><code>product = models.ForeignKey(Product, related_name='lot_product')
code = models.ForeignKey(Product, related_name='lot_code')
</code></pre>
<p>related_name comes from django docs:</p>
<blockquote>
<p><strong>ForeignKey.relate... | 3 | 2010-01-12T19:59:06Z | [
"python",
"django"
] |
creating 2 foreign keys that relate to one another | 2,051,895 | <pre><code>class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 127)
def __unicode__(self):
return self.name
class ProductLot(models.Model):
product = models.ForeignKey(Product)
code = mo... | 0 | 2010-01-12T19:54:44Z | 2,051,978 | <p>Make <code>code</code> a property that looks at <code>product</code>:</p>
<pre><code>def getCode(self):
return self.product and self.product.code
def setCode(self, value):
if self.product:
self.product.code = value
self.product.save()
code = property(getCode, setCode)
</code></pre>
<p>You won't be ab... | 1 | 2010-01-12T20:08:04Z | [
"python",
"django"
] |
creating 2 foreign keys that relate to one another | 2,051,895 | <pre><code>class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 127)
def __unicode__(self):
return self.name
class ProductLot(models.Model):
product = models.ForeignKey(Product)
code = mo... | 0 | 2010-01-12T19:54:44Z | 2,052,287 | <p>I think you should revise your models. Right now, each instance of <code>ProductLot</code> points exactly to two products. I'm not sure this is what you want.</p>
<p>It really depends on what the relation between code and product is. Some thoughts:</p>
<ol>
<li><p>Every <code>Product</code> has a unique <code>code... | 0 | 2010-01-12T20:54:17Z | [
"python",
"django"
] |
access to gnome configuration information using python | 2,051,905 | <p>Is there a standard way of accessing Gnome configuration information (i.e. <code>~/.gconf</code>) using Python?</p>
<p><strong>Updated</strong>: please provide a short example.</p>
| 6 | 2010-01-12T19:56:43Z | 2,051,921 | <p>Python GConf, also check out packages like <strong>python-gconf</strong> and/or <strong>gnome-python-gconf</strong> in your distros package repo:</p>
<blockquote>
<p>/usr/share/doc/python-gconf/examples/</p>
</blockquote>
<p>Or <strong>browse the svn</strong> at <a href="http://svn.gnome.org/viewvc/gnome-python/... | 10 | 2010-01-12T19:59:12Z | [
"python",
"gnome"
] |
Python parallel processing libraries | 2,051,984 | <p>Python seems to have <a href="http://wiki.python.org/moin/ParallelProcessing" rel="nofollow">many different packages available</a> to assist one in parallel processing on an SMP based system or across a cluster. I'm interested in building a client server system in which a server maintains a queue of jobs and client... | 5 | 2010-01-12T20:08:41Z | 2,052,085 | <p>Given that you tagged your question "scientific-computing", and mention a cluster, some kind of MPI wrapper seems the obvious choice, if the goal is to develop parallel applications as one might guess from the title. Then again, the text in your question suggests you want to develop a batch scheduler. So I don't rea... | 0 | 2010-01-12T20:23:39Z | [
"python",
"cluster-computing",
"scientific-computing"
] |
Python parallel processing libraries | 2,051,984 | <p>Python seems to have <a href="http://wiki.python.org/moin/ParallelProcessing" rel="nofollow">many different packages available</a> to assist one in parallel processing on an SMP based system or across a cluster. I'm interested in building a client server system in which a server maintains a queue of jobs and client... | 5 | 2010-01-12T20:08:41Z | 2,052,535 | <p>The simplest way to do this would probably just to output the intermediate samples to separate files (or a database) as they finish, and have a process occasionally poll these output files to see if they're sufficient or if more jobs need to be submitted. </p>
| 0 | 2010-01-12T21:30:27Z | [
"python",
"cluster-computing",
"scientific-computing"
] |
Python parallel processing libraries | 2,051,984 | <p>Python seems to have <a href="http://wiki.python.org/moin/ParallelProcessing" rel="nofollow">many different packages available</a> to assist one in parallel processing on an SMP based system or across a cluster. I'm interested in building a client server system in which a server maintains a queue of jobs and client... | 5 | 2010-01-12T20:08:41Z | 2,053,518 | <p>There are also now two different Python wrappers around the map/reduce framework Hadoop:</p>
<p><a href="http://code.google.com/p/happy/" rel="nofollow">http://code.google.com/p/happy/</a></p>
<p><a href="http://wiki.github.com/klbostee/dumbo" rel="nofollow">http://wiki.github.com/klbostee/dumbo</a></p>
<p>Map/Re... | 1 | 2010-01-13T00:25:35Z | [
"python",
"cluster-computing",
"scientific-computing"
] |
Python parallel processing libraries | 2,051,984 | <p>Python seems to have <a href="http://wiki.python.org/moin/ParallelProcessing" rel="nofollow">many different packages available</a> to assist one in parallel processing on an SMP based system or across a cluster. I'm interested in building a client server system in which a server maintains a queue of jobs and client... | 5 | 2010-01-12T20:08:41Z | 2,070,433 | <p>Have a go with <a href="http://www.parallelpython.com/" rel="nofollow">ParallelPython</a>. Seems easy to use, and should provide the jobs and queues interface that you want.</p>
| 2 | 2010-01-15T09:06:09Z | [
"python",
"cluster-computing",
"scientific-computing"
] |
Downgrading to pyobjc 2.0 from pyobjc 2.2 | 2,052,013 | <p>I accidentally installed pyobjc 2.2 with easy-install pyobjc, and it's causing problems: When I try to import it I get the error </p>
<pre><code>Incompatible library version: _objc.so requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0
</code></pre>
<p>I'm not interested in fixing that tho... | 3 | 2010-01-12T20:11:56Z | 2,052,357 | <p>If you are using the Apple-supplied Python 2.5 on 10.5 Leopard, which comes with PyObjC 2.0 built-in, probably the easiest way to downgrade is to remove the 2.2 version from its site-packages directory, <code>/Library/Python/2.5/site-packages</code>. First, though, run the command:</p>
<pre><code>easy_install -m p... | 1 | 2010-01-12T21:02:35Z | [
"python",
"osx",
"pyobjc",
"downgrade"
] |
Downgrading to pyobjc 2.0 from pyobjc 2.2 | 2,052,013 | <p>I accidentally installed pyobjc 2.2 with easy-install pyobjc, and it's causing problems: When I try to import it I get the error </p>
<pre><code>Incompatible library version: _objc.so requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0
</code></pre>
<p>I'm not interested in fixing that tho... | 3 | 2010-01-12T20:11:56Z | 2,061,711 | <p>I figured it out. The 2.5 pyobjc library is in /System/Library/Frameworks/Python.framework/Versions/2.5/...<br>
and the command to install pyobjc for python 2.6 is</p>
<pre><code>sudo port install py26-pyobjc2
</code></pre>
<p>Thanks anyways for the help!</p>
| 0 | 2010-01-14T01:55:53Z | [
"python",
"osx",
"pyobjc",
"downgrade"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,139 | <p>you can sort your tuples O(n log n) then create your dictionary O(n)</p>
<p>or simplier O(n) but could impose heavy load on memory in case of many tuples:</p>
<pre><code>your_dict = {}
for (a,b) in your_list:
if b in your_dict:
your_dict[b].append(a)
else:
your_dict[b]=[a]
</code></pre>
<p... | 2 | 2010-01-12T20:31:17Z | [
"python",
"list"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,176 | <p>I am not sure how you will get out of the key test, but once they key/value pair has been initialized it is easy :) </p>
<pre><code>d = {}
if 'b' not in d:
d['b'] = set()
d['b'].add('a')
</code></pre>
<p>The set will ensure that only 1 of 'a' is in the collection. You need to do the initial 'b' check though to... | 0 | 2010-01-12T20:38:33Z | [
"python",
"list"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,206 | <p>See <a href="http://docs.python.org/library/stdtypes.html#mapping-types-dict">the docs</a> for the <code>setdefault()</code> method:</p>
<blockquote>
<p>setdefault(key[, default])<br>
If key is
in the dictionary, return its value.
If not, insert key with a value of
default and return default. default
de... | 22 | 2010-01-12T20:42:56Z | [
"python",
"list"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,217 | <p>Assuming you're not really tied to lists, <a href="http://docs.python.org/library/collections.html#collections.defaultdict">defaultdict</a> and <a href="http://docs.python.org/library/stdtypes.html#set">set</a> are quite handy.</p>
<pre><code>import collections
d = collections.defaultdict(set)
for a, b in mappings:... | 12 | 2010-01-12T20:44:52Z | [
"python",
"list"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,219 | <p>Use collections.defaultdict</p>
<pre><code>your_dict = defaultdict(list)
for (a,b) in your_list:
your_dict[b].append(a)
</code></pre>
| 4 | 2010-01-12T20:44:58Z | [
"python",
"list"
] |
Efficient way to either create a list, or append to it if one already exists? | 2,052,111 | <p>I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single... | 18 | 2010-01-12T20:27:13Z | 2,052,294 | <p>Instead of using an <code>if</code>, AFAIK it is more <em>pythonic</em> to use a <code>try</code> block instead.</p>
<pre><code>your_list=[('a',1),('a',3),('b',1),('f',1),('a',2),('z',1)]
your_dict={}
for (a,b) in your_list:
try:
your_dict[b].append(a)
except KeyError:
your_dict[b]=[a]
pri... | 2 | 2010-01-12T20:54:51Z | [
"python",
"list"
] |
How to use a Django include tag for a separate HTML template? | 2,052,114 | <p>I am trying to use the <strong>include</strong> Django template tag, and inside it I reference a template which handles the format of the form. When I reference this though inside my template it outputs each of the dynamic parts, each character per new line, it is really strange. For example here is a snippet of t... | 1 | 2010-01-12T20:28:11Z | 2,052,201 | <blockquote>
<p><strong>spaceless</strong> tag</p>
<p>Removes whitespace between HTML tags. This includes tab characters and newlines.</p>
</blockquote>
| 1 | 2010-01-12T20:42:01Z | [
"python",
"django"
] |
How to use a Django include tag for a separate HTML template? | 2,052,114 | <p>I am trying to use the <strong>include</strong> Django template tag, and inside it I reference a template which handles the format of the form. When I reference this though inside my template it outputs each of the dynamic parts, each character per new line, it is really strange. For example here is a snippet of t... | 1 | 2010-01-12T20:28:11Z | 2,052,220 | <p><code>form</code> is probably a string rather than a Form object, and iterating over a string yields its individual characters.</p>
| 1 | 2010-01-12T20:45:07Z | [
"python",
"django"
] |
Threading in a django app | 2,052,237 | <p>I'm trying to create what I call a scrobbler. The task is to read a Delicious user from a queue, fetch all of their bookmarks and put them in the bookmarks queue. Then something should go through that queue, do some parsing and then store the data in a database.</p>
<p>This obviously calls for threading because mos... | 2 | 2010-01-12T20:47:21Z | 2,052,393 | <p>This calls for a task queue, though not necessarily threads. You'll have your server process, one or several scrobbler processes, and a queue that lets them communicate. The queue can be in the database, or something separate like a beanstalkd. All this has nothing to do with your error, which sounds like your datab... | 1 | 2010-01-12T21:08:15Z | [
"python",
"django",
"multithreading"
] |
Threading in a django app | 2,052,237 | <p>I'm trying to create what I call a scrobbler. The task is to read a Delicious user from a queue, fetch all of their bookmarks and put them in the bookmarks queue. Then something should go through that queue, do some parsing and then store the data in a database.</p>
<p>This obviously calls for threading because mos... | 2 | 2010-01-12T20:47:21Z | 2,055,139 | <p>1) Does the error persist if you use a real database, not SQLite?</p>
<p>2) If you're using threads, you might need to create separate SQL cursors for use in threads.</p>
| 1 | 2010-01-13T07:37:55Z | [
"python",
"django",
"multithreading"
] |
Threading in a django app | 2,052,237 | <p>I'm trying to create what I call a scrobbler. The task is to read a Delicious user from a queue, fetch all of their bookmarks and put them in the bookmarks queue. Then something should go through that queue, do some parsing and then store the data in a database.</p>
<p>This obviously calls for threading because mos... | 2 | 2010-01-12T20:47:21Z | 4,555,066 | <p>i think the table really doesn't exists yew have to create it first by SQL commad
or any other way. As i have a small database for testing different modules i just delete
the database and recreate it using syncdb command </p>
| 0 | 2010-12-29T14:45:48Z | [
"python",
"django",
"multithreading"
] |
Threading in a django app | 2,052,237 | <p>I'm trying to create what I call a scrobbler. The task is to read a Delicious user from a queue, fetch all of their bookmarks and put them in the bookmarks queue. Then something should go through that queue, do some parsing and then store the data in a database.</p>
<p>This obviously calls for threading because mos... | 2 | 2010-01-12T20:47:21Z | 6,693,251 | <p>You can not use threading with in memory databases (sqlite3 in this case) in Django see this <a href="https://code.djangoproject.com/ticket/12118" rel="nofollow">bug</a>. This might work with PostgreSQL or MySQL.</p>
<p>I'd recommend something like celeryd instead of threads, message queues are MUCH easier to work ... | 2 | 2011-07-14T12:39:20Z | [
"python",
"django",
"multithreading"
] |
How to throttle Django error emails | 2,052,284 | <p>I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute?</p>
| 10 | 2010-01-12T20:53:55Z | 2,052,495 | <p>I presume the database downtime was not intentional, in which case you probably should have put your Django process into some kind of <strong><a href="http://www.mail-archive.com/django-users@googlegroups.com/msg82963.html" rel="nofollow">maintenance mode</a></strong> or taken it offline?</p>
<p>Otherwise, the usua... | 1 | 2010-01-12T21:23:21Z | [
"python",
"django",
"error-handling",
"error-reporting"
] |
How to throttle Django error emails | 2,052,284 | <p>I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute?</p>
| 10 | 2010-01-12T20:53:55Z | 2,052,763 | <p>maybe <a href="http://nagios.sourceforge.net/docs/3_0/flapping.html" rel="nofollow">Nagios' page</a> on flapping is worth reading</p>
| 0 | 2010-01-12T21:59:40Z | [
"python",
"django",
"error-handling",
"error-reporting"
] |
How to throttle Django error emails | 2,052,284 | <p>I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute?</p>
| 10 | 2010-01-12T20:53:55Z | 2,053,920 | <p>One option is to switch to something like <a href="http://errorstack.com" rel="nofollow">ErrorStack</a> for error-reporting. I wrote a <a href="http://bitbucket.org/carljm/django-errorstack/" rel="nofollow">django app</a> to make it stupid-simple to integrate into your project.</p>
| 2 | 2010-01-13T02:07:03Z | [
"python",
"django",
"error-handling",
"error-reporting"
] |
How to throttle Django error emails | 2,052,284 | <p>I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute?</p>
| 10 | 2010-01-12T20:53:55Z | 8,997,843 | <p>I limited emails to 10 per minute by doing the following. This uses a redis connection function unique to my install. I suggest modifying the incr_counter function to suit your needs. To be safe, use a direct redis or memcache connection for this and not any django.cache wrappers. </p>
<p>settings.py</p>
<pre><cod... | 7 | 2012-01-25T04:33:01Z | [
"python",
"django",
"error-handling",
"error-reporting"
] |
How to throttle Django error emails | 2,052,284 | <p>I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute?</p>
| 10 | 2010-01-12T20:53:55Z | 25,889,167 | <p>Using Gattster's great answer as an example, I wrote a simple implementation based on django's built-in cache functions.</p>
<pre><code># -*- coding: utf-8 -*-
from django.utils.log import AdminEmailHandler
class ThrottledAdminEmailHandler(AdminEmailHandler):
PERIOD_LENGTH_IN_SECONDS = 10
MAX_EMAILS_IN_... | 7 | 2014-09-17T11:20:46Z | [
"python",
"django",
"error-handling",
"error-reporting"
] |
Updating the wx.gauge without while-loop | 2,052,369 | <p>Have been wondering about this for days now:</p>
<p>I have a basic wxpython program like this:</p>
<pre><code>from MyModule import *
class Form(wx.Panel):
def __init__(self, parent, id):
self.gauge = wx.Gauge(...)
...
def ButtonClick(self, event):
proc = LongProcess()
while (LongProcess):
... | 4 | 2010-01-12T21:04:56Z | 2,052,462 | <p>You can instantiate custom events from the non-GUI thread and wx.PostEvent them back to the GUI-thread. This is a thread-safe action. My use cases typically work like this:</p>
<ul>
<li>Start worker thread - Custom event 'Starting Action'</li>
<li>Start processing</li>
<li>Post events back updating progress 'Line ... | 7 | 2010-01-12T21:16:20Z | [
"python",
"wxpython"
] |
Manually raising (throwing) an exception in Python | 2,052,390 | <p>How can I raise an exception in Python so that it can later be caught via an <code>except</code> block?</p>
| 797 | 2010-01-12T21:07:40Z | 2,052,396 | <blockquote>
<p><strong>DON'T DO THIS</strong>. Raising a bare <code>Exception</code> is absolutely <strong>not</strong> the right thing to do; see <a href="http://stackoverflow.com/a/24065533">Aaron Hall's excellent answer</a> instead.</p>
</blockquote>
<p>Can't get much more pythonic than this:</p>
<pre><code>rai... | 567 | 2010-01-12T21:08:45Z | [
"python",
"exception",
"exception-handling"
] |
Manually raising (throwing) an exception in Python | 2,052,390 | <p>How can I raise an exception in Python so that it can later be caught via an <code>except</code> block?</p>
| 797 | 2010-01-12T21:07:40Z | 24,065,533 | <blockquote>
<h1>How do I manually throw/raise an exception in Python?</h1>
</blockquote>
<p><a href="https://docs.python.org/3/library/exceptions.html#exception-hierarchy">Use the most specific Exception constructor that semantically fits your issue</a>. </p>
<p>Be specific in your message, e.g.:</p>
<pre><code>... | 785 | 2014-06-05T16:30:58Z | [
"python",
"exception",
"exception-handling"
] |
Manually raising (throwing) an exception in Python | 2,052,390 | <p>How can I raise an exception in Python so that it can later be caught via an <code>except</code> block?</p>
| 797 | 2010-01-12T21:07:40Z | 30,317,038 | <p>For the common case where you need to throw an exception in response to some unexpected conditions, and that you never intend to catch, but simply to fail fast to enable you to debug from there if it ever happens â the most logical one seems to be <code>AssertionError</code>:</p>
<pre><code>if 0 < distance <... | 15 | 2015-05-19T04:55:14Z | [
"python",
"exception",
"exception-handling"
] |
Problem assigning input to list | 2,052,452 | <p>I know this is probably an easy question but after reviewing the documentation for python 2.6.4 I cannot seem to find out what is wrong. This is my file, in it's entirety. The problem I am having is in get_phone_number(). After asking for the amount of phone numbers, I get this error:</p>
<pre><code>Traceback (most... | 1 | 2010-01-12T21:15:03Z | 2,052,474 | <p>replace </p>
<pre><code>self.phone_number[phone_count]
</code></pre>
<p>with</p>
<pre><code>self.phone_number = []
</code></pre>
<p>The first statement does nothing (actually, it tries to access the phone_count-th element of a list called phone_number in self, which does not exist, and hence the error).</p>
<p>... | 2 | 2010-01-12T21:18:33Z | [
"python"
] |
Problem assigning input to list | 2,052,452 | <p>I know this is probably an easy question but after reviewing the documentation for python 2.6.4 I cannot seem to find out what is wrong. This is my file, in it's entirety. The problem I am having is in get_phone_number(). After asking for the amount of phone numbers, I get this error:</p>
<pre><code>Traceback (most... | 1 | 2010-01-12T21:15:03Z | 2,052,481 | <p>You need to initialise self.phone_number</p>
<pre><code> def get_phone_number(self):
count = 0
phone_count = raw_input("How many phone numbers?\n")
self.phone_number = []
while count < (phone_count - 1):
self.phone_number.append (raw_input("Phone Nu... | 0 | 2010-01-12T21:19:37Z | [
"python"
] |
Problem assigning input to list | 2,052,452 | <p>I know this is probably an easy question but after reviewing the documentation for python 2.6.4 I cannot seem to find out what is wrong. This is my file, in it's entirety. The problem I am having is in get_phone_number(). After asking for the amount of phone numbers, I get this error:</p>
<pre><code>Traceback (most... | 1 | 2010-01-12T21:15:03Z | 2,052,502 | <p>Your code contains quite a few errors and is not Pythonic. Some points: you need to convert the first user input to an integer. You can use a for loop instead of a while loop. On Python 2.5 you can use xrange instead of range but for Python 3.0 use range. Use append to add an item to a list.</p>
<pre><code>class Ph... | 1 | 2010-01-12T21:25:30Z | [
"python"
] |
Uploading files to App Engine using webapp and Django forms | 2,052,673 | <p>My basic question is this: Is there an equivalent of </p>
<pre><code>form = MyForm(request.POST, request.FILES)
</code></pre>
<p>when handling file uploads using the <code>webapp</code> framework on Google App Engine?</p>
<p>I know that I can pull out specific uploaded file data using <code>self.request.get('fie... | 1 | 2010-01-12T21:47:04Z | 2,053,692 | <p>Have a look at <a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">app-engine-patch</a>. <code>request.FILES</code> is supposed to work if you use it.</p>
<p>There is also a little snippet <a href="http://code.google.com/p/app-engine-patch/issues/detail?id=237#c1" rel="nofollow">here</a>, but I have... | 0 | 2010-01-13T01:05:37Z | [
"python",
"django",
"google-app-engine",
"forms",
"file-upload"
] |
Uploading files to App Engine using webapp and Django forms | 2,052,673 | <p>My basic question is this: Is there an equivalent of </p>
<pre><code>form = MyForm(request.POST, request.FILES)
</code></pre>
<p>when handling file uploads using the <code>webapp</code> framework on Google App Engine?</p>
<p>I know that I can pull out specific uploaded file data using <code>self.request.get('fie... | 1 | 2010-01-12T21:47:04Z | 2,058,946 | <p>Here's the solution I came up with. I added the following method to my custom <code>webapp.RequestHandler</code> subclass:</p>
<pre><code># Required imports
import cgi
from django.core.files.uploadedfile import SimpleUploadedFile
def get_uploaded_files(self):
"""Gets a dictionary mapping field names to SimpleU... | 3 | 2010-01-13T17:45:05Z | [
"python",
"django",
"google-app-engine",
"forms",
"file-upload"
] |
Uploading files to App Engine using webapp and Django forms | 2,052,673 | <p>My basic question is this: Is there an equivalent of </p>
<pre><code>form = MyForm(request.POST, request.FILES)
</code></pre>
<p>when handling file uploads using the <code>webapp</code> framework on Google App Engine?</p>
<p>I know that I can pull out specific uploaded file data using <code>self.request.get('fie... | 1 | 2010-01-12T21:47:04Z | 2,074,855 | <p><code>self.request.arguments()</code> contains all the elements that you could retrieve separately using <code>self.request.get('field_name')</code> if you knew 'field_name'.</p>
<p>Since you don't know the name of your fields in advance, you might want to loop on all of it's elements. This would work just fine if ... | 0 | 2010-01-15T21:17:16Z | [
"python",
"django",
"google-app-engine",
"forms",
"file-upload"
] |
mysql-python static linking on Linux 64-bit | 2,052,791 | <p>Has anyone tried to statically link mysql-python with mysql client library on 64-bit Linux? </p>
<pre><code>gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o /home/apy/MySQL-
python-1.2.3c1/mysql-5.1.42/i/lib/mysql/libmysqlclient_r.a -L/home/apy/MyS
QL-python-1.2.3c1/mysql-5.1.42/i/lib/mysql -lmysqlclient_r... | 1 | 2010-01-12T22:02:52Z | 2,074,303 | <ol>
<li><p>Set <code>CFLAGS="-fPIC"</code> environment variable. (<a href="http://www.x86-64.org/pipermail/discuss/2004-October/005227.html" rel="nofollow">reason</a>)</p></li>
<li><p>Pass <code>--disable-shared</code> to <code>./configure</code> (besides <code>--enable-static</code>, that is) when building mysql.</p>... | 1 | 2010-01-15T19:44:04Z | [
"python",
"mysql",
"linux",
"64bit",
"static-libraries"
] |
Python get all combinations of numbers | 2,052,951 | <p>I'm trying to display all possible combinations of a list of numbers, for example if I have 334 I want to get:</p>
<pre><code>3 3 4
3 4 3
4 3 3
</code></pre>
<p>I need to be able to do this for any set of digits up to about 12 digits long.</p>
<p>I'm sure its probably fairly simple using something like itertools.... | 4 | 2010-01-12T22:31:52Z | 2,052,979 | <p>You want permutations, not combinations. See: <a href="http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python">http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python</a></p>
<pre><code>>>> from itertools import permutations
>... | 2 | 2010-01-12T22:36:12Z | [
"python",
"combinations"
] |
Python get all combinations of numbers | 2,052,951 | <p>I'm trying to display all possible combinations of a list of numbers, for example if I have 334 I want to get:</p>
<pre><code>3 3 4
3 4 3
4 3 3
</code></pre>
<p>I need to be able to do this for any set of digits up to about 12 digits long.</p>
<p>I'm sure its probably fairly simple using something like itertools.... | 4 | 2010-01-12T22:31:52Z | 2,052,981 | <pre><code>>>> lst = [3, 3, 4]
>>> import itertools
>>> set(itertools.permutations(lst))
{(3, 4, 3), (3, 3, 4), (4, 3, 3)}
</code></pre>
| 20 | 2010-01-12T22:36:27Z | [
"python",
"combinations"
] |
Python get all combinations of numbers | 2,052,951 | <p>I'm trying to display all possible combinations of a list of numbers, for example if I have 334 I want to get:</p>
<pre><code>3 3 4
3 4 3
4 3 3
</code></pre>
<p>I need to be able to do this for any set of digits up to about 12 digits long.</p>
<p>I'm sure its probably fairly simple using something like itertools.... | 4 | 2010-01-12T22:31:52Z | 2,053,846 | <p>without itertools</p>
<pre><code>def permute(LIST):
length=len(LIST)
if length <= 1:
yield LIST
else:
for n in range(0,length):
for end in permute( LIST[:n] + LIST[n+1:] ):
yield [ LIST[n] ] + end
for x in permute(["3","3","4"]):
print x
</code></pre... | 3 | 2010-01-13T01:44:11Z | [
"python",
"combinations"
] |
Python get all combinations of numbers | 2,052,951 | <p>I'm trying to display all possible combinations of a list of numbers, for example if I have 334 I want to get:</p>
<pre><code>3 3 4
3 4 3
4 3 3
</code></pre>
<p>I need to be able to do this for any set of digits up to about 12 digits long.</p>
<p>I'm sure its probably fairly simple using something like itertools.... | 4 | 2010-01-12T22:31:52Z | 20,938,494 | <p>I'd use python's <code>itertools</code>, but if you had to implement this yourself, here's code that returns all permutations of a specified size for a list of values.</p>
<p>Example: <code>values = [1,2,3]</code>, <code>size = 2</code> => <code>[[3, 2], [2, 3], [2, 1], [3, 1], [1, 3], [1, 2]]</code></p>
<pre><cod... | 1 | 2014-01-05T20:05:10Z | [
"python",
"combinations"
] |
Opening different windows in wxPython using strings from a list | 2,053,009 | <p>I have a list of file locations stored as strings. I want to be able to open a separate window for all of the different strings. What would be the best way to do that? Essentially, You click a button, the strings are constructed and they are left in a list. When I was prototyping, I built a small program to display ... | 0 | 2010-01-12T22:39:42Z | 2,053,186 | <pre><code>for s in mystrings:
open_window_for_string(s)
</code></pre>
<p>I'm sure you can supply a definition for <code>open_window_for_string</code> if you know how to open a window with the contents of a file...</p>
<p>Also, it doesn't actually have to be a function of one argument, of course, define it to acc... | 0 | 2010-01-12T23:14:37Z | [
"python",
"list",
"wxpython",
"iteration"
] |
Is the order of a Python dictionary guaranteed over iterations? | 2,053,021 | <p>I'm currently implementing a complex microbial food-web in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html">SciPy.integrate.ode</a>. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks s... | 14 | 2010-01-12T22:42:01Z | 2,053,036 | <p>Yes, the same order is guaranteed if it is not modified.</p>
<p>See the docs <a href="https://docs.python.org/2/library/stdtypes.html#dict.items" rel="nofollow">here</a>.</p>
<p><strong>Edit:</strong></p>
<p>Regarding if changing the value (but not adding/removing a key) will affect the order, this is what the co... | 31 | 2010-01-12T22:43:49Z | [
"python",
"dictionary",
"numpy",
"scipy",
"scientific-computing"
] |
Is the order of a Python dictionary guaranteed over iterations? | 2,053,021 | <p>I'm currently implementing a complex microbial food-web in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html">SciPy.integrate.ode</a>. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks s... | 14 | 2010-01-12T22:42:01Z | 2,053,052 | <p>Provided <em>no</em> modifications are made to the dictionary, the answer is yes. <a href="https://docs.python.org/2/library/stdtypes.html#dict.items" rel="nofollow">See the docs here</a>.</p>
<p>However, dictionaries are unordered by nature in Python. In general, it's not the best practice to rely on dictionaries ... | 8 | 2010-01-12T22:49:02Z | [
"python",
"dictionary",
"numpy",
"scipy",
"scientific-computing"
] |
Is the order of a Python dictionary guaranteed over iterations? | 2,053,021 | <p>I'm currently implementing a complex microbial food-web in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html">SciPy.integrate.ode</a>. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks s... | 14 | 2010-01-12T22:42:01Z | 2,053,055 | <p>If you want the order to be consistent, I would do something to force a particular order. Although you might be able to convince yourself that the order is guaranteed, and you might be right, it seems fragile to me, and it will be mysterious to other developers.</p>
<p>For example, you emphasize <em>always</em> in... | 5 | 2010-01-12T22:49:12Z | [
"python",
"dictionary",
"numpy",
"scipy",
"scientific-computing"
] |
Is the order of a Python dictionary guaranteed over iterations? | 2,053,021 | <p>I'm currently implementing a complex microbial food-web in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html">SciPy.integrate.ode</a>. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks s... | 14 | 2010-01-12T22:42:01Z | 2,053,086 | <p>I also would recommend not relying on the fact the dictionaries order is non-random.</p>
<p>If you want a built in solution to sorting you dictionary read <a href="http://www.python.org/dev/peps/pep-0265/">http://www.python.org/dev/peps/pep-0265/</a></p>
<p>Here is the most relevant material:</p>
<p>This PEP is r... | 5 | 2010-01-12T22:54:33Z | [
"python",
"dictionary",
"numpy",
"scipy",
"scientific-computing"
] |
Is the order of a Python dictionary guaranteed over iterations? | 2,053,021 | <p>I'm currently implementing a complex microbial food-web in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html">SciPy.integrate.ode</a>. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks s... | 14 | 2010-01-12T22:42:01Z | 2,054,655 | <p>Python 3.1 has a <a href="http://docs.python.org/3.1/library/collections#collections.OrderedDict" rel="nofollow">collections.OrderedDict</a> class that can be used for this purpose. It's very efficient, too: "Big-O running times for all methods are the same as for regular dictionaries."</p>
<p>The <a href="http://s... | 3 | 2010-01-13T05:30:13Z | [
"python",
"dictionary",
"numpy",
"scipy",
"scientific-computing"
] |
Grabbing the output of MAPLE via Python | 2,053,231 | <p>How would I use the subprocess module in Python to start a command line instance of MAPLE to feed and return output to the main code? For example I'd like:</p>
<pre><code>X = '1+1;'
print MAPLE(X)
</code></pre>
<p>To return the value of "2".</p>
<p>The best I've seen is a SAGE wrapper around the MAPLE commands, b... | 3 | 2010-01-12T23:25:46Z | 2,054,301 | <p>Trying to drive a subprocess "interactively" more often than not runs into issues with the subprocess doing some buffering, which blocks things.</p>
<p>That's why for such purposes I suggest instead using <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">pexpect</a> (everywhere but Windows: <a href="http://... | 3 | 2010-01-13T04:01:04Z | [
"python",
"subprocess",
"pexpect",
"maple"
] |
Grabbing the output of MAPLE via Python | 2,053,231 | <p>How would I use the subprocess module in Python to start a command line instance of MAPLE to feed and return output to the main code? For example I'd like:</p>
<pre><code>X = '1+1;'
print MAPLE(X)
</code></pre>
<p>To return the value of "2".</p>
<p>The best I've seen is a SAGE wrapper around the MAPLE commands, b... | 3 | 2010-01-12T23:25:46Z | 2,059,048 | <p>Here's an example of how to do interactive IO with a command line program. I used something similar to build a spell checker based on the <code>ispell</code> command line utility:</p>
<pre><code>f = popen2.Popen3("ispell -a")
f.fromchild.readline() #skip the credit line
for word in words:
f.tochild.write(word+... | 0 | 2010-01-13T18:02:57Z | [
"python",
"subprocess",
"pexpect",
"maple"
] |
Grabbing the output of MAPLE via Python | 2,053,231 | <p>How would I use the subprocess module in Python to start a command line instance of MAPLE to feed and return output to the main code? For example I'd like:</p>
<pre><code>X = '1+1;'
print MAPLE(X)
</code></pre>
<p>To return the value of "2".</p>
<p>The best I've seen is a SAGE wrapper around the MAPLE commands, b... | 3 | 2010-01-12T23:25:46Z | 2,059,211 | <p>Using the tip from Alex Martelli (thank you!), I've came up with an explicit answer to my question. Posting here in hopes that others may find useful:</p>
<pre><code>import pexpect
MW = "/usr/local/maple12/bin/maple -tu"
X = '1+1;'
child = pexpect.spawn(MW)
child.expect('#--')
child.sendline(X)
child.expect('#--')
... | 3 | 2010-01-13T18:29:46Z | [
"python",
"subprocess",
"pexpect",
"maple"
] |
GNOME applet using threads hangs | 2,053,241 | <p>I am trying to develop a GNOME applet (put into panel) using python (pyGTK). I've started by following the <a href="http://stackoverflow.com/questions/2034834/whats-the-newest-way-to-develop-gnome-panel-applets-using-python/2034947#2034947">tutorial suggested in other SO question</a>. </p>
<p>My plan is to let the ... | 2 | 2010-01-12T23:27:29Z | 2,054,068 | <p>According to several comments on the gtk lists, you shouldn't be trying to update your user interface from threads. It would be better to poll the child threads from your main application. For references see <a href="http://mail.gnome.org/archives/gtk-list/2009-December/msg00137.html" rel="nofollow">here</a> and <a ... | 2 | 2010-01-13T02:56:23Z | [
"python",
"multithreading",
"gtk",
"pygtk",
"gnome"
] |
GNOME applet using threads hangs | 2,053,241 | <p>I am trying to develop a GNOME applet (put into panel) using python (pyGTK). I've started by following the <a href="http://stackoverflow.com/questions/2034834/whats-the-newest-way-to-develop-gnome-panel-applets-using-python/2034947#2034947">tutorial suggested in other SO question</a>. </p>
<p>My plan is to let the ... | 2 | 2010-01-12T23:27:29Z | 20,080,093 | <p>It might be too late for answering, but anyway hope this helps anyone jumped on this page.</p>
<p><a href="http://faq.pygtk.org/index.py?file=faq20.006.htp&req=show" rel="nofollow">http://faq.pygtk.org/index.py?file=faq20.006.htp&req=show</a></p>
| 0 | 2013-11-19T19:14:21Z | [
"python",
"multithreading",
"gtk",
"pygtk",
"gnome"
] |
how to create 2d array in python if we know number of rows,and number of columns depends on some condition? | 2,053,387 | <p>My array maximum dimension could be 2x27,but number of columns could be lower than 27.Number of columns depends on some condition.Is good solution to initialize array 2x27 and then delete unnecessary columns or has more elegant way to do this?</p>
| 2 | 2010-01-12T23:53:54Z | 2,053,400 | <p>For so few elements use a dictionary, with tuples as keys:</p>
<pre><code>dct = {}
dct[(0,0)] = 'X'
if (10,10) in dct:
dct[(10,10)] += 1
else:
dct[(10,10] = 0
# Deleting a row / column
dct.pop((10,0))
dct.pop((10,1))
...
dct.pop((10,10))
</code></pre>
<p>Dictionaries are very flexible.</p>
<p>Alternativel... | 1 | 2010-01-12T23:56:44Z | [
"python"
] |
how to create 2d array in python if we know number of rows,and number of columns depends on some condition? | 2,053,387 | <p>My array maximum dimension could be 2x27,but number of columns could be lower than 27.Number of columns depends on some condition.Is good solution to initialize array 2x27 and then delete unnecessary columns or has more elegant way to do this?</p>
| 2 | 2010-01-12T23:53:54Z | 2,053,417 | <p>Check this <a href="http://www.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93" rel="nofollow">link</a> about Numpy Array. This page has some simple examples of use.</p>
| 0 | 2010-01-13T00:01:13Z | [
"python"
] |
how to create 2d array in python if we know number of rows,and number of columns depends on some condition? | 2,053,387 | <p>My array maximum dimension could be 2x27,but number of columns could be lower than 27.Number of columns depends on some condition.Is good solution to initialize array 2x27 and then delete unnecessary columns or has more elegant way to do this?</p>
| 2 | 2010-01-12T23:53:54Z | 2,053,515 | <p>Here is a simple way to handle it:</p>
<pre><code>num_rows, num_cols = 2, 27
table = []
for r in range(num_rows):
row = []
table.append(row)
for c in range(num_cols):
row.append(c)
print table
</code></pre>
| 1 | 2010-01-13T00:25:12Z | [
"python"
] |
how to create 2d array in python if we know number of rows,and number of columns depends on some condition? | 2,053,387 | <p>My array maximum dimension could be 2x27,but number of columns could be lower than 27.Number of columns depends on some condition.Is good solution to initialize array 2x27 and then delete unnecessary columns or has more elegant way to do this?</p>
| 2 | 2010-01-12T23:53:54Z | 2,054,280 | <p>No, it makes no particular sense to build a larger array then remove some part of it -- just build what you need. Assuming that by "2d array" you actually mean "list of lists":</p>
<pre><code>def makarray(value, nrows, ncols):
return [[value]*ncols for _ in range(nrows)]
</code></pre>
| 3 | 2010-01-13T03:56:21Z | [
"python"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,502 | <pre><code>def colorRedAndTimeNotEqualTo2(thelist):
for i in thelist:
if i["color"] == "red" and i["time"] != 2:
return True
return False
print colorRedAndTimeNotEqualTo2([{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}])
</code></pre>
<p>for i in thelist it... | 1 | 2010-01-13T00:22:31Z | [
"python",
"list"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,513 | <p>You can do most of the list manipulation in a list comprehension. Here's one that makes a list of times for all elements where the color is red. Then you can ask if 2 exists in those times. </p>
<pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
reds = ( x['tim... | 0 | 2010-01-13T00:24:42Z | [
"python",
"list"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,520 | <p>Well, there's nothing as elegant as "find" but you can use a list comprehension:</p>
<pre><code>matches = [x for x in thelist if x["color"] == "red" and x["time"] != 2]
if len(matches):
m = matches[0]
# do something with m
</code></pre>
<p>However, I find the <code>[0]</code> and len() tedious. I often use... | 0 | 2010-01-13T00:25:41Z | [
"python",
"list"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,522 | <pre><code>list = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
for i in list:
if i['color'] == 'red' && i['time'] != 2:
print i
</code></pre>
| 0 | 2010-01-13T00:25:59Z | [
"python",
"list"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,527 | <pre><code>for val in thelist:
if val['color'] == 'red' and val['time'] != 2:
#do something here
</code></pre>
<p>But it doesn't look like that's the right data structure to use.</p>
| 0 | 2010-01-13T00:27:17Z | [
"python",
"list"
] |
How do I determine if an element is in a list? | 2,053,492 | <pre><code>thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
</code></pre>
<p>How do I say:</p>
<pre><code>If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
</code></pre>
| 1 | 2010-01-13T00:19:26Z | 2,053,564 | <p>Using <a href="http://docs.python.org/library/functions.html#any"><code>any()</code></a> to find out if there is an element satisfying the conditions:</p>
<pre><code>>>> any(item['color'] == 'red' and item['time'] != 2 for item in thelist)
False
</code></pre>
| 13 | 2010-01-13T00:33:42Z | [
"python",
"list"
] |
Git-diff to HTML | 2,053,657 | <p>I'm looking for a way to produce HTML files from a git-diff output, preferably using python. I've been looking at <a href="http://docs.python.org/library/difflib.html">http://docs.python.org/library/difflib.html</a> without being able to figure out how to use the git-diff output as an input.</p>
<p>Any clue?</p>
<... | 5 | 2010-01-13T00:56:03Z | 2,058,104 | <p>You could use the <a href="http://pygments.org/docs/cmdline/" rel="nofollow">pygments</a> commandline script to get a syntax highligthed HTML output. </p>
<p>Installation: </p>
<pre><code>$ easy_install Pygments
</code></pre>
<p>Example:</p>
<pre><code>$ git diff HEAD^1 > last.diff
$ pygmentize -f html -O ful... | 8 | 2010-01-13T16:01:14Z | [
"python",
"html",
"git",
"diff"
] |
Git-diff to HTML | 2,053,657 | <p>I'm looking for a way to produce HTML files from a git-diff output, preferably using python. I've been looking at <a href="http://docs.python.org/library/difflib.html">http://docs.python.org/library/difflib.html</a> without being able to figure out how to use the git-diff output as an input.</p>
<p>Any clue?</p>
<... | 5 | 2010-01-13T00:56:03Z | 17,555,754 | <p>Perhaps <em><a href="https://github.com/wspringer/difr" rel="nofollow">difr</a></em> is you what you're looking for. It takes any kind git style diff as an input and produces an HTML version of it that is pretty to similar to what GitHub would give you. (And it embeds an editor for adding some small comments. That m... | 1 | 2013-07-09T18:40:26Z | [
"python",
"html",
"git",
"diff"
] |
Git-diff to HTML | 2,053,657 | <p>I'm looking for a way to produce HTML files from a git-diff output, preferably using python. I've been looking at <a href="http://docs.python.org/library/difflib.html">http://docs.python.org/library/difflib.html</a> without being able to figure out how to use the git-diff output as an input.</p>
<p>Any clue?</p>
<... | 5 | 2010-01-13T00:56:03Z | 30,436,124 | <p>I wrote a simple implementation for my <a href="https://pypi.python.org/pypi/maildiff/1.1.1" rel="nofollow">maildiff</a></p>
<pre><code>def getHtml(diffData):
""" This method convertes git diff data to html color code
"""
openTag = "<span style='font-size: .80em; color: "
openTagEnd = ";font-fami... | 1 | 2015-05-25T10:22:51Z | [
"python",
"html",
"git",
"diff"
] |
Watch over another process (svn) | 2,053,857 | <p>I have a python script to download source code from a list of repositories, some of them are big. </p>
<p>Sometimes, svn hangs in the middle of a check out. Is there a way to watch over svn process, and so I know it is hang or not?</p>
| 1 | 2010-01-13T01:47:14Z | 2,053,963 | <p>You can use <a href="http://pysvn.tigris.org/docs/pysvn_prog_ref.html" rel="nofollow">PySVN</a>, and register a callback for each "event" processes. PySVN can also poll a "cancel" callback. The first callback could start a timer, and if the timer expires, you can do tell the "cancel" callback to return False, thus c... | 1 | 2010-01-13T02:25:21Z | [
"python",
"svn",
"multiprocessing"
] |
Watch over another process (svn) | 2,053,857 | <p>I have a python script to download source code from a list of repositories, some of them are big. </p>
<p>Sometimes, svn hangs in the middle of a check out. Is there a way to watch over svn process, and so I know it is hang or not?</p>
| 1 | 2010-01-13T01:47:14Z | 2,053,972 | <p>You can keep polling the stdout of the svn process, and test how often you get new files. If you don't get a new file within x seconds, bounce the process.</p>
<p>Launch svn using subprocess from within your master script, and poll stdout while waiting for the process to complete.</p>
| 0 | 2010-01-13T02:26:53Z | [
"python",
"svn",
"multiprocessing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,950 | <p>you can use startswith</p>
<p>eg</p>
<pre><code>myword = "lock"
if myword.startswith("lo"):
print "ok"
</code></pre>
<p>or if you want to find "lo" in the word, regardless of position, just use the "in" operator</p>
<pre><code>if "lo" in myword
</code></pre>
<p>therefore, one way you can do this:</p>
<pre><... | 2 | 2010-01-13T02:17:17Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,954 | <p>If you are accepting input from a user, then why are you worried about the speed of comparison? Even the slowest technique will be far faster than the user can perceive. Use the simplest most understandable code you can, and leave efficiency concerns for tight inner loops.</p>
<pre><code>cmds = [
"lock",
... | 15 | 2010-01-13T02:21:42Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,969 | <p><code>jaro_winkler()</code> in <a href="http://www.michael-noll.com/wiki/Python-Levenshtein" rel="nofollow">python-Levenshtein</a> might be what you're looking for.</p>
| 1 | 2010-01-13T02:26:02Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,974 | <p>This will do what you want:</p>
<pre><code>def select_command(commands, user_input):
user_input = user_input.strip().lower()
for command in commands:
if command.startswith(user_input):
return command
return None
</code></pre>
<p><strong>However:</strong></p>
<p>You seem overworried... | 5 | 2010-01-13T02:27:47Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,976 | <p>Replace with your favorite string compare function. Fairly fast, and to the point.</p>
<pre><code>matches = ( x for x in list if x[:len(stringToSearchFor)] == stringToSearchFor )
print matches[0]
</code></pre>
| 0 | 2010-01-13T02:28:06Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,053,985 | <p>I suggest you look at using the readline python library, rather than reinventing the wheel.
The user will have to hit tab to complete the word, but you can set readline up so that tab matches as far as possible or cycles through all words starting wit the current stub.</p>
<p>This seems to be a fairly decent introd... | 2 | 2010-01-13T02:30:03Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,054,009 | <p>This is adapted from <a href="http://jtauber.com/blog/2005/02/10/updated_python_trie_implementation/" rel="nofollow">J.Tauber's Trie implementation in Python</a>, which you could compare and/or re-adapt with whatever extra features you need. See also the <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">Wi... | 0 | 2010-01-13T02:37:10Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,054,011 | <p>If i understand your Q correctly, you want a snippet that will return the answer as soon as it has it, without traversing further through your 'command list.' This should do what you want:</p>
<pre><code>from itertools import ifilter
def check_input(some_string, code_book) :
for q in ifilter(code_book.__contai... | 0 | 2010-01-13T02:38:46Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,054,035 | <p><strong>This is optimized at runtime like you requested...</strong> (although most likely not needed)</p>
<p>Here is a simple bit of code which will take an input dictionary of command mapped to function, and results in an output dictionary of all non-duplicate sub commands mapped to the same function.</p>
<p>So y... | 3 | 2010-01-13T02:47:08Z | [
"python",
"regex",
"parsing"
] |
fastest way to compare strings in python | 2,053,937 | <p>I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is:</p>
<pre><code>lock
read
write
request
log
</code></pre>
<p>Now, I want the user to be able to enter the... | 7 | 2010-01-13T02:11:49Z | 2,054,081 | <pre><code>import timeit
cmds = []
for i in range(1,10000):
cmds.append("test")
def get_cmds(user_input):
return [c for c in cmds if c.startswith(user_input)]
if __name__=='__main__':
t = timeit.Timer("get_cmds('te')", "from __main__ import get_cmds")
print "%0.3f seconds" % (t.timeit(number=1))
#&g... | 0 | 2010-01-13T02:59:46Z | [
"python",
"regex",
"parsing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.