title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How to dynamically compose an OR query filter in Django? | 852,414 | <p>From an example you can see a multiple OR query filter:</p>
<pre><code>Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
</code></pre>
<p>For example, this results in:</p>
<pre><code>[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
</code></pre>
<p>However, I want to creat... | 45 | 2009-05-12T12:08:51Z | 39,164,442 | <p>Another option I wasn't aware of until recently - <code>QuerySet</code> also overrides the <code>&</code>, <code>|</code>, <code>~</code>, etc, operators. The other answers that OR Q objects are a better solution to this question, but for the sake of interest/argument, you can do:</p>
<pre><code>id_list = [1, 2... | 0 | 2016-08-26T10:45:46Z | [
"python",
"django",
"django-q"
] |
Reverse proxy capable pure python webserver? | 852,541 | <p>I am looking for a pure python based web server has the capability for reverse proxy as well? </p>
| 1 | 2009-05-12T12:37:00Z | 852,635 | <p>pretty sure you can do that with twisted,</p>
<p><a href="http://twistedmatrix.com/trac/wiki/TwistedWeb" rel="nofollow">twisted web</a></p>
<p>but why not just use apache?</p>
| 2 | 2009-05-12T12:56:03Z | [
"python",
"proxy",
"webserver",
"reverse"
] |
Reverse proxy capable pure python webserver? | 852,690 | <p>I am looking for a pure python based web server has the capability for reverse proxy as well? </p>
| 3 | 2009-05-12T13:09:52Z | 852,749 | <p>Have a look at <a href="http://twistedmatrix.com/" rel="nofollow">Twisted</a>, especially its <a href="http://twistedmatrix.com/documents/current/api/twisted.web.proxy.ReverseProxyResource.html" rel="nofollow">ReverseProxyResource</a>.</p>
<blockquote>
<p>Twisted Web also provides various facilities for being set... | 3 | 2009-05-12T13:21:18Z | [
"python",
"proxy",
"webserver",
"reverse"
] |
Reverse proxy capable pure python webserver? | 852,690 | <p>I am looking for a pure python based web server has the capability for reverse proxy as well? </p>
| 3 | 2009-05-12T13:09:52Z | 852,857 | <p><a href="http://pypi.python.org/pypi/proxylet/" rel="nofollow">http://pypi.python.org/pypi/proxylet/</a></p>
<p>From <a href="http://www.rfk.id.au/blog/entry/proxylet-lightweight-HTTP-reverse-proxy" rel="nofollow">http://www.rfk.id.au/blog/entry/proxylet-lightweight-HTTP-reverse-proxy</a></p>
<blockquote>
<p>pro... | 0 | 2009-05-12T13:39:41Z | [
"python",
"proxy",
"webserver",
"reverse"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 853,036 | <pre><code>def get_positions(xs, target):
return [(i,e.index(target)) for i,e in enumerate(xs)]
</code></pre>
<p>That's a good starting point. Presumably you have some sort of class such as</p>
<pre><code>class SomeClass:
def __init__(self):
self.xs = [['1','2','4','6'], ['7','0','1','4']]
def g... | 2 | 2009-05-12T14:21:07Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 853,055 | <p>It looks likes you want, for a list of sublists and a given item, to return a list of pairs where each pair is (the index of the sublist, the index of the item within the sublist). You can do that using <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensio... | 5 | 2009-05-12T14:23:36Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 853,189 | <p>If you don't want a exception if the item is not in the list try this. Also as a generator because they are cool and versatile.</p>
<pre><code>xs = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
def get_positions(xs, item):
for i, xt in enumerate( xs ):
try: # trying beats checking
yield (i, x... | 2 | 2009-05-12T14:51:49Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 853,335 | <p>If you want something that will both </p>
<ul>
<li>find duplicates and </li>
<li>handle nested lists (lists of lists of lists of ...)</li>
</ul>
<p>you can do something like the following:</p>
<pre><code>def get_positions(xs, item):
if isinstance(xs, list):
for i, it in enumerate(xs):
for ... | 7 | 2009-05-12T15:19:58Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 853,427 | <p>A while ago I wrote a library for python to do list matching that would fit the bill pretty well. It used the tokens ?, +, and * as wildcards, where ? signifies a single atom, + is a non-greedy one-or-more, and * is greedy one-or-more. For example:</p>
<pre><code>from matching import match
match(['?', 2, 3, '*'],... | 0 | 2009-05-12T15:39:48Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 855,402 | <p>Here is a version without try..except, returning an iterator and that for</p>
<pre><code>[['1', '1', '1', '1'], ['7', '0', '4']]
</code></pre>
<p>returns </p>
<pre><code>[(0, 0), (0, 1), (0, 2), (0, 3)]
def getPosition1(l, val):
for row_nb, r in enumerate(l):
for col_nb in (x for x in xrange(len(r)) if... | 0 | 2009-05-12T23:26:22Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 855,669 | <p>The most strainghtforward and probably the slowest way to do it would be:</p>
<pre><code> >>> value = '1'
>>> l = [['1', '2', '3', '4'], ['3', '4', '5', '1']]
>>> m = []
>>> for i in range(len(l)):
... for j in range(len(l[i])):
... if l[i][j] == value:
... | 0 | 2009-05-13T01:29:19Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 855,811 | <p>Here is another straight forward method that doesn't use generators.</p>
<pre><code>def getPosition(lists,item):
positions = []
for i,li in enumerate(lists):
j = -1
try:
while True:
j = li.index(item,j+1)
positions.append((i,j))
except Valu... | 0 | 2009-05-13T02:39:12Z | [
"python"
] |
How can I find the locations of an item in a Python list of lists? | 853,023 | <p>I want to find the location(s) of a specific item in a list of lists. It should return a list of tuples, where each tuple represents the indexes for a specific instance of the item. For example:</p>
<pre><code>list = [['1', '2', '4', '6'], ['7', '0', '1', '4']]
getPosition('1') #returns [(0, 0), (1, 2)]
and getP... | 5 | 2009-05-12T14:18:36Z | 861,107 | <pre><code>def getPosition(list, item):
return [(i, sublist.index(item)) for i, sublist in enumerate(list)
if item in sublist]
</code></pre>
| 3 | 2009-05-14T00:55:28Z | [
"python"
] |
Django ORM: Selecting related set | 853,184 | <p>Say I have 2 models:</p>
<pre><code>class Poll(models.Model):
category = models.CharField(u"Category", max_length = 64)
[...]
class Choice(models.Model):
poll = models.ForeignKey(Poll)
[...]
</code></pre>
<p>Given a Poll object, I can query its choices with:</p>
<pre><code>poll.choice_set.all()
<... | 11 | 2009-05-12T14:50:25Z | 853,228 | <p>I think what you're saying is, "I want all Choices for a set of Polls." If so, try this:</p>
<pre><code>polls = Poll.objects.filter(category='foo')
choices = Choice.objects.filter(poll__in=polls)
</code></pre>
| 12 | 2009-05-12T15:00:07Z | [
"python",
"django",
"orm"
] |
Django ORM: Selecting related set | 853,184 | <p>Say I have 2 models:</p>
<pre><code>class Poll(models.Model):
category = models.CharField(u"Category", max_length = 64)
[...]
class Choice(models.Model):
poll = models.ForeignKey(Poll)
[...]
</code></pre>
<p>Given a Poll object, I can query its choices with:</p>
<pre><code>poll.choice_set.all()
<... | 11 | 2009-05-12T14:50:25Z | 853,397 | <p>I think what you are trying to do is the term "eager loading" of child data - meaning you are loading the child list (choice_set) for each Poll, but all in the first query to the DB, so that you don't have to make a bunch of queries later on. </p>
<p>If this is correct, then what you are looking for is 'select_rela... | 1 | 2009-05-12T15:34:56Z | [
"python",
"django",
"orm"
] |
Django ORM: Selecting related set | 853,184 | <p>Say I have 2 models:</p>
<pre><code>class Poll(models.Model):
category = models.CharField(u"Category", max_length = 64)
[...]
class Choice(models.Model):
poll = models.ForeignKey(Poll)
[...]
</code></pre>
<p>Given a Poll object, I can query its choices with:</p>
<pre><code>poll.choice_set.all()
<... | 11 | 2009-05-12T14:50:25Z | 854,077 | <p><strong>Update</strong>: Since Django 1.4, this feature is built in: see <a href="https://docs.djangoproject.com/en/stable/ref/models/querysets/#prefetch-related" rel="nofollow">prefetch_related</a>.</p>
<p>First answer: don't waste time writing something like qbind until you've already written a working applicatio... | 10 | 2009-05-12T18:11:29Z | [
"python",
"django",
"orm"
] |
Django ORM: Selecting related set | 853,184 | <p>Say I have 2 models:</p>
<pre><code>class Poll(models.Model):
category = models.CharField(u"Category", max_length = 64)
[...]
class Choice(models.Model):
poll = models.ForeignKey(Poll)
[...]
</code></pre>
<p>Given a Poll object, I can query its choices with:</p>
<pre><code>poll.choice_set.all()
<... | 11 | 2009-05-12T14:50:25Z | 11,374,381 | <p>Time has passed and this functionality is now available in Django 1.4 with the introduction of the <a href="https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related">prefetch_related()</a> QuerySet function. This function effectively does what is performed by the suggested <code>qbind</code> fun... | 15 | 2012-07-07T10:56:21Z | [
"python",
"django",
"orm"
] |
How can you migrate Django models similar to Ruby on Rails migrations? | 853,248 | <p>Django has a number of open source projects that tackle one of the framework's more notable <a href="http://code.djangoproject.com/wiki/SchemaEvolution">missing features</a>: model "evolution". Ruby on Rails has native support for <a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html">migrations</... | 5 | 2009-05-12T15:04:24Z | 853,468 | <p>South has the most steam behind it. dmigrations is too basic IMO. django-evolution screams if you ever touch the db outside of it.</p>
<p>South is the strongest contender by far. With the model freezing and auto-migrations it's come a long way.</p>
| 10 | 2009-05-12T15:46:14Z | [
"python",
"django",
"migration"
] |
How can you migrate Django models similar to Ruby on Rails migrations? | 853,248 | <p>Django has a number of open source projects that tackle one of the framework's more notable <a href="http://code.djangoproject.com/wiki/SchemaEvolution">missing features</a>: model "evolution". Ruby on Rails has native support for <a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html">migrations</... | 5 | 2009-05-12T15:04:24Z | 854,022 | <p>South and django-evolution are certainly the best options. South's model-freezing and auto-hinting are still quite fragile in my experience (django-evolution's hinting is much more robust in edge cases), but django-evolution's development seems to have mostly stalled since last summer. If I were starting now I'd p... | 5 | 2009-05-12T18:00:30Z | [
"python",
"django",
"migration"
] |
How can you migrate Django models similar to Ruby on Rails migrations? | 853,248 | <p>Django has a number of open source projects that tackle one of the framework's more notable <a href="http://code.djangoproject.com/wiki/SchemaEvolution">missing features</a>: model "evolution". Ruby on Rails has native support for <a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html">migrations</... | 5 | 2009-05-12T15:04:24Z | 854,059 | <p>I'm a member of the team that developed dmigrations - but I would wholeheartedly recommend South. It's much more mature, is under active development, and has some killer features like ORM freezing (if you try to use ORM code in dmigrations, then change your models, you're in for a world of pain).</p>
| 1 | 2009-05-12T18:08:12Z | [
"python",
"django",
"migration"
] |
How can you migrate Django models similar to Ruby on Rails migrations? | 853,248 | <p>Django has a number of open source projects that tackle one of the framework's more notable <a href="http://code.djangoproject.com/wiki/SchemaEvolution">missing features</a>: model "evolution". Ruby on Rails has native support for <a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html">migrations</... | 5 | 2009-05-12T15:04:24Z | 1,898,037 | <p>After reading this, I went from 'knowing nothing about data model evolution' to 'using south to manage model migration' in less than 1 hour. South's documentation is outstanding and got me up to speed in record time. Not having looked at the other tools mentioned, I fully recommend it.</p>
<p>Update: Since posting ... | 1 | 2009-12-13T22:28:40Z | [
"python",
"django",
"migration"
] |
Which open-source Python or Java library provides an easy way to draw circles on a ESRI Shapefile? | 853,311 | <p>I need to write a software that creates an shapefile with various circles or circumferences on it.
The shapefile created should be readable by ESRI ArcMap.</p>
<p>I need a library that let me add circles or circular arc to it.</p>
<p>The library could be in for Python or in Java. </p>
| 2 | 2009-05-12T15:15:35Z | 853,382 | <p>If you look at <a href="http://openmap.bbn.com/" rel="nofollow">OpenMap</a>, it may be possible to write some code using that set of libraries in Java to do what you are asking.</p>
<p>I don't know if its possible from a single call, but there is definitely code in OpenMap to <a href="http://openmap.bbn.com/doc/api... | 1 | 2009-05-12T15:31:04Z | [
"java",
"python",
"arcgis",
"shapefile",
"esri"
] |
Which open-source Python or Java library provides an easy way to draw circles on a ESRI Shapefile? | 853,311 | <p>I need to write a software that creates an shapefile with various circles or circumferences on it.
The shapefile created should be readable by ESRI ArcMap.</p>
<p>I need a library that let me add circles or circular arc to it.</p>
<p>The library could be in for Python or in Java. </p>
| 2 | 2009-05-12T15:15:35Z | 3,366,881 | <p>Matt Perry has a short and sweet example of creating circles in a shapefile in <a href="http://www.perrygeo.net/wordpress/?p=4" rel="nofollow">Tissot Indicatrix - Examining the distortion of map projections</a>. Not listed in the post is how to install the prerequiste gdal/ogr; for that see <a href="http://trac.osge... | 0 | 2010-07-29T20:58:36Z | [
"java",
"python",
"arcgis",
"shapefile",
"esri"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 853,424 | <p>How about <a href="http://code.google.com/p/pyodbc/">pyodbc</a>? <a href="http://stackoverflow.com/questions/827502/pyodbc-and-microsoft-access-inconsistent-results-from-simple-query">This SO question</a> demonstrates it's possible to read MS Access using it.</p>
| 10 | 2009-05-12T15:39:23Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 853,762 | <p>Most likely, you'll want to use a nice framework like <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a> to access your data, or at least, I would recommend it. <a href="http://www.sqlalchemy.org/trac/wiki/DatabaseNotes#MicrosoftAccess" rel="nofollow">Support for Access</a> is "experimental", but I r... | 2 | 2009-05-12T16:51:52Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 855,090 | <p>If you sync your database to the web using <a href="http://eqldata.com/" rel="nofollow">EQL Data</a>, then you can query the contents of your Access tables using JSON or YAML: <a href="http://eqldata.com/kb/1002" rel="nofollow">http://eqldata.com/kb/1002</a>.</p>
<p>That article is about PHP, but it would work just... | 0 | 2009-05-12T22:00:41Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 855,212 | <p>I've used <a href="https://pypi.python.org/pypi/pyodbc/" rel="nofollow">PYODBC</a> to connect succesfully to an MS Access db - on Windows though. Install was easy, usage is fairly simple, you just need to set the right connection string (the one for MS Access is given in the list) and of you go with the examples.</p... | 17 | 2009-05-12T22:33:26Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 855,788 | <p>You've got what sounds like some good solutions. Another one that might be a bit closer to the "metal" than you'd like is MDB Tools.</p>
<p><a href="http://sourceforge.net/projects/mdbtools/">MDB Tools</a> is a set of open source libraries and utilities to facilitate exporting data from MS Access databases (mdb fi... | 8 | 2009-05-13T02:32:10Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 15,400,363 | <p>On Linux, MDBTools is your only chance as of now. <sup><a href="http://stackoverflow.com/questions/853370/#comment53931912_15400363">[disputed]</a></sup></p>
<p>On Windows, you can deal with mdb files with pypyodbc.</p>
<p>To create an Access mdb file:</p>
<pre><code>import pypyodbc
pypyodbc.win_create_mdb( "D:\\... | 25 | 2013-03-14T02:56:02Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 18,155,406 | <p>Old question, but I thought I'd post a pypyodbc alternative suggestion for Windows: ADO. Turns out, it's really easy to get at Access databases, Excel spreadsheets and anything else with a modern (as opposed to old-school ODBC) driver via COM.</p>
<p>Check out the following articles:</p>
<ul>
<li><a href="http://w... | 3 | 2013-08-09T20:48:15Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 24,096,474 | <p>On Ubuntu 12.04 this was what I did to make it work.</p>
<p>Install pyodbc:</p>
<pre><code>$ sudo apt-get install python-pyodbc
</code></pre>
<p>Follow on installing some extra drivers:</p>
<pre><code>$ sudo apt-get install mdbtools libmdbodbc1
</code></pre>
<p>Make a little test program which connects to the D... | 1 | 2014-06-07T11:01:31Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 25,773,262 | <p>If you have some time to spare, you can try to fix and update this python-class that reads MS-Access DBs through the native COM32-client API: <a href="http://code.activestate.com/recipes/528868-extraction-and-manipulation-class-for-microsoft-ac/" rel="nofollow">Extraction and manipulation class for Microsoft Access<... | 0 | 2014-09-10T19:12:11Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
What do I need to read Microsoft Access databases using Python? | 853,370 | <p>How can I access Microsoft Access databases in Python? With SQL?</p>
<p>I'd prefere a solution that works with Linux, but I could also settle for Windows.</p>
<p>I only require read access.</p>
| 24 | 2009-05-12T15:29:23Z | 25,774,158 | <p>Personally, I have never been able to get MDB Tools (along with related ODBC stuff like unixODBC) to work properly with Python or PHP under Linux, even after numerous attempts. I just tried the instructions in the other answer to this question <a href="http://stackoverflow.com/a/24096474/2144390">here</a> and all I ... | 2 | 2014-09-10T20:06:12Z | [
"python",
"linux",
"ms-access",
"python-module"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,419 | <p>'\n' is one character. It is a new line escape character and is just a representation of the new line. </p>
<p>please rephrase your question in a readable way.</p>
<p>[Edit]
I think I know what your problem is. I ran your program and it is working just fine. You are probably trying to pass '\n' to your program fro... | 9 | 2009-05-12T15:38:21Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,432 | <p>I'm guessing that your real problem is not with reading in \n as a '\' 'n' -- internally, Python should automagically translate \n into a single character.</p>
<p>My guess is that the real problem is that your newlines are probably actually two characters -- carriage return ('\r') and newline ('\n'). Try handling ... | 4 | 2009-05-12T15:40:18Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,445 | <p>You should probably take advantage of a number's numeric value to perform your encryption and avoid those big data structures that will fail for non-ascii text anyway.</p>
| 1 | 2009-05-12T15:41:53Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,459 | <p>Newline character is a single character.</p>
<pre><code>>>> a = '\n'
>>> print len(a)
1
>>> a = '\n\n\n'
>>> a[1]
'\n'
>>> len(a)
3
>>> len(a[0])
1
</code></pre>
<p>So you misunderstand what your problem is.</p>
| 3 | 2009-05-12T15:44:14Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,471 | <p>I'm new to Python, but there could be a way to simplify what you are doing by using the <strong>ord</strong> and <strong>chr</strong> functions to change characters to ASCII values and vice versa. Here's a link to the <a href="http://docs.python.org/library/functions.html" rel="nofollow">built-in function documentat... | 2 | 2009-05-12T15:46:22Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 853,530 | <p>I assume the problem is if there is \n in the text to be decrypted, it breaks:</p>
<pre><code>KeyError: \
module body in untitled at line 166
function Crypt in untitled at line 94
</code></pre>
<p>Basically, <code>raw_input()</code> returns a string containing two characters <code>\</code> and <code>n</code>... | 4 | 2009-05-12T15:56:59Z | [
"python"
] |
Alternate newline character? python | 853,398 | <p>I am looking for a way to represent '\n' with only one character. I am writing a program that uses dictionaries to 'encrypt' text. Because each character is represented in the dictionary, i am having a problem when my program gets to a '\n' in a string, but reads it as '\' 'n' . Is there alternate way to represent a... | 0 | 2009-05-12T15:35:10Z | 12,133,036 | <p>A simple and fast way to replace the usual escapes with the corresponding ASCII characters is using the <code>str.decode</code> method:</p>
<pre><code>>>> s = r'This string has\tsome\nescapes'
>>> s
'This string has\\tsome\\nescapes'
>>> s.decode('string-escape')
'This string has\tsome\ne... | 0 | 2012-08-26T19:05:06Z | [
"python"
] |
Strange python behaviour | 853,407 | <p>I was bored and playing around with the ipython console and came upon the following behaviour I don't really understand</p>
<pre><code>In [1]: 2**2
Out[1]: 4
In [2]: 2**2**2
Out[2]: 16
In [3]: 2**2**2**2
Out[3]: 65536
In [4]: 2**2**2**2**2
</code></pre>
<p>The answer to [4] is <em>not</em> 4294967296L, it's a v... | 7 | 2009-05-12T15:36:58Z | 853,449 | <p>Python is going right to left on the mathematical power operation. For example, IN[2] is doing:</p>
<p>2**(4) = 16</p>
<p>IN[3] = 2**2**2**2 = 2**2**(4) = 2**16 = 65536</p>
<p>You would need parenthesis if you want it to calculate from left to right. The reason OUT[4] is not outputting the answer you want is beca... | 16 | 2009-05-12T15:42:53Z | [
"python",
"ipython"
] |
Strange python behaviour | 853,407 | <p>I was bored and playing around with the ipython console and came upon the following behaviour I don't really understand</p>
<pre><code>In [1]: 2**2
Out[1]: 4
In [2]: 2**2**2
Out[2]: 16
In [3]: 2**2**2**2
Out[3]: 65536
In [4]: 2**2**2**2**2
</code></pre>
<p>The answer to [4] is <em>not</em> 4294967296L, it's a v... | 7 | 2009-05-12T15:36:58Z | 853,460 | <p>The precedence of the ** operator makes the evaluation goes from right-to-left (instead of the expected left-to-right). In other words:</p>
<pre><code>2**2**2**2 == (2**(2**(2**2)))
</code></pre>
| 7 | 2009-05-12T15:44:27Z | [
"python",
"ipython"
] |
Strange python behaviour | 853,407 | <p>I was bored and playing around with the ipython console and came upon the following behaviour I don't really understand</p>
<pre><code>In [1]: 2**2
Out[1]: 4
In [2]: 2**2**2
Out[2]: 16
In [3]: 2**2**2**2
Out[3]: 65536
In [4]: 2**2**2**2**2
</code></pre>
<p>The answer to [4] is <em>not</em> 4294967296L, it's a v... | 7 | 2009-05-12T15:36:58Z | 853,464 | <p>This is because the order of precedence in Python causes this equation to be evaluated from right-to-left.</p>
<pre><code>>>> 2**2
4
>>> 2**2**2
16
>>> 2**(2**2)
16
>>> 2**2**2**2
65536
>>> 2**2**(2**2)
65536
>>> 2**(2**(2**2))
65536
>>> 2**2**2**2**2
5... | 4 | 2009-05-12T15:45:34Z | [
"python",
"ipython"
] |
Strange python behaviour | 853,407 | <p>I was bored and playing around with the ipython console and came upon the following behaviour I don't really understand</p>
<pre><code>In [1]: 2**2
Out[1]: 4
In [2]: 2**2**2
Out[2]: 16
In [3]: 2**2**2**2
Out[3]: 65536
In [4]: 2**2**2**2**2
</code></pre>
<p>The answer to [4] is <em>not</em> 4294967296L, it's a v... | 7 | 2009-05-12T15:36:58Z | 853,469 | <p>Evaluating right-to-left, let's look at the steps Python is going through to get these answers:</p>
<pre><code>2**2
4
2**(2**2)
2**(4)
16
2**(2**(2**2))
2**(2**(4))
2**(16)
65536
2**(2**(2**(2**2)))
2**(2**(2**(4)))
2**(2**(16))
2**(65536)
2.0035299304068464649790723515603e+19728
</code></pre>
| 3 | 2009-05-12T15:46:16Z | [
"python",
"ipython"
] |
Strange python behaviour | 853,407 | <p>I was bored and playing around with the ipython console and came upon the following behaviour I don't really understand</p>
<pre><code>In [1]: 2**2
Out[1]: 4
In [2]: 2**2**2
Out[2]: 16
In [3]: 2**2**2**2
Out[3]: 65536
In [4]: 2**2**2**2**2
</code></pre>
<p>The answer to [4] is <em>not</em> 4294967296L, it's a v... | 7 | 2009-05-12T15:36:58Z | 854,650 | <p>As the other answers already said, it's because <code>**</code> is evaluated from right to left.
Here is the <a href="http://docs.python.org/reference/expressions.html#summary" rel="nofollow">documentation link</a>, where all the precedences are described.</p>
| 4 | 2009-05-12T20:15:14Z | [
"python",
"ipython"
] |
How should I store state for a long-running process invoked from Django? | 853,421 | <p>I am working on a Django application which allows a user to upload files. I need to perform some server-side processing on these files before sending them on to <a href="http://aws.amazon.com/s3/">Amazon S3</a>. After reading the responses to <a href="http://stackoverflow.com/questions/219329/django-fastcgi-how-to... | 5 | 2009-05-12T15:39:05Z | 853,611 | <p>We do this by having a "Request" table in the database.</p>
<p>When the upload arrives, we create the uploaded File object, and create a Request.</p>
<p>We start the background batch processor.</p>
<p>We return a 200 "we're working on it" page -- it shows the Requests and their status.</p>
<p>Our batch processor... | 6 | 2009-05-12T16:12:37Z | [
"python",
"django",
"asynchronous",
"amazon-s3",
"pyro"
] |
How should I store state for a long-running process invoked from Django? | 853,421 | <p>I am working on a Django application which allows a user to upload files. I need to perform some server-side processing on these files before sending them on to <a href="http://aws.amazon.com/s3/">Amazon S3</a>. After reading the responses to <a href="http://stackoverflow.com/questions/219329/django-fastcgi-how-to... | 5 | 2009-05-12T15:39:05Z | 854,088 | <p>So, it's a job queue that you need. For your case, I would absolutely go with the DB to save state, even if those states are short lived. It sounds like that will meet all of your requirements, and isn't terribly difficult to implement since you already have all of the moving parts there, available to you. Keep i... | 1 | 2009-05-12T18:13:47Z | [
"python",
"django",
"asynchronous",
"amazon-s3",
"pyro"
] |
How should I store state for a long-running process invoked from Django? | 853,421 | <p>I am working on a Django application which allows a user to upload files. I need to perform some server-side processing on these files before sending them on to <a href="http://aws.amazon.com/s3/">Amazon S3</a>. After reading the responses to <a href="http://stackoverflow.com/questions/219329/django-fastcgi-how-to... | 5 | 2009-05-12T15:39:05Z | 1,899,376 | <p>I know this is an old question but someone may find my answer useful even after all this time, so here goes.</p>
<p>You can of course use database as queue but there are solutions developed exactly for that purpose.</p>
<p><a href="http://www.amqp.org/">AMQP</a> is made just for that. Together with <a href="http:/... | 5 | 2009-12-14T07:06:12Z | [
"python",
"django",
"asynchronous",
"amazon-s3",
"pyro"
] |
Can I Pass Dictionary Values/Entry and Keys to function | 853,483 | <p>I am writing a function and intended to use a dictionary key and its value as parameters. For example:</p>
<pre><code>testDict={'x':2,'xS':4}
def newFunct(key,testDict['key']):
newvalue=key+str(testDict['key'])
return newValue
for key in testDict:
newValue=newFunct(key,testDict[key])
print newVal... | 0 | 2009-05-12T15:50:15Z | 853,505 | <p>why don't you just do:</p>
<pre><code>[k + str(v) for k, v in test_dict.iteritems()]
</code></pre>
<p>or for py3k:</p>
<pre><code>[k + str(v) for k, v in test_dict.items()]
</code></pre>
<p><strong>edit</strong></p>
<pre><code>def f(k, v):
print(k, v) # or do something much more complicated
for k, v i... | 0 | 2009-05-12T15:53:19Z | [
"python",
"function",
"dictionary"
] |
Can I Pass Dictionary Values/Entry and Keys to function | 853,483 | <p>I am writing a function and intended to use a dictionary key and its value as parameters. For example:</p>
<pre><code>testDict={'x':2,'xS':4}
def newFunct(key,testDict['key']):
newvalue=key+str(testDict['key'])
return newValue
for key in testDict:
newValue=newFunct(key,testDict[key])
print newVal... | 0 | 2009-05-12T15:50:15Z | 853,508 | <p>Is this what you want?</p>
<pre><code>def func(**kwargs):
for key, value in kwargs.items():
pass # Do something
func(**myDict) # Call func with the given dict as key/value parameters
</code></pre>
<p>(See the <a href="http://docs.python.org/tutorial/controlflow.html#keyword-arguments" rel="nofollow">d... | 5 | 2009-05-12T15:53:30Z | [
"python",
"function",
"dictionary"
] |
Can I Pass Dictionary Values/Entry and Keys to function | 853,483 | <p>I am writing a function and intended to use a dictionary key and its value as parameters. For example:</p>
<pre><code>testDict={'x':2,'xS':4}
def newFunct(key,testDict['key']):
newvalue=key+str(testDict['key'])
return newValue
for key in testDict:
newValue=newFunct(key,testDict[key])
print newVal... | 0 | 2009-05-12T15:50:15Z | 854,162 | <p>Not sure why we are bringing in kwargs, this is much simpler than that. You said you're new to Python, I think you just need some Python fundamentals here.</p>
<pre><code>def newFunct(key,testDict['key']):
</code></pre>
<p>Should be:</p>
<pre><code>def newFunct(key, val):
</code></pre>
<p>There's no reason to us... | 2 | 2009-05-12T18:30:57Z | [
"python",
"function",
"dictionary"
] |
Can I Pass Dictionary Values/Entry and Keys to function | 853,483 | <p>I am writing a function and intended to use a dictionary key and its value as parameters. For example:</p>
<pre><code>testDict={'x':2,'xS':4}
def newFunct(key,testDict['key']):
newvalue=key+str(testDict['key'])
return newValue
for key in testDict:
newValue=newFunct(key,testDict[key])
print newVal... | 0 | 2009-05-12T15:50:15Z | 854,750 | <p>From your description is seems like testDict is some sort of global variable with respect to the function. If this is the case - why do you even need to pass it to the function?</p>
<p>Instead of your code:</p>
<pre><code>testDict={'x':2,'xS':4}
def newFunct(key,testDict[key]):
newvalue=key+str(testDict[key])... | 0 | 2009-05-12T20:38:54Z | [
"python",
"function",
"dictionary"
] |
Do I need PyISAPIe to run Django on IIS6? | 853,755 | <p>It seems that all roads lead to having to use <a href="http://pypi.python.org/pypi/PyISAPIe/1.0.130" rel="nofollow">PyISAPIe</a> to get <a href="http://www.djangoproject.com/" rel="nofollow">Django</a> running on IIS6. This becomes a problem for us because it appears <a href="http://groups.google.com/group/pyisapie/... | 0 | 2009-05-12T16:50:46Z | 856,894 | <p>Django runs well on any WSGI infrastructure (much like any other modern Python web app framework) and there are several ways to run WSGI on IIS, e.g. see <a href="http://code.google.com/p/isapi-wsgi/" rel="nofollow">http://code.google.com/p/isapi-wsgi/</a> .</p>
| 1 | 2009-05-13T09:05:52Z | [
"python",
"django",
"iis-6",
"pyisapie"
] |
Do I need PyISAPIe to run Django on IIS6? | 853,755 | <p>It seems that all roads lead to having to use <a href="http://pypi.python.org/pypi/PyISAPIe/1.0.130" rel="nofollow">PyISAPIe</a> to get <a href="http://www.djangoproject.com/" rel="nofollow">Django</a> running on IIS6. This becomes a problem for us because it appears <a href="http://groups.google.com/group/pyisapie/... | 0 | 2009-05-12T16:50:46Z | 927,299 | <p>You need separate application pools no matter what extension you use. This is because application pools split the handler DLLs into different w3wp.exe process instances. You might wonder why this is necessary:</p>
<p>Look at Django's module setting: <code>os.environ["DJANGO_SETTINGS_MODULE"]</code>. That's the envi... | 3 | 2009-05-29T17:56:49Z | [
"python",
"django",
"iis-6",
"pyisapie"
] |
Creating a SQL Server database from Python | 854,008 | <p>I'm using Python with pywin32's adodbapi to write a script to create a SQL Server database and all its associated tables, views, and procedures. The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit(), and you can't execute a drop or cr... | 2 | 2009-05-12T17:55:47Z | 854,151 | <p>create the actual db outside the transaction. I'm not familiar with python, but there has to be a way to execute a user given string on a database, use that with the actual create db command. Then use the adodbapi to do all the tables, etc and commit that transaction.</p>
| 0 | 2009-05-12T18:28:29Z | [
"python",
"sql-server",
"pywin32",
"adodbapi"
] |
Creating a SQL Server database from Python | 854,008 | <p>I'm using Python with pywin32's adodbapi to write a script to create a SQL Server database and all its associated tables, views, and procedures. The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit(), and you can't execute a drop or cr... | 2 | 2009-05-12T17:55:47Z | 854,284 | <p>"The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit()"</p>
<p>"and you can't execute a drop or create database statement in a user transaction."</p>
<p>I'm not sure all of this is actually true for all DBAPI interfaces.</p>
<p>Sinc... | 1 | 2009-05-12T18:55:13Z | [
"python",
"sql-server",
"pywin32",
"adodbapi"
] |
Creating a SQL Server database from Python | 854,008 | <p>I'm using Python with pywin32's adodbapi to write a script to create a SQL Server database and all its associated tables, views, and procedures. The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit(), and you can't execute a drop or cr... | 2 | 2009-05-12T17:55:47Z | 854,346 | <p>The adodbapi connection object <code>conn</code> does automatically start a new transaction after every commit if the database supports transactions. DB-API requires autocommit to be turned off by default and it allows an API method to turn it back on, but I don't see one in adodbapi.</p>
<p>You might be able to us... | 1 | 2009-05-12T19:10:19Z | [
"python",
"sql-server",
"pywin32",
"adodbapi"
] |
Creating a SQL Server database from Python | 854,008 | <p>I'm using Python with pywin32's adodbapi to write a script to create a SQL Server database and all its associated tables, views, and procedures. The problem is that Python's DBAPI requires that cursor.execute() be wrapped in a transaction that is only committed by cursor.commit(), and you can't execute a drop or cr... | 2 | 2009-05-12T17:55:47Z | 4,656,450 | <p>I had this same issue while trying run commands over adodbapi (e.g. DBCC CHECKDB...) and joeforker's advice helped a bit. The problem I still had was that adodbapi automatically starts a transaction, so there was no way to execute something outside of a transaction.</p>
<p>In the end I ended up disabling adodbapi's... | 0 | 2011-01-11T10:11:36Z | [
"python",
"sql-server",
"pywin32",
"adodbapi"
] |
How to establish communication between flex and python code build on Google App Engine | 854,353 | <p>I want to communicate using flex client with GAE, I am able to communicate using XMl from GAE to FLex but how should I post from flex3 to python code present on App Engine.</p>
<p>Can anyone give me a hint about how to send login information from Flex to python
Any ideas suggest me some examples.....please provide... | 0 | 2009-05-12T19:11:49Z | 854,403 | <p>Do a HTTP post from Flex to your AppEngine app using the URLRequest class.</p>
| 0 | 2009-05-12T19:22:11Z | [
"python",
"flex",
"google-app-engine"
] |
How to establish communication between flex and python code build on Google App Engine | 854,353 | <p>I want to communicate using flex client with GAE, I am able to communicate using XMl from GAE to FLex but how should I post from flex3 to python code present on App Engine.</p>
<p>Can anyone give me a hint about how to send login information from Flex to python
Any ideas suggest me some examples.....please provide... | 0 | 2009-05-12T19:11:49Z | 854,409 | <p>Your question is somewhat vague, but this <a href="http://code.google.com/appengine/kb/general.html#auth" rel="nofollow">FAQ entry</a> might be a good start.</p>
| 0 | 2009-05-12T19:22:58Z | [
"python",
"flex",
"google-app-engine"
] |
How to establish communication between flex and python code build on Google App Engine | 854,353 | <p>I want to communicate using flex client with GAE, I am able to communicate using XMl from GAE to FLex but how should I post from flex3 to python code present on App Engine.</p>
<p>Can anyone give me a hint about how to send login information from Flex to python
Any ideas suggest me some examples.....please provide... | 0 | 2009-05-12T19:11:49Z | 854,560 | <p>I've been able to use flex on GAE using the examples found at <a href="http://gaeswf.appspot.com/" rel="nofollow">The GAE SWF Project</a> which uses <a href="http://pyamf.org/" rel="nofollow">PyAMF</a>.</p>
| 2 | 2009-05-12T19:54:38Z | [
"python",
"flex",
"google-app-engine"
] |
Change keyboard locks in Python | 854,393 | <p>Is there any way, in Python, to programmatically <em>change</em> the CAPS LOCK/NUM LOCK/SCROLL LOCK states?</p>
<p>This isn't really a joke question - more like a real question for a joke program. I intend to use it for making the lights do funny things...</p>
| 16 | 2009-05-12T19:19:37Z | 854,442 | <p>If you're using windows you can use <a href="https://pypi.python.org/pypi/SendKeys/" rel="nofollow">SendKeys</a> for this I believe.</p>
<p><a href="https://web.archive.org/web/20121125032946/http://www.rutherfurd.net/python/sendkeys" rel="nofollow">http://www.rutherfurd.net/python/sendkeys</a></p>
<pre><code>impo... | 14 | 2009-05-12T19:28:17Z | [
"python",
"windows"
] |
Change keyboard locks in Python | 854,393 | <p>Is there any way, in Python, to programmatically <em>change</em> the CAPS LOCK/NUM LOCK/SCROLL LOCK states?</p>
<p>This isn't really a joke question - more like a real question for a joke program. I intend to use it for making the lights do funny things...</p>
| 16 | 2009-05-12T19:19:37Z | 858,992 | <p>On Linux here's a Python program to blink all the keyboard LEDs on and off:</p>
<pre><code>import fcntl
import os
import time
KDSETLED = 0x4B32
SCR_LED = 0x01
NUM_LED = 0x02
CAP_LED = 0x04
console_fd = os.open('/dev/console', os.O_NOCTTY)
all_on = SCR_LED | NUM_LED | CAP_LED
all_off = 0
while 1:
fcntl.io... | 14 | 2009-05-13T16:32:23Z | [
"python",
"windows"
] |
Change keyboard locks in Python | 854,393 | <p>Is there any way, in Python, to programmatically <em>change</em> the CAPS LOCK/NUM LOCK/SCROLL LOCK states?</p>
<p>This isn't really a joke question - more like a real question for a joke program. I intend to use it for making the lights do funny things...</p>
| 16 | 2009-05-12T19:19:37Z | 21,021,632 | <p>To set CAPS LOCK to a specific value using SendKeys it is important to first detect the state of CAPS LOCK. Here's how to do that in python (under windows):</p>
<pre><code>import win32api,win32con
def IsCapsLockOn():
# return 1 if CAPSLOCK is ON
return win32api.GetKeyState(win32con.VK_CAPITAL)
</code></pre... | 2 | 2014-01-09T13:30:03Z | [
"python",
"windows"
] |
Change keyboard locks in Python | 854,393 | <p>Is there any way, in Python, to programmatically <em>change</em> the CAPS LOCK/NUM LOCK/SCROLL LOCK states?</p>
<p>This isn't really a joke question - more like a real question for a joke program. I intend to use it for making the lights do funny things...</p>
| 16 | 2009-05-12T19:19:37Z | 38,284,507 | <p>For Windows:</p>
<pre><code>#http://stackoverflow.com/questions/21549847/send-key-combination-with-python
#https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
import win32com.client as comclt
wsh= comclt.Dispatch("WScript.Shell")
wsh.SendKeys("abc") #types out abc directly into wherever you have your ... | 0 | 2016-07-09T17:37:38Z | [
"python",
"windows"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 854,963 | <p>This is not <em>really</em> thread safe because producer could overwrite <code>QUEUE_ITEM</code> before consumer has consumed it and consumer could consume <code>QUEUE_ITEM</code> twice. As you mentioned, you're OK with that but most people aren't.</p>
<p>Someone with more knowledge of cpython internals will have ... | 1 | 2009-05-12T21:31:55Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 854,968 | <p>I think it's possible that a thread is interrupted while producing/consuming, especially if the items are big objects.
Edit: this is just a wild guess. I'm no expert.</p>
<p>Also the threads may produce/consume any number of items before the other one starts running.</p>
| 0 | 2009-05-12T21:32:56Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 854,977 | <p>You can use a list as the queue as long as you stick to append/pop since both are atomic.</p>
<pre><code>QUEUE = []
# this is executed in one threading.Thread object
def producer():
global QUEUE
while True:
i = produce_item()
QUEUE.append(i)
# this is executed in another threading.Thread o... | 0 | 2009-05-12T21:34:05Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 855,054 | <p>Trickery will bite you. Just use Queue to communicate between threads.</p>
| 5 | 2009-05-12T21:50:51Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 855,122 | <p>The <code>__del__</code> could be a problem as You said. It could be avoided, if only there was a way to prevent the garbage collector from invoking the <code>__del__</code> method on the old object before We finish assigning the new one to the <code>QUEUE_ITEM</code>. We would need something like:</p>
<pre><code>i... | 0 | 2009-05-12T22:07:49Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Is this Python producer-consumer lockless approach thread-safe? | 854,906 | <p>I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.</p>
<p>Requirements in my case were simple:</p>
... | 6 | 2009-05-12T21:15:48Z | 855,735 | <p>Yes this will work in the way that you described:</p>
<ol>
<li>That the producer may produce a skippable element.</li>
<li>That the consumer may consume the same element.</li>
</ol>
<blockquote>
<p>But I also know that del x operation isn't atomic when x implements <strong>del</strong> method. So if my item has ... | 2 | 2009-05-13T02:03:19Z | [
"python",
"locking",
"thread-safety",
"producer-consumer"
] |
Error with Beautiful Soup's extract() | 855,087 | <p>I'm working on some screen scraping software and have run into an issue with Beautiful Soup. I'm using python 2.4.3 and Beautiful Soup 3.0.7a.</p>
<p>I need to remove an <code><hr></code> tag, but it can have many different attributes, so a simple replace() call won't cut it.</p>
<p>Given the following html:... | 0 | 2009-05-12T22:00:29Z | 855,474 | <p>It may be a bug. But fortunately for you, there is another way to get the string:</p>
<pre><code>from BeautifulSoup import BeautifulSoup
string = \
"""<h1>foo</h1>
<h2><hr/>bar</h2>"""
soup = BeautifulSoup(string)
bad_tags = soup.findAll('hr');
[tag.extract() for tag in bad_tags]
... | 2 | 2009-05-12T23:58:12Z | [
"python",
"beautifulsoup"
] |
Error with Beautiful Soup's extract() | 855,087 | <p>I'm working on some screen scraping software and have run into an issue with Beautiful Soup. I'm using python 2.4.3 and Beautiful Soup 3.0.7a.</p>
<p>I need to remove an <code><hr></code> tag, but it can have many different attributes, so a simple replace() call won't cut it.</p>
<p>Given the following html:... | 0 | 2009-05-12T22:00:29Z | 36,795,070 | <p>I've got the same problem.
I do not know why, but i guess it has to do with the empty elements created by BS.</p>
<p>For example if i have the following code:</p>
<pre><code>from bs4 import BeautifulSoup
html =' \
<a> \
<b test="help"> \
hello there! ... | 0 | 2016-04-22T13:23:06Z | [
"python",
"beautifulsoup"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 855,172 | <p>You can use it like this:</p>
<pre><code>--cover-package=foo --cover-package=bar
</code></pre>
<p>I had a quick look at nose source code to confirm: <a href="https://github.com/nose-devs/nose/blob/master/nose/plugins/cover.py">This is the line</a></p>
<pre><code> if options.cover_packages:
for pkgs in ... | 15 | 2009-05-12T22:23:05Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 855,341 | <p>If you use <a href="http://nedbatchelder.com/blog/200904/coverage%5Fv30%5Fbeta%5F2.html" rel="nofollow">coverage:py 3.0</a>, then code in the Python directory is ignored by default, including the standard library and all installed packages.</p>
| 3 | 2009-05-12T23:10:06Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 6,273,255 | <pre><code>touch __init__.py; nosetests --with-coverage --cover-package=`pwd | sed 's@.*/@@g'`
</code></pre>
| 1 | 2011-06-08T01:11:45Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 7,691,689 | <p>You can use:</p>
<pre><code>--cover-package=.
</code></pre>
<p>or even set environment variable</p>
<pre><code>NOSE_COVER_PACKAGE=.
</code></pre>
<p>Tested with nose 1.1.2</p>
| 9 | 2011-10-07T18:58:42Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 16,101,923 | <p>I would do this:</p>
<pre><code>nosetests --with-coverage --cover-package=foo,bar tests/*
</code></pre>
<p>I prefer this solution to the others suggested; it's simple yet you are explicit about which packages you wish to have coverage for. Nadia's answer involves a lot more redundant typing, Stuart's answer uses s... | 2 | 2013-04-19T09:54:24Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 22,674,615 | <p>I have a lot of top-level Python files/packages and find it annoying to list them all manually using --cover-package, so I made two aliases for myself. Alias <code>nosetests_cover</code> will run coverage with all your top-level Python files/packages listed in --cover-package. Alias <code>nosetests_cover_sort</code>... | 4 | 2014-03-26T22:44:04Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 32,377,465 | <p>For anyone trying to do this with setup.cfg, the following works. I had some trouble figuring out how to specify multiple packages.</p>
<pre><code>[nosetests]
with-coverage=1
cover-html=1
cover-package=module1,module2
</code></pre>
| 2 | 2015-09-03T13:47:08Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
Can I restrict nose coverage output to directory (rather than package)? | 855,114 | <p>My SUT looks like:</p>
<pre><code>foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py
</code></pre>
<p>When I run <code>nosetests --with-coverage</code>, I get details for all sorts of
modu... | 13 | 2009-05-12T22:06:28Z | 37,620,563 | <p>You can improve the accepted answer like so <code>--cover-package=foo,bar</code></p>
| 0 | 2016-06-03T17:46:00Z | [
"python",
"code-coverage",
"nose",
"nosetests"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,195 | <p>12000 elements is nothing in Python... and actually the number of elements can go as far as the Python interpreter has memory on your system.</p>
| 3 | 2009-05-12T22:29:11Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,200 | <p>I'd say you're only limited by the total amount of RAM available. Obviously the larger the array the longer operations on it will take.</p>
| 1 | 2009-05-12T22:30:24Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,213 | <p>Sure it is OK. Actually you can see for yourself easily:</p>
<pre><code>l = range(12000)
l = sorted(l, reverse=True)
</code></pre>
<p>Running the those lines on my machine took:</p>
<pre><code>real 0m0.036s
user 0m0.024s
sys 0m0.004s
</code></pre>
<p>But sure as everyone else said. The larger the array th... | 21 | 2009-05-12T22:33:28Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,221 | <p>In casual code I've created lists with millions of elements. I believe that Python's implementation of lists are only bound by the amount of memory on your system. </p>
<p>In addition, the list methods / functions should continue to work despite the size of the list. </p>
<p>If you care about performance, it might... | 5 | 2009-05-12T22:36:12Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,455 | <p>According to the <a href="http://svn.python.org/view/python/trunk/Objects/listobject.c?revision=69227&view=markup">source code</a>, the maximum size of a list is <code>PY_SSIZE_T_MAX/sizeof(PyObject*)</code>.</p>
<p><code>PY_SSIZE_T_MAX</code> is defined in <a href="http://svn.python.org/view/python/trunk/Inclu... | 124 | 2009-05-12T23:48:21Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 855,465 | <p><a href="http://effbot.org/zone/python-list.htm#performance" rel="nofollow">Performance characteristics for lists</a> are described on Effbot.</p>
<p>Python lists are actually implemented as vector for fast random access, so the container will basically hold as many items as there is space for in memory. (You need ... | 4 | 2009-05-12T23:53:34Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 15,739,630 | <p>As the <a href="http://docs.python.org/2/library/sys.html#sys.maxsize">Python documentation says</a>:</p>
<p><strong>sys.maxsize</strong></p>
<blockquote>
<p>The largest positive integer supported by the platformâs Py_ssize_t type, and thus the maximum size lists, strings, dicts, and many other containers can ... | 20 | 2013-04-01T07:45:18Z | [
"python",
"arrays",
"size"
] |
How Big can a Python Array Get? | 855,191 | <p>In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?</p>
| 70 | 2009-05-12T22:27:33Z | 22,240,449 | <p>There is no limitation of list number.
The main reason which causes your error is the RAM.
Please upgrade your memory size.</p>
| -5 | 2014-03-07T02:44:06Z | [
"python",
"arrays",
"size"
] |
Getting local dictionary for function scope only in Python | 855,259 | <p>I keep ending up at this situation where I want to use a dictionary very much like the one 'locals' gives back, but that only contains the variables in the limited scope of the function. Is there a way to do this in python? </p>
<p>A bit more about why I want to do this: I'm playing with Django and when I go to giv... | 0 | 2009-05-12T22:49:01Z | 855,277 | <p>How is passing a dictionary a violation of DRY? <a href="http://docs.djangoproject.com/en/dev/misc/design-philosophies/#don-t-repeat-yourself-dry" rel="nofollow">Django is all about DRY</a>, so I doubt the standard behavior of it would directly violate it. In either case, however, I use a modified version of <a href... | 4 | 2009-05-12T22:54:22Z | [
"python",
"django",
"scope",
"django-views",
"locals"
] |
Getting local dictionary for function scope only in Python | 855,259 | <p>I keep ending up at this situation where I want to use a dictionary very much like the one 'locals' gives back, but that only contains the variables in the limited scope of the function. Is there a way to do this in python? </p>
<p>A bit more about why I want to do this: I'm playing with Django and when I go to giv... | 0 | 2009-05-12T22:49:01Z | 855,284 | <p>I'm not sure I agree that making a dictionary is a violation of DRY, but if you really don't want to repeat anything at all, you could just define a 'context' dictionary at the top of the view and use dictionary keys instead of variables throughout the view.</p>
<pre><code>def my_view(request):
context = {}
... | 5 | 2009-05-12T22:57:12Z | [
"python",
"django",
"scope",
"django-views",
"locals"
] |
Getting local dictionary for function scope only in Python | 855,259 | <p>I keep ending up at this situation where I want to use a dictionary very much like the one 'locals' gives back, but that only contains the variables in the limited scope of the function. Is there a way to do this in python? </p>
<p>A bit more about why I want to do this: I'm playing with Django and when I go to giv... | 0 | 2009-05-12T22:49:01Z | 855,363 | <p>You say you don't like using locals() because it is "wasteful". Wasteful of what? I believe the dictionary it returns already exists, it's just giving you a reference to it. And even if it has to create the dictionary, this is one of the most highly optimized operations in Python, so don't worry about it.</p>
<p... | 2 | 2009-05-12T23:14:39Z | [
"python",
"django",
"scope",
"django-views",
"locals"
] |
Getting local dictionary for function scope only in Python | 855,259 | <p>I keep ending up at this situation where I want to use a dictionary very much like the one 'locals' gives back, but that only contains the variables in the limited scope of the function. Is there a way to do this in python? </p>
<p>A bit more about why I want to do this: I'm playing with Django and when I go to giv... | 0 | 2009-05-12T22:49:01Z | 856,880 | <p>While I agree with many other respondents that passing either <code>locals()</code> or a fully specified dict <code>{'var1':var1, 'var2': var2}</code> is most likely OK, if you specifically want to "subset" a dict such as <code>locals()</code> that's far from hard either, e.g.:</p>
<pre><code>loc = locals()
return ... | 2 | 2009-05-13T09:02:09Z | [
"python",
"django",
"scope",
"django-views",
"locals"
] |
Running django on OSX | 855,408 | <p>I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.</p>
<p>I'm running OSX 10.5 and have the standard ... | 0 | 2009-05-12T23:29:12Z | 855,573 | <p>You probably won't find much joy using <code>.htaccess</code> to configure Django through Apache (though I confess you probably could do it if you're determined enough... but for production I suspect it will be more complicated than necessary). I develop and run Django in OS X, and it works quite seamlessly.</p>
<p... | 5 | 2009-05-13T00:55:15Z | [
"python",
"django",
"osx"
] |
Running django on OSX | 855,408 | <p>I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.</p>
<p>I'm running OSX 10.5 and have the standard ... | 0 | 2009-05-12T23:29:12Z | 856,033 | <p>Unless you are planning on going to production with OS X you might not want to bother. If you must do it, go straight to mod_wsgi. Don't bother with mod_python or older solutions. I did mod_python on Apache and while it runs great now, it took countless hours to set up.</p>
<p>Also, just to clarify something based ... | 4 | 2009-05-13T04:14:09Z | [
"python",
"django",
"osx"
] |
Running django on OSX | 855,408 | <p>I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.</p>
<p>I'm running OSX 10.5 and have the standard ... | 0 | 2009-05-12T23:29:12Z | 856,037 | <p>If you're planning on running it for production (or non-development) mode another option is to do away with Apache and go with something lightweight like nginx. But if you're doing development work, you'll want to stick with the built-in server and PyDev in Eclipse. It's so much easier to walk through the server cod... | 3 | 2009-05-13T04:16:04Z | [
"python",
"django",
"osx"
] |
Running django on OSX | 855,408 | <p>I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.</p>
<p>I'm running OSX 10.5 and have the standard ... | 0 | 2009-05-12T23:29:12Z | 856,986 | <p>Yet another option is to consider using a virtual machine for your development. You can install a full version of whatever OS your production server will be running - say, Debian - and run your Apache and DB in the VM.</p>
<p>You can connect to the virtual disk in the Finder, so you can still use TextMate (or whate... | 2 | 2009-05-13T09:32:16Z | [
"python",
"django",
"osx"
] |
referenced before assignment error in python | 855,493 | <p>In Python I'm getting the following error:</p>
<pre><code>UnboundLocalError: local variable 'total' referenced before assignment
</code></pre>
<p>At the start of the file (before the function where the error comes from), I declare 'total' using the global keyword. Then, in the body of the program, before the funct... | 32 | 2009-05-13T00:08:33Z | 855,511 | <p>I think you are using 'global' incorrectly. See <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-global-statement">Python reference</a>. You should declare variable without global and then inside the function when you want to access global variable you declare it 'global yourvar'.</p>
<pre><code>#!... | 70 | 2009-05-13T00:24:28Z | [
"python"
] |
Why can't I pass a direct reference to a dictionary value to a function? | 855,514 | <p>Earlier today I asked a <a href="http://stackoverflow.com/questions/853483/can-i-pass-dictionary-values-entry-and-keys-to-function">question</a>
about passing dictionary values to a function. While I understand now how to accomplish what I was trying to accomplish the why question (which was not asked) was never an... | 1 | 2009-05-13T00:25:53Z | 855,521 | <p>Yes, the parser will reject this code.</p>
<p>Parameter lists are used in function definitions to bind identifiers within the function to arguments that are passed in from the outside <strong>on invocation</strong>.</p>
<p>Since <code>newDict['bubba']</code> is not a valid identifier, this doesn't make any sense -... | 6 | 2009-05-13T00:31:12Z | [
"python",
"function",
"dictionary",
"parameters"
] |
Why can't I pass a direct reference to a dictionary value to a function? | 855,514 | <p>Earlier today I asked a <a href="http://stackoverflow.com/questions/853483/can-i-pass-dictionary-values-entry-and-keys-to-function">question</a>
about passing dictionary values to a function. While I understand now how to accomplish what I was trying to accomplish the why question (which was not asked) was never an... | 1 | 2009-05-13T00:25:53Z | 855,543 | <p>It looks like you might be confused between the <em>definition</em> of a function and <em>calling</em> that function. As a simple example:</p>
<pre><code>def f(x):
y = x * x
print "x squared is", y
</code></pre>
<p>By itself, this function doesn't do anything (ie. it doesn't print anything). If you put thi... | 2 | 2009-05-13T00:42:33Z | [
"python",
"function",
"dictionary",
"parameters"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.