title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How to use Matplotlib in Django? | 1,874,642 | <p>From some examples from the Internet I made the test code below. It works! </p>
<p>... BUT if I reload the page, the pie will draw itself with the same image. Some parts get darker every time I reload the page. When I restart the the development server, it is reset. How do I draw properly with <a href="http://en.wi... | 13 | 2009-12-09T15:26:50Z | 1,874,740 | <p>You need to remove the <code>num</code> parameter from the <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.figure">figure constructor</a> and <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.close">close</a> the figure when you're done with it.</p>... | 19 | 2009-12-09T15:40:58Z | [
"python",
"django",
"matplotlib"
] |
Data extraction and manipulation in jython | 1,874,712 | <p>For a given file </p>
<p>For ex : 11 ,345 , sdfsfsfs , 1232 </p>
<p>i need to such above records from a file , read 11 to delimiter and strip the white space and store in the another file , similarly 345 to delimiter strip the while space and store in the file. This way i need to do for multiple rows.</p>
<p>so... | 0 | 2009-12-09T15:35:48Z | 1,875,183 | <p>Open the input file (1) and the output file (2) for reading and writing respectively. </p>
<pre><code>file1 = open('file1', 'r')
file2 = open('file2', 'w')
</code></pre>
<p>Iterate over the input file, getting each line. Split the line on a comma. Then re-join the line using a comma, but first stripping the whit... | 2 | 2009-12-09T16:45:38Z | [
"python",
"string",
"jython"
] |
Data extraction and manipulation in jython | 1,874,712 | <p>For a given file </p>
<p>For ex : 11 ,345 , sdfsfsfs , 1232 </p>
<p>i need to such above records from a file , read 11 to delimiter and strip the white space and store in the another file , similarly 345 to delimiter strip the while space and store in the file. This way i need to do for multiple rows.</p>
<p>so... | 0 | 2009-12-09T15:35:48Z | 1,875,559 | <p>One approach you could take would be to remove all whitespace using the <a href="http://docs.python.org/library/string.html#string.translate" rel="nofollow"><code>string.translate</code> function</a>.</p>
<pre><code>import string
#makes a 256 character string that will be used in the translate function
trans_table... | 0 | 2009-12-09T17:37:07Z | [
"python",
"string",
"jython"
] |
data cache for python package | 1,874,737 | <p>I have a python module which generates large data files which I want to cache on disk for future use. The cache is likely to end up some hundreds of MB for a normal user, but save a lot of computation time.</p>
<p>The files aren't distributed with the module, but are generated the first time the code is run with a ... | 2 | 2009-12-09T15:40:20Z | 1,874,827 | <p>You can use the standard library module <a href="http://docs.python.org/library/configparser.html" rel="nofollow">ConfigParser</a> to parse an ini file (or .rc file depending on your culture). To find the file, <a href="http://docs.python.org/library/os.path.html?highlight=expanduser#os.path.expanduser" rel="nofoll... | 3 | 2009-12-09T15:54:17Z | [
"python",
"distutils"
] |
data cache for python package | 1,874,737 | <p>I have a python module which generates large data files which I want to cache on disk for future use. The cache is likely to end up some hundreds of MB for a normal user, but save a lot of computation time.</p>
<p>The files aren't distributed with the module, but are generated the first time the code is run with a ... | 2 | 2009-12-09T15:40:20Z | 8,593,059 | <p>There is an emerging standard in the free OS world: <a href="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html" rel="nofollow">http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html</a></p>
<p>This module can help you for Windows and Max OS X, but it seems to be broken with resp... | 2 | 2011-12-21T16:28:15Z | [
"python",
"distutils"
] |
Python SQLite FTS3 alternatives? | 1,874,957 | <p>Are there any good alternatives to SQLite + FTS3 for python?</p>
<p>I'm iterating over a series of text documents, and would like to categorize them according to some text queries. For example, I might want to know if a document mentions the words "rating" or "upgraded" within three words of "buy." The FTS3 syntax ... | 2 | 2009-12-09T16:12:13Z | 2,633,032 | <p>I suggest you install pysqlite2 module separately. You should make sure that you have sqlite3 installed in your system which should have the FTS3 module ;-)</p>
<p>Checkout <a href="http://code.google.com/p/pysqlite/downloads/list" rel="nofollow">http://code.google.com/p/pysqlite/downloads/list</a> for the latest c... | 2 | 2010-04-13T20:39:20Z | [
"python",
"search",
"text",
"full-text-search"
] |
Pip + WSGI import errors | 1,875,037 | <p>when i deploy my apps that worked fine using the django test server I usually get errors for every package I installed using pip install -e ....#egg=foo. I usually do this using virtualenv, which placed the files into env/src/foo and places another file into python/site-packages (this is an example of django-css):</... | 2 | 2009-12-09T16:23:55Z | 1,875,104 | <p>The modwsgi documentation has notes on <a href="http://code.google.com/p/modwsgi/wiki/VirtualEnvironments" rel="nofollow">how to use virtualenv</a>. It is usually as simple as modifying your <code>django.wsgi</code> (or whatever you call it) file so that it adds the virtualenv environment to modwsgi's path.</p>
<p>... | 0 | 2009-12-09T16:34:15Z | [
"python",
"django",
"wsgi",
"virtualenv",
"pip"
] |
Pip + WSGI import errors | 1,875,037 | <p>when i deploy my apps that worked fine using the django test server I usually get errors for every package I installed using pip install -e ....#egg=foo. I usually do this using virtualenv, which placed the files into env/src/foo and places another file into python/site-packages (this is an example of django-css):</... | 2 | 2009-12-09T16:23:55Z | 1,875,169 | <p>This is what my WSGI script for Django in a virtualenv looks like:</p>
<pre><code>import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import site
site.addsitedir('/path/to/virtualenv/lib/python2.6/site-packages')
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
</cod... | 4 | 2009-12-09T16:44:05Z | [
"python",
"django",
"wsgi",
"virtualenv",
"pip"
] |
Using paired certificates with urllib2 | 1,875,052 | <p>I need to create a secure channel between my server and a remote web service. I'll be using HTTPS with a client certificate. I'll also need to validate the certificate presented by the remote service.</p>
<ol>
<li><p>How can I use my own client certificate with urllib2?</p></li>
<li><p>What will I need to do in m... | 14 | 2009-12-09T16:27:21Z | 1,875,106 | <p>Here's a <a href="http://bugs.python.org/issue3466">bug in the official Python bugtracker</a> that looks relevant, and has a proposed patch.</p>
| 10 | 2009-12-09T16:34:40Z | [
"python",
"ssl",
"certificate",
"urllib2"
] |
Using paired certificates with urllib2 | 1,875,052 | <p>I need to create a secure channel between my server and a remote web service. I'll be using HTTPS with a client certificate. I'll also need to validate the certificate presented by the remote service.</p>
<ol>
<li><p>How can I use my own client certificate with urllib2?</p></li>
<li><p>What will I need to do in m... | 14 | 2009-12-09T16:27:21Z | 2,504,830 | <p>check <a href="http://www.osmonov.com/2009/04/client-certificates-with-urllib2.html" rel="nofollow">http://www.osmonov.com/2009/04/client-certificates-with-urllib2.html</a></p>
| 1 | 2010-03-24T01:42:03Z | [
"python",
"ssl",
"certificate",
"urllib2"
] |
Using paired certificates with urllib2 | 1,875,052 | <p>I need to create a secure channel between my server and a remote web service. I'll be using HTTPS with a client certificate. I'll also need to validate the certificate presented by the remote service.</p>
<ol>
<li><p>How can I use my own client certificate with urllib2?</p></li>
<li><p>What will I need to do in m... | 14 | 2009-12-09T16:27:21Z | 4,464,435 | <p>Because alex's answer is a link, and the code on that page is poorly formatted, I'm just going to put this here for posterity:</p>
<pre><code>import urllib2, httplib
class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
def __init__(self, key, cert):
urllib2.HTTPSHandler.__init__(self)
self.key =... | 26 | 2010-12-16T19:05:28Z | [
"python",
"ssl",
"certificate",
"urllib2"
] |
Importing a module based on installed python version? | 1,875,259 | <p>My module currently imports the <code>json</code> module, which is only available in 2.6. I'd like to make a check against the python version to import <code>simplejson</code>, which can be built for 2.5 (and is the module adopted in 2.6 anyway). Something like:</p>
<pre><code>if __version__ 2.5:
import simplej... | 5 | 2009-12-09T16:55:26Z | 1,875,267 | <pre><code>try:
import simplejson as json
except ImportError:
import json
</code></pre>
<p>of course, it doesn't work around cases when in python-2.5 you don't have <code>simplejson</code> installed, the same as your example.</p>
| 9 | 2009-12-09T16:56:30Z | [
"python",
"json"
] |
Importing a module based on installed python version? | 1,875,259 | <p>My module currently imports the <code>json</code> module, which is only available in 2.6. I'd like to make a check against the python version to import <code>simplejson</code>, which can be built for 2.5 (and is the module adopted in 2.6 anyway). Something like:</p>
<pre><code>if __version__ 2.5:
import simplej... | 5 | 2009-12-09T16:55:26Z | 1,875,584 | <p>Though the ImportError approach (SilentGhost's answer) is definitely best for this example, anyone wanting to do that <code>__version__</code> thing would use something like this:</p>
<pre><code>import sys
if sys.version_info < (2, 6):
import simplejson as json
else:
import json
</code></pre>
<p>To be a... | 4 | 2009-12-09T17:44:22Z | [
"python",
"json"
] |
Fabric error: Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'message' | 1,875,306 | <p>I'm trying to setup a fabfile to deploy my Django app.</p>
<p>I can't figure out why I'm getting this error:</p>
<blockquote>
<p>Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'changed settings for prodserver'</p>
</blockquote>
<pre><code>$ fab create_branch_deploy_to_p... | 5 | 2009-12-09T17:01:17Z | 1,876,122 | <p>Is this a python-related issue like the one described in <a href="http://www.mail-archive.com/fab-user@nongnu.org/msg00853.html" rel="nofollow">this thread</a>?</p>
<blockquote>
<p>The main problem with this is that the <code>stdout</code>/<code>stderr</code> capturing is per-run/sudo invocation and not per-task.... | 1 | 2009-12-09T19:09:55Z | [
"python",
"git",
"fabric"
] |
Fabric error: Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'message' | 1,875,306 | <p>I'm trying to setup a fabfile to deploy my Django app.</p>
<p>I can't figure out why I'm getting this error:</p>
<blockquote>
<p>Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'changed settings for prodserver'</p>
</blockquote>
<pre><code>$ fab create_branch_deploy_to_p... | 5 | 2009-12-09T17:01:17Z | 1,876,166 | <p>I was able to diagnose the issue when I added capture=False to the declaration:</p>
<pre><code>local('git rm fabfile.py', capture=False)
local('git add settings.py', capture=False)
</code></pre>
<p>This allowed the error to be displayed more verbosely.</p>
<p>Apparently, the maintainer of Fabric will to revert <c... | 6 | 2009-12-09T19:17:34Z | [
"python",
"git",
"fabric"
] |
Validate image size in django admin | 1,875,316 | <p>I see a lot of people with Django apps that have image uploads are automatically resizing the images after they are uploaded. That is well and good for some cases, but I don't want to do this. Instead, I simply want to force the user to upload a file that is already the proper size. </p>
<p>I want to have an ImageF... | 13 | 2009-12-09T17:02:27Z | 1,875,453 | <p>The right place to do this is during form validation.<br>
A quick example (will edit/integrate with more info later):</p>
<pre><code>from django.core.files.images import get_image_dimensions
class myForm(forms.ModelForm):
class Meta:
model = myModel
def clean_picture(self):
picture = self.cleane... | 36 | 2009-12-09T17:20:18Z | [
"python",
"django",
"image",
"django-forms",
"python-imaging-library"
] |
Validate image size in django admin | 1,875,316 | <p>I see a lot of people with Django apps that have image uploads are automatically resizing the images after they are uploaded. That is well and good for some cases, but I don't want to do this. Instead, I simply want to force the user to upload a file that is already the proper size. </p>
<p>I want to have an ImageF... | 13 | 2009-12-09T17:02:27Z | 1,875,704 | <p>This may be a dupe of/very similar to this question:</p>
<p><a href="http://stackoverflow.com/questions/307679/using-jquery-restricting-file-size-before-uploading">Using jQuery, Restricting File Size Before Uploading</a></p>
<p>I don't think there is a way to do it the way you want. Agos solution is the way to go.... | 1 | 2009-12-09T18:01:34Z | [
"python",
"django",
"image",
"django-forms",
"python-imaging-library"
] |
Validate image size in django admin | 1,875,316 | <p>I see a lot of people with Django apps that have image uploads are automatically resizing the images after they are uploaded. That is well and good for some cases, but I don't want to do this. Instead, I simply want to force the user to upload a file that is already the proper size. </p>
<p>I want to have an ImageF... | 13 | 2009-12-09T17:02:27Z | 29,530,519 | <p>use this function in your model file, </p>
<pre><code>from django.core.exceptions import ValidationError
def validate_image(fieldfile_obj):
filesize = fieldfile_obj.file.size
megabyte_limit = 2.0
if filesize > megabyte_limit*1024*1024:
raise ValidationErro... | 0 | 2015-04-09T05:34:07Z | [
"python",
"django",
"image",
"django-forms",
"python-imaging-library"
] |
Django password change:Reverse for '<function password_change_done at 0xa3b0f0c>' with arguments '()' and keyword arguments '{}' not found | 1,875,318 | <p>When inckuded the following in urls.py </p>
<pre><code>(r'^settings/users/change_password/$', 'django.contrib.auth.views.password_change'
</code></pre>
<p>The following shows up on the screen,</p>
<pre><code>Reverse for '<function password_change_done at 0xa3b0f0c>' with arguments '()' and keyword arguments... | 1 | 2009-12-09T17:02:49Z | 1,875,954 | <p>The password_change view redirects to <code>django.contrib.auth.views.password_change_done</code> - this needs to be listed in your urls.py.</p>
<p>Alternatively, add the <code>post_change_redirect</code> argument to your password_change view to tell it where to redirect to:</p>
<pre><code>(r'^settings/users/chang... | 4 | 2009-12-09T18:44:55Z | [
"python",
"django"
] |
Wx.Widgets AUIMananger Toggle Panes | 1,875,396 | <p>I'm having trouble toggling panes with the AUIManager.</p>
<p>Here's basically what I'm doing:</p>
<pre><code>class foo(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=wx.Size(800,600))
self.menubar = wx.MenuBar()
self._mgr = wx.aui.AuiM... | 0 | 2009-12-09T17:13:49Z | 4,107,417 | <p>This method works fine for me. It should for you too if you call <code>Update()</code> on your <code>window manager</code> after you show or hide your pane.</p>
<pre><code> def togglePane(self,event):
if self._mgr.GetPane('Widget Name').IsShown():
self._mgr.GetPane('Widget Name').Hide()
else:
... | 1 | 2010-11-05T15:33:38Z | [
"python",
"wxpython"
] |
Dynamic function with local variables | 1,875,497 | <p>I'm trying to dynamically create a bunch of class properties, but each dynamic fget accessor needs a unique local variable.</p>
<p>Here is a simplified example:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def fget(self, i=i):
r... | 2 | 2009-12-09T17:26:49Z | 1,875,562 | <p>"Each dynamic fget accessor needs a unique local variable."</p>
<p>That tells you that each "property" is a separate instance of some class.</p>
<p>Consider using descriptors for this so that you have a complete class instead of some cobbed-up instance variable.</p>
<p>Or consider using some variant on the <stron... | 1 | 2009-12-09T17:37:47Z | [
"python"
] |
Dynamic function with local variables | 1,875,497 | <p>I'm trying to dynamically create a bunch of class properties, but each dynamic fget accessor needs a unique local variable.</p>
<p>Here is a simplified example:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def fget(self, i=i):
r... | 2 | 2009-12-09T17:26:49Z | 1,875,575 | <p>You could use a closure over a local variable instead of passing <code>i</code> as a default argument:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def asclosure():
# function to create a new local scope for |ci|
ci... | 0 | 2009-12-09T17:42:31Z | [
"python"
] |
Dynamic function with local variables | 1,875,497 | <p>I'm trying to dynamically create a bunch of class properties, but each dynamic fget accessor needs a unique local variable.</p>
<p>Here is a simplified example:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def fget(self, i=i):
r... | 2 | 2009-12-09T17:26:49Z | 1,875,578 | <p>One alternative is to define a second function that captures the value of the variable as a new local. E.g.:</p>
<pre><code>def make_prop_that_returns(i):
return property(lambda self: i)
class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
dict['f%d' % i] = make... | 1 | 2009-12-09T17:43:14Z | [
"python"
] |
Dynamic function with local variables | 1,875,497 | <p>I'm trying to dynamically create a bunch of class properties, but each dynamic fget accessor needs a unique local variable.</p>
<p>Here is a simplified example:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def fget(self, i=i):
r... | 2 | 2009-12-09T17:26:49Z | 1,875,587 | <p>For this simplified example, I think that what you have works pretty well (aside from being a bit hacky). While the <code>i=i</code> part can be ugly and tricky, it is a relatively well known way to make closures. Add a comment if you're afraid someone won't get it.</p>
<p>However, if you're doing something that'... | 0 | 2009-12-09T17:45:01Z | [
"python"
] |
Dynamic function with local variables | 1,875,497 | <p>I'm trying to dynamically create a bunch of class properties, but each dynamic fget accessor needs a unique local variable.</p>
<p>Here is a simplified example:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
for i in range(5):
def fget(self, i=i):
r... | 2 | 2009-12-09T17:26:49Z | 1,875,588 | <p>You just need another function where <code>i</code> is a argument:</p>
<pre><code>class Test(object):
def __metaclass__(name, bases, dict):
def makeprop( i ):
# a new namespace where `i` never changes
def fget(self):
return i
return property(fget)
... | 0 | 2009-12-09T17:45:06Z | [
"python"
] |
Saving wx widget contents to a file | 1,875,538 | <p>I have created different shapes like circle/rect etc in my program using BufferedPaintDC on event. Now i want to save the file as I click the saveas button in the menu option. For that I am using memoryDC and save the contents as bmp file.</p>
<p>def Saveas(self,event):</p>
<pre><code> dlg = wx.FileDialog(self,... | 1 | 2009-12-09T17:33:03Z | 1,875,626 | <p>What you're asking is very close to saying you want to take a screenshot. Although technically grabbing a copy of what the window currently looks like is not the same as cloning what the OnPaint does, it's possible it would do the job for you.</p>
<p>If it doesn't work, take note of the technique, including the us... | 0 | 2009-12-09T17:50:15Z | [
"python",
"wxpython",
"wxwidgets"
] |
Python 2.6+ str.format() and regular expressions | 1,875,676 | <p>Using <code>str.format()</code> is the new standard for formatting strings in Python 2.6, and Python 3. I've run into an issue when using <code>str.format()</code> with regular expressions.</p>
<p>I've written a regular expression to return all domains that are a single level below a specified domain or any domains... | 9 | 2009-12-09T17:57:34Z | 1,875,706 | <p>you first would need to format string and then use regex. It really doesn't worth it to put everything into a single line. Escaping is done by doubling the curly braces:</p>
<pre><code>>>> pat= '^(w{{3}}\.)?([0-9A-Za-z-]+\.){{1}}{domainName}$'.format(domainName = 'delivery.com')
>>> pat
'^(w{3}\\.... | 15 | 2009-12-09T18:02:01Z | [
"python",
"regex",
"format",
"string-formatting"
] |
Python 2.6+ str.format() and regular expressions | 1,875,676 | <p>Using <code>str.format()</code> is the new standard for formatting strings in Python 2.6, and Python 3. I've run into an issue when using <code>str.format()</code> with regular expressions.</p>
<p>I've written a regular expression to return all domains that are a single level below a specified domain or any domains... | 9 | 2009-12-09T17:57:34Z | 1,875,714 | <p>Per <a href="http://docs.python.org/library/string.html#formatstrings" rel="nofollow">the documentation</a>, if you need a literal <code>{</code> or <code>}</code> to survive the formatting opertation, use <code>{{</code> and <code>}}</code> in the original string.</p>
<pre><code>'^(w{{3}}\.)?([0-9A-Za-z-]+\.){{1}}... | 3 | 2009-12-09T18:04:52Z | [
"python",
"regex",
"format",
"string-formatting"
] |
Execute sql query with Elixir | 1,875,885 | <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p>
<p><code>VACUUM FULL ANALYZE table</code></p>
<p><strong>Update</strong></p>
<p>The... | 5 | 2009-12-09T18:36:02Z | 1,876,026 | <p>If you have access to SQLAlchemy session, you can execute arbitrary SQL statements via its <code>execute</code> method:</p>
<pre><code>session.execute("VACUUM FULL ANALYZE table")
</code></pre>
| 0 | 2009-12-09T18:53:08Z | [
"python",
"postgresql",
"sqlalchemy",
"python-elixir"
] |
Execute sql query with Elixir | 1,875,885 | <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p>
<p><code>VACUUM FULL ANALYZE table</code></p>
<p><strong>Update</strong></p>
<p>The... | 5 | 2009-12-09T18:36:02Z | 1,880,137 | <p>(Depending on the Postgres version) you most likely <a href="http://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-BASICS" rel="nofollow">do not want</a> to run "VACUUM FULL".</p>
| 0 | 2009-12-10T10:42:42Z | [
"python",
"postgresql",
"sqlalchemy",
"python-elixir"
] |
Execute sql query with Elixir | 1,875,885 | <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p>
<p><code>VACUUM FULL ANALYZE table</code></p>
<p><strong>Update</strong></p>
<p>The... | 5 | 2009-12-09T18:36:02Z | 1,880,368 | <p><code>UnboundExecutionError</code> says that your session is not bound to an engine and there is no way to discover engine from query passed to <code>execute()</code>. You can either use <code>engine.execute()</code> directly or pass additional <code>mapper</code> parameter (either mapper or mapped model correspondi... | 1 | 2009-12-10T11:27:24Z | [
"python",
"postgresql",
"sqlalchemy",
"python-elixir"
] |
Execute sql query with Elixir | 1,875,885 | <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p>
<p><code>VACUUM FULL ANALYZE table</code></p>
<p><strong>Update</strong></p>
<p>The... | 5 | 2009-12-09T18:36:02Z | 2,042,987 | <p>You need to bind the session to an engine</p>
<pre><code>session.bind = metadata.bind
session.execute('YOUR SQL STATEMENT')
</code></pre>
| 2 | 2010-01-11T16:02:56Z | [
"python",
"postgresql",
"sqlalchemy",
"python-elixir"
] |
Execute sql query with Elixir | 1,875,885 | <p>I'm using Elixir in a project that connects to a postgres database. I want to run the following query on the database I'm connected to, but I'm not sure how to do it as I'm rather new to Elixir and SQLAlchemy. Anyone know how?</p>
<p><code>VACUUM FULL ANALYZE table</code></p>
<p><strong>Update</strong></p>
<p>The... | 5 | 2009-12-09T18:36:02Z | 2,096,497 | <p>Dammit. I knew the answer was going to be right under my nose. Assuming you setup your connection like I did.</p>
<pre><code>metadata.bind = 'postgres://user:pw@host/db'
</code></pre>
<p>The solution to this was as simple as </p>
<pre><code>conn = metadata.bind.engine.connect()
old_lvl = conn.connection.isolatio... | 10 | 2010-01-19T19:39:42Z | [
"python",
"postgresql",
"sqlalchemy",
"python-elixir"
] |
Deleting key/value from list of dictionaries using lambda and map | 1,875,932 | <p>I have a list of dictionaries that have the same keys within eg:</p>
<pre><code>[{k1:'foo', k2:'bar', k3...k4....}, {k1:'foo2', k2:'bar2', k3...k4....}, ....]
</code></pre>
<p>I'm trying to delete k1 from all dictionaries within the list.</p>
<p>I tried</p>
<pre><code>map(lambda x: del x['k1'], list)
</code></pr... | 6 | 2009-12-09T18:40:52Z | 1,875,946 | <p>lambda bodies are only expressions, not statements like <code>del</code>.</p>
<p>If you <em>have</em> to use map and lambda, then:</p>
<pre><code>map(lambda d: d.pop('k1'), list_of_d)
</code></pre>
<p>A for loop is probably clearer:</p>
<pre><code>for d in list_of_d:
del d['k1']
</code></pre>
| 12 | 2009-12-09T18:43:27Z | [
"python",
"dictionary",
"lambda"
] |
How can I access an uploaded file in universal-newline mode? | 1,875,956 | <p>I am working with a file uploaded using Django's <code>forms.FileField</code>. This returns an object of type <code>InMemoryUploadedFile</code>.</p>
<p>I need to access this file in universal-newline mode. Any ideas on how to do this without saving and then reopening the file?</p>
<p>Thanks</p>
| 14 | 2009-12-09T18:45:07Z | 1,979,878 | <p>If you are using Python 2.6 or higher, you can use the <code>io.StringIO</code> class after having read your file into memory (using the read() method). Example:</p>
<pre><code>>>> import io
>>> s = u"a\r\nb\nc\rd"
>>> sio = io.StringIO(s, newline=None)
>>> sio.readlines()
[u'a\n... | 12 | 2009-12-30T12:11:35Z | [
"python",
"django",
"django-forms"
] |
Search Python list and return 2 or more of the same character | 1,875,989 | <p>I've just started to learn Python and I'm creating the game Hangman. I've got the basic functionality down. I have a list containing the words and they're randomly selected. I have an input for the user to guess letters and check it against the list that the word is split into, I have another list that the correctly... | 0 | 2009-12-09T18:48:15Z | 1,876,021 | <p>You need to loop over all matching indices:</p>
<pre><code>for word_index, letter in enumerate(letter_list):
if letter == user_input:
correct_letters[word_index] = user_input
</code></pre>
<p><em>Note:</em> If the loop would be <code>for letter in letter_list:</code> you would only iterate over letters... | 4 | 2009-12-09T18:52:03Z | [
"python",
"list"
] |
Search Python list and return 2 or more of the same character | 1,875,989 | <p>I've just started to learn Python and I'm creating the game Hangman. I've got the basic functionality down. I have a list containing the words and they're randomly selected. I have an input for the user to guess letters and check it against the list that the word is split into, I have another list that the correctly... | 0 | 2009-12-09T18:48:15Z | 1,878,016 | <p>You can use a list comprehension: </p>
<pre><code>correct_letters = [letter if user_input == letter else correct
for (correct, letter) in zip(correct_letters, letter_list)]
</code></pre>
<p>Note that this will create a new <code>correct_letters</code> list, instead
of modifying the original one... | 0 | 2009-12-10T01:03:35Z | [
"python",
"list"
] |
Python: How do I dynamically alter methods of dict and list objects? | 1,876,028 | <p>Here is a mockup of what I want to do:</p>
<pre><code>alist = [1,2,3,4,5] # create a vanilla python list object
replacef (alist) # replace __setitem__, extend,... with custom functions
alist[0]=2 # now the custom __setitem__ is called
</code></pre>
<p>This is for a DSL project where the syntax sh... | 3 | 2009-12-09T18:53:22Z | 1,876,088 | <p>Maybe you can do the "alist = MyList(1,2,3,4,5)" thing inside the <code>replaceref</code> function? </p>
<pre><code>def replacef(l):
return MyList(l) # Return instance of list subclass that has custom __setitem__
alist = [1,2,3,4,5]
alist = replaceref(alist)
</code></pre>
<p>This way user would still use the ... | 4 | 2009-12-09T19:03:57Z | [
"python",
"list",
"dynamic",
"methods",
"dictionary"
] |
Python: How do I dynamically alter methods of dict and list objects? | 1,876,028 | <p>Here is a mockup of what I want to do:</p>
<pre><code>alist = [1,2,3,4,5] # create a vanilla python list object
replacef (alist) # replace __setitem__, extend,... with custom functions
alist[0]=2 # now the custom __setitem__ is called
</code></pre>
<p>This is for a DSL project where the syntax sh... | 3 | 2009-12-09T18:53:22Z | 1,876,549 | <p>"Explicit is better than implicit." You should just document that your users need to use <code>MyList()</code> instead of <code>list()</code>. You and your users will be happier in the long run.</p>
<p>Ruby allows what you want, by the way. With Ruby, you can open up global objects and just add new behaviors. I... | 2 | 2009-12-09T20:12:26Z | [
"python",
"list",
"dynamic",
"methods",
"dictionary"
] |
Raise of an eoferror for a file | 1,876,100 | <pre><code> import pickle
filename=input('Enter a file name:')
def commands():
f=open(filename,'w')
names=[]
grades=[]
while True:
name=input("Give a student's name:")
if name.lower()=='end':
f.close()
print("File closed")
... | 0 | 2009-12-09T19:06:21Z | 1,876,129 | <p>You're running into the end of the file "EOF" before your program expects to.</p>
| 1 | 2009-12-09T19:11:15Z | [
"python",
"file",
"eoferror"
] |
Raise of an eoferror for a file | 1,876,100 | <pre><code> import pickle
filename=input('Enter a file name:')
def commands():
f=open(filename,'w')
names=[]
grades=[]
while True:
name=input("Give a student's name:")
if name.lower()=='end':
f.close()
print("File closed")
... | 0 | 2009-12-09T19:06:21Z | 1,876,293 | <p>I would suggest keeping the students/grades in a dictionary. If the user has finished her input, <code>pickle</code> the dictionary into a file. Like</p>
<pre><code>grades = {}
while True:
# ask for student's name n
# ...
if n.lower() == 'end':
break
# ask for student's grade g
# ...
... | 1 | 2009-12-09T19:38:23Z | [
"python",
"file",
"eoferror"
] |
Raise of an eoferror for a file | 1,876,100 | <pre><code> import pickle
filename=input('Enter a file name:')
def commands():
f=open(filename,'w')
names=[]
grades=[]
while True:
name=input("Give a student's name:")
if name.lower()=='end':
f.close()
print("File closed")
... | 0 | 2009-12-09T19:06:21Z | 1,876,309 | <p>The problem is that the <code>myfunc</code> function reopens the file on each iteration, deleting its contents. You should move the <code>open</code> call to before the while loop.</p>
| 0 | 2009-12-09T19:40:38Z | [
"python",
"file",
"eoferror"
] |
Raise of an eoferror for a file | 1,876,100 | <pre><code> import pickle
filename=input('Enter a file name:')
def commands():
f=open(filename,'w')
names=[]
grades=[]
while True:
name=input("Give a student's name:")
if name.lower()=='end':
f.close()
print("File closed")
... | 0 | 2009-12-09T19:06:21Z | 1,877,926 | <p>You have the error <code>global name 'names' is not defined</code> because you have declare <code>names</code> within <code>def entoles()</code> and is only seen within this scope.</p>
<p>You have to declare <code>names</code> outside the <code>dev entoles()</code> if you want to be able to access it.</p>
<p>Also... | 1 | 2009-12-10T00:37:59Z | [
"python",
"file",
"eoferror"
] |
How to get the REMOTE_PORT (the client port) in Python running at IIS 7.5? REMOTE_PORT server variable cannot be found! | 1,876,131 | <p>Hey. I'm coding a cgi in Python, running on an IIS 7.5 web server, on Windows. I would like to get the tcp port (usually was the server environment variable REMOTE_PORT) from which the client is connecting to it. </p>
<p>I've tried to look up all the way throuhout the keys as in os.environ.keys() and I can get the ... | 0 | 2009-12-09T19:11:25Z | 1,876,246 | <p>Googling suggests people with ASP.NET and PHP solutions have similar problems and that since <a href="http://support.microsoft.com/kb/319083" rel="nofollow">IIS 5.0 that variable hasn't been available</a>. I get the impression you have to call a routine called GetServerVariable() to retrieve it. That routine sound... | 0 | 2009-12-09T19:31:34Z | [
"python",
"windows",
"iis-7",
"cgi"
] |
Django & customising a legacy database | 1,876,163 | <p>I'm currently working on a project to implement a Django interface to an existing calendar application. The calendar application has MySQL as the backend DB.</p>
<p>In our custom application we would like to modify/extend the data in one of the tables used by the existing calendar application e.g.</p>
<pre><code>#... | 1 | 2009-12-09T19:17:03Z | 1,877,217 | <p>It appears that you are trying to extend CalendarEvent with more fields.</p>
<p>First, I would make this change to CustomCalendarEvent:</p>
<p><strike><code>code = models.CharField(max_length=80) # Mapped from name</code></strike></p>
<p><code>calendar_event = models.ForeignKey(CalendarEvent)</code></p>
<p... | 2 | 2009-12-09T22:00:42Z | [
"python",
"django",
"legacy-database"
] |
Django & customising a legacy database | 1,876,163 | <p>I'm currently working on a project to implement a Django interface to an existing calendar application. The calendar application has MySQL as the backend DB.</p>
<p>In our custom application we would like to modify/extend the data in one of the tables used by the existing calendar application e.g.</p>
<pre><code>#... | 1 | 2009-12-09T19:17:03Z | 1,879,709 | <p>Why don't you use model inheritance? <code>CustomCalendarEvent</code> can inherit from <code>CalendarEvent</code> and add the new fields that way.</p>
| 2 | 2009-12-10T09:13:58Z | [
"python",
"django",
"legacy-database"
] |
Explain Python .join() | 1,876,191 | <p>I'm pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.</p>
<p>I try:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring().join(strid)
</code></pre>
<p>and get somet... | 92 | 2009-12-09T19:22:04Z | 1,876,202 | <p>join() is for concatenating all list elements. For concatenating just two strings "+" would make more sense:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring() + strid
</code></pre>
| 5 | 2009-12-09T19:24:09Z | [
"python",
"list",
"string"
] |
Explain Python .join() | 1,876,191 | <p>I'm pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.</p>
<p>I try:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring().join(strid)
</code></pre>
<p>and get somet... | 92 | 2009-12-09T19:22:04Z | 1,876,204 | <p><code>join</code> takes an iterable thing as an argument. Usually it's a list. The problem in your case is that a string is itself iterable, giving out each character in turn. Your code breaks down to this:</p>
<pre><code>"wlfgALGbXOahekxSs".join("595")
</code></pre>
<p>which acts the same as this:</p>
<pre><co... | 51 | 2009-12-09T19:24:45Z | [
"python",
"list",
"string"
] |
Explain Python .join() | 1,876,191 | <p>I'm pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.</p>
<p>I try:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring().join(strid)
</code></pre>
<p>and get somet... | 92 | 2009-12-09T19:22:04Z | 1,876,206 | <p>Look carefully at your output:</p>
<pre><code>5wlfgALGbXOahekxSs9wlfgALGbXOahekxSs5
^ ^ ^
</code></pre>
<p>I've highlighted the "5", "9", "5" of your original string. The Python <a href="https://docs.python.org/3/library/stdtypes.html#str.join"><code>join()</code></a> method is a st... | 162 | 2009-12-09T19:25:02Z | [
"python",
"list",
"string"
] |
Explain Python .join() | 1,876,191 | <p>I'm pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.</p>
<p>I try:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring().join(strid)
</code></pre>
<p>and get somet... | 92 | 2009-12-09T19:22:04Z | 1,876,211 | <p>To append a string, just concatenate it with the <code>+</code> sign.</p>
<p>E.g.</p>
<pre><code>>>> a = "Hello, "
>>> b = "world"
>>> str = a + b
>>> print str
Hello, world
</code></pre>
<p><code>join</code> connects strings together with a separator. The separator is what you... | 19 | 2009-12-09T19:26:13Z | [
"python",
"list",
"string"
] |
Explain Python .join() | 1,876,191 | <p>I'm pretty new to Python and am completely confused by .join() which I have read is the preferred method for concatenating strings.</p>
<p>I try:</p>
<pre><code>strid = repr(595)
print array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring().join(strid)
</code></pre>
<p>and get somet... | 92 | 2009-12-09T19:22:04Z | 1,877,009 | <p>To expand a bit more on what others are saying, if you wanted to use join to simply concatenate your two strings, you would do this:</p>
<pre><code>strid = repr(595)
print ''.join([array.array('c', random.sample(string.ascii_letters, 20 - len(strid)))
.tostring(), strid])
</code></pre>
| 1 | 2009-12-09T21:26:13Z | [
"python",
"list",
"string"
] |
Proper help for arguments | 1,876,289 | <p>Python optparse works very good when script usage is something like this</p>
<pre><code>%prog [options] [args]
</code></pre>
<p>But I need to write help for script with 1 required argument, so usage will be like this</p>
<pre><code>%prog action [options] [args]
</code></pre>
<p>You can see something similar when... | 2 | 2009-12-09T19:37:25Z | 1,876,321 | <p>Yes. You can set the usage string like this:</p>
<pre><code>usage = "%prog action [options] [args]"
parser = OptionParser(usage=usage)
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=True,
help="make lots of noise [default]")
</code></pre>
<p>P... | 2 | 2009-12-09T19:43:05Z | [
"python",
"optparse"
] |
Proper help for arguments | 1,876,289 | <p>Python optparse works very good when script usage is something like this</p>
<pre><code>%prog [options] [args]
</code></pre>
<p>But I need to write help for script with 1 required argument, so usage will be like this</p>
<pre><code>%prog action [options] [args]
</code></pre>
<p>You can see something similar when... | 2 | 2009-12-09T19:37:25Z | 1,876,338 | <p>I think a good solution for you is <a href="http://code.google.com/p/argparse/" rel="nofollow">argparse</a>, which has been <a href="http://www.python.org/dev/peps/pep-0389/" rel="nofollow">proposed for inclusion in Python 2.7 and 3.2</a>. It handles subcommands, I believe as you want, and the linked page includes ... | 7 | 2009-12-09T19:45:39Z | [
"python",
"optparse"
] |
Proper help for arguments | 1,876,289 | <p>Python optparse works very good when script usage is something like this</p>
<pre><code>%prog [options] [args]
</code></pre>
<p>But I need to write help for script with 1 required argument, so usage will be like this</p>
<pre><code>%prog action [options] [args]
</code></pre>
<p>You can see something similar when... | 2 | 2009-12-09T19:37:25Z | 1,876,449 | <p>I've run into this problem as well. My solution was to declare commands in a list or tuple, format them into the <code>usage</code> parameter of OptionParser and then use the args list provided by the parser to determine if a command was provided or not, since it technically has to be <code>args[0]</code>. Eg:</p>
... | 0 | 2009-12-09T20:01:59Z | [
"python",
"optparse"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,876,657 | <p>Your code is going to be doing the "if not prev" test every time round the loop, even though it only applies to the first element.
Also your code seems broken to me - the first time round the loop the prev and current values are the same.</p>
<p>I would do it like this, assuming that there is at least one element:<... | 3 | 2009-12-09T20:28:07Z | [
"python",
"loops"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,876,681 | <p>This code generates NameError because at <code>if not prev</code>, prev is not defined. Set it to False or None before the cycle. Also you may make a different loop:</p>
<pre><code>for i in xrange(1, len(tmp)):
print 'seq: {0}, prev seq: {1}, variance: {2}'.format(tmp[i][1], tmp[i - 1][1], tmp[i] - tmp[i - 1][1... | 0 | 2009-12-09T20:32:27Z | [
"python",
"loops"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,876,741 | <p>Just iterate over pairs, using <code>zip()</code>, which is much more readable.</p>
<p><strong>UPDATE:</strong> for python 2.x, use <code>itertools.izip</code> instead as it is more efficient!</p>
<pre><code>from itertools import izip
for prev, next in izip(tmp, tmp[1:]):
print 'seq: ', next[1], 'prev seq:', p... | 4 | 2009-12-09T20:41:53Z | [
"python",
"loops"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,877,445 | <pre><code>it = imap(operator.itemgetter(1), tmp) # get all 2nd items
prev = next(it, None) # get 1st element (doesn't throw exception for empty `tmp`)
for x in it:
print 'seq: %s prev seq: %s variance: %s' % (x, prev, x-prev)
prev = x
</code></pre>
| 0 | 2009-12-09T22:42:55Z | [
"python",
"loops"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,877,902 | <p>Using <code>itertools</code>:</p>
<pre><code>from itertools import izip, islice
for prev, cur in izip(l, islice(l, 1, None)):
print 'seq:', cur[1], 'prev seq:', prev[1], 'delta:', cur[1]-prev[1]
</code></pre>
<p>For the specific example given in the question, note that, if the numbers
can be represented using ... | 2 | 2009-12-10T00:27:53Z | [
"python",
"loops"
] |
Optimal way to access a value from the last iteration in a loop | 1,876,587 | <p>What's the best and fastest way to access a value from the previous iteration in a for loop, assuming that the object will be very large (example, a cursor object which has 100,000+ records) </p>
<p>Using a simple example:</p>
<pre><code>tmp = [
['xyz', 335], ['zzz', 338], ['yyy', 339], ['yyy', 442],
... | 3 | 2009-12-09T20:17:51Z | 1,877,915 | <p>Guido's time machine to the rescue!</p>
<p>From the <a href="http://docs.python.org/library/itertools.html#recipes" rel="nofollow">itertools recipes</a> page:</p>
<pre><code>import itertools
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
... | 1 | 2009-12-10T00:32:20Z | [
"python",
"loops"
] |
how to auto-update a Django page only when required? | 1,876,625 | <p>As described in <a href="http://stackoverflow.com/questions/1836861/how-to-update-a-django-page-without-a-page-reload">http://stackoverflow.com/questions/1836861/how-to-update-a-django-page-without-a-page-reload</a>, I send periodic XMLHTTPRequests from the browser to the server using JavaScript to get those pieces ... | 2 | 2009-12-09T20:24:08Z | 1,877,367 | <p>The difficulty in answering is in not knowing what the server-side resources are that are being returned to the user.</p>
<p>I'll make up something which may serve as an example. Let's say you were developing an application that allowed you to monitor in real-time comments being made by users on your site. We can... | 7 | 2009-12-09T22:26:27Z | [
"javascript",
"python",
"ajax",
"django"
] |
why is python reusing a class instance inside in function | 1,876,905 | <p>I'm running a for loop inside a function which is creating instances of a class to test them. instead of making new classes it appears to be reusing the same two over and over.</p>
<p>Is there something I'm missing about how classes and variables are handled in python methods?</p>
<p>how can I generate a new objec... | 6 | 2009-12-09T21:11:02Z | 1,877,006 | <p>All that shows is that the memory of the objects is being reused, not that new objects aren't being instantiated. In each iteration <code>collection</code> is being overwritten, hence the previous object's reference count drops and the Python interpreter is free to deallocate its memory and reuse it (for the next ob... | 11 | 2009-12-09T21:26:05Z | [
"python",
"namespaces",
"class"
] |
why is python reusing a class instance inside in function | 1,876,905 | <p>I'm running a for loop inside a function which is creating instances of a class to test them. instead of making new classes it appears to be reusing the same two over and over.</p>
<p>Is there something I'm missing about how classes and variables are handled in python methods?</p>
<p>how can I generate a new objec... | 6 | 2009-12-09T21:11:02Z | 1,877,020 | <p>from python documentation:</p>
<p>id()
Return the âidentityâ of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.</p>
| 3 | 2009-12-09T21:28:46Z | [
"python",
"namespaces",
"class"
] |
Loading a wave from waveid | 1,876,908 | <p>I'm working on a small wave thingy where i need to load a wave based on an outside event. So i don't have a context to work with.</p>
<p>I've been looking at the python api for a while but i can't figure out the correct way to get a wave object (that i can then call CreateBlip() on) when i just have the waveid.</p>... | 1 | 2009-12-09T21:11:09Z | 1,932,852 | <p>At the moment the answer is that i can't be done. Hopefully in a future version of the Api. </p>
| 0 | 2009-12-19T12:54:28Z | [
"python",
"google-wave"
] |
Loading a wave from waveid | 1,876,908 | <p>I'm working on a small wave thingy where i need to load a wave based on an outside event. So i don't have a context to work with.</p>
<p>I've been looking at the python api for a while but i can't figure out the correct way to get a wave object (that i can then call CreateBlip() on) when i just have the waveid.</p>... | 1 | 2009-12-09T21:11:09Z | 2,916,050 | <p>At Google I/O, the <a href="http://code.google.com/apis/wave/extensions/wavedataapi/index.html" rel="nofollow">Wave Data API</a> was announced which allows for pulling waves which haven't previously gotten a context as long as they're accessible to a @googlewave.com user authenticated through OAuth. However, this ca... | 1 | 2010-05-26T19:20:01Z | [
"python",
"google-wave"
] |
Textbox Change Event | 1,877,220 | <p>What two things need to happen for a text box's change event to fire?</p>
| 0 | 2009-12-09T22:01:44Z | 1,877,252 | <ol>
<li>Textbox gets focus</li>
<li>User types in textbox...</li>
</ol>
| 0 | 2009-12-09T22:06:17Z | [
"python"
] |
Textbox Change Event | 1,877,220 | <p>What two things need to happen for a text box's change event to fire?</p>
| 0 | 2009-12-09T22:01:44Z | 1,877,513 | <p>If you are talking about the onchange event on an HTML text or textarea element, it's after the value in a textbox has changed and the focus changes away from that element.</p>
| 0 | 2009-12-09T22:58:46Z | [
"python"
] |
Textbox Change Event | 1,877,220 | <p>What two things need to happen for a text box's change event to fire?</p>
| 0 | 2009-12-09T22:01:44Z | 1,882,870 | <p>@Chris-You are on the right track. Actually its when The cursor gets moved into the control and When control gains focus.</p>
| 0 | 2009-12-10T18:04:26Z | [
"python"
] |
Is it possible to make a custom mouse cursor with Python Tkinter? (Using matplotlib with the TkAgg backend) | 1,877,360 | <p>It's likely that this is just a general Python Tkinter question, not necessarily a matplotlib one.</p>
<p>So I'm in the midst of developing a rather large suite of plotting functionality on top of matplotlib using the Matplotlib "TkAgg" backend (Agg rendering to a Tk canvas using TkInter). I'm using some of the de... | 2 | 2009-12-09T22:25:08Z | 1,882,362 | <p>Something like this works with unix X11 XBM files:</p>
<pre><code>import Tkinter
t = Tkinter.Tk()
t.configure(cursor=('@/usr/include/X11/bitmaps/star', '/usr/include/X11/bitmaps/starMask', 'black', 'white'))
t.mainloop()
</code></pre>
<p>As for the Macs, from the man page for "Tk_GetCursorFromData":</p>
<blockquo... | 3 | 2009-12-10T16:53:34Z | [
"python",
"matplotlib",
"tkinter",
"mouse-cursor"
] |
wxPython: Handling drag-and-drop in a parent object - problem with event propagation | 1,877,402 | <p>I have a wxPython program where I want to be able to drag groups of controls around to reorder them. Each group of controls is on a panel, and I want the panel object to handle the drag-and-drop.</p>
<p>Currently it works if you click and drag on the panel itself, but it doesn't work if you click on any control in... | 0 | 2009-12-09T22:32:24Z | 1,935,002 | <p>IMO the best way is, Panel should bind to control's <code>wx.EVT_LEFT_DOWN</code> and drag only when special key combination e.g. cntrl-alt-d are pressed</p>
<p>Panel can do it recursively or have a function in Panel, addControl and only such control will be hooked.</p>
<p>Your point that "individual controls may ... | 1 | 2009-12-20T05:56:50Z | [
"python",
"drag-and-drop",
"wxpython"
] |
wxPython: Handling drag-and-drop in a parent object - problem with event propagation | 1,877,402 | <p>I have a wxPython program where I want to be able to drag groups of controls around to reorder them. Each group of controls is on a panel, and I want the panel object to handle the drag-and-drop.</p>
<p>Currently it works if you click and drag on the panel itself, but it doesn't work if you click on any control in... | 0 | 2009-12-09T22:32:24Z | 5,763,065 | <p>I realize this is rather late, but in case it's still helpful to someone:</p>
<p>I've done this in the code in <a href="http://stackoverflow.com/questions/5761570/how-to-move-items-smoothly-in-wxpython">my (related) question</a>: </p>
<pre><code>import wx
app = wx.App(False)
d = {}
def wMouseDown(e):
print "... | 2 | 2011-04-23T08:04:51Z | [
"python",
"drag-and-drop",
"wxpython"
] |
Setting numpy slice in lambda function | 1,877,437 | <p>I want to create a lambda function that takes two numpy arrays and sets a slice of the first to the second and returns the newly set numpy array.</p>
<p>Considering you can't assign things in lambda functions is there a way to do something similar to this?</p>
<p>The context of this is that I want to set the centr... | 2 | 2009-12-09T22:40:54Z | 1,877,755 | <p>This is ugly; you should not use it. But it is oneline lambda as you've asked:</p>
<pre><code>f = lambda b, a=None, s=slice(1,-1): f(b, numpy.zeros(numpy.array(b.shape) + 2))\
if a is None else (a.__setitem__([s]*a.ndim, b), a)[1]
</code></pre>
<h3>What is <code>__setitem__</code>?</h3>
<p><... | 3 | 2009-12-09T23:41:45Z | [
"python",
"lambda",
"numpy"
] |
Implementing python exceptions | 1,877,686 | <p>I'm having some problems implementing an exception system in my program.
I found somewhere the following piece of code that I am trying to use for my program:</p>
<pre><code>class InvalidProgramStateException(Exception):
def __init__(self, expr, msg):
self.expr = expr
self.msg = msg
</code></pre... | 3 | 2009-12-09T23:26:53Z | 1,877,713 | <p>Check this site: <a href="http://docs.python.org/tutorial/errors.html" rel="nofollow">Error tutorials Python</a></p>
| 2 | 2009-12-09T23:33:13Z | [
"python",
"exception"
] |
Implementing python exceptions | 1,877,686 | <p>I'm having some problems implementing an exception system in my program.
I found somewhere the following piece of code that I am trying to use for my program:</p>
<pre><code>class InvalidProgramStateException(Exception):
def __init__(self, expr, msg):
self.expr = expr
self.msg = msg
</code></pre... | 3 | 2009-12-09T23:26:53Z | 1,877,720 | <p>Your custom exceptions don't actually need to take parameters at all. If you haven't got any particular error message or state to encapsulate in the Exception, this will work just fine:</p>
<pre><code>class MyException(Exception):
pass
</code></pre>
<p>This would allow your program to catch cases of this excep... | 10 | 2009-12-09T23:34:15Z | [
"python",
"exception"
] |
Euclidian distance between posts based on tags | 1,877,725 | <p>I am playing with the euclidian distance example from programming collective intelligence book, </p>
<pre><code>
# Returns a distance-based similarity score for person1 and person2
def sim_distance(prefs,person1,person2):
# Get the list of shared_items
si={}
for item in prefs[person1]:
if item in pre... | 1 | 2009-12-09T23:35:05Z | 1,877,776 | <p>Okay, first off, your code looks incomplete: I see only one return from your function. I think you mean something like this:</p>
<pre><code>def sim_distance(prefs, person1, person2):
# Get the list of shared_items
p1, p2 = prefs[person1], prefs[person2]
si = set(p1).intersection(set(p2))
# Add up the squa... | 1 | 2009-12-09T23:48:59Z | [
"python",
"similarity",
"euclidean-distance"
] |
Euclidian distance between posts based on tags | 1,877,725 | <p>I am playing with the euclidian distance example from programming collective intelligence book, </p>
<pre><code>
# Returns a distance-based similarity score for person1 and person2
def sim_distance(prefs,person1,person2):
# Get the list of shared_items
si={}
for item in prefs[person1]:
if item in pre... | 1 | 2009-12-09T23:35:05Z | 1,877,783 | <p>Basically, tags don't have weights and can't be represented by numerical values. So you can't define a distance between two tags.</p>
<p>If you want to find the similarity between two posts using their tags, I would suggest that you use the ratio of similar tag. For example, if you have</p>
<pre><code>url1 -> t... | 1 | 2009-12-09T23:50:52Z | [
"python",
"similarity",
"euclidean-distance"
] |
Python: "unsupported operand types for +: 'long' and 'numpy.float64' " | 1,877,789 | <p>My program uses genetic techniques to build equations.</p>
<p>It randomly assembles strings into an equation with one unknown.</p>
<pre><code>"(((x + 1) * x) / (4 * 6) ** 2)"
</code></pre>
<p>One of the strings is: "math.factorial(random.randint(1,9))"</p>
<p>So an equation is typically something like: </p>
<p>... | 1 | 2009-12-09T23:51:52Z | 1,877,845 | <p>First, you are missing a closing bracket in your example, and the <code>(+ or - or / or * or **)</code> is confusing.</p>
<p>What are you trying to achieve?
Do you just want to insert the result in the string?
Try this:</p>
<pre><code>for x in numpy.arange(1,6.4,.1):
s = "sinus %f is %f!" % (x, numpy.sin(x))
... | 3 | 2009-12-10T00:09:41Z | [
"python",
"numpy"
] |
Python: "unsupported operand types for +: 'long' and 'numpy.float64' " | 1,877,789 | <p>My program uses genetic techniques to build equations.</p>
<p>It randomly assembles strings into an equation with one unknown.</p>
<pre><code>"(((x + 1) * x) / (4 * 6) ** 2)"
</code></pre>
<p>One of the strings is: "math.factorial(random.randint(1,9))"</p>
<p>So an equation is typically something like: </p>
<p>... | 1 | 2009-12-09T23:51:52Z | 1,877,998 | <p>This works for me:</p>
<pre><code>for x in numpy.arange(1,6.4,.1):
eval("( 1 + (2 * 3) / 4 ) * numpy.sin(x)")
</code></pre>
| 1 | 2009-12-10T00:56:45Z | [
"python",
"numpy"
] |
Request for comments: python class factory for group of constant values | 1,877,830 | <p>The following python module is meant to be a basis for "constant" handling in python. The use case is the following:</p>
<ul>
<li>one groups some constants (basically "names") that belong together with their values into a dictionary</li>
<li>with that dictionary bound to class variable a class is created and instan... | 2 | 2009-12-10T00:04:37Z | 1,877,871 | <p>Most pythonic way is (to me):</p>
<pre><code>my_fav_fruits = ('Apple', 'Orange', 'Strawberry', 'Chocolate Pudding')
lucky_numbers = (13, 7, 4, 99, 256)
</code></pre>
<p>Your design seems to bring some other languages features into python. You could do substitute of interface from java in similar fashion. Define a ... | 1 | 2009-12-10T00:18:19Z | [
"python",
"code-review",
"constants",
"factory"
] |
Request for comments: python class factory for group of constant values | 1,877,830 | <p>The following python module is meant to be a basis for "constant" handling in python. The use case is the following:</p>
<ul>
<li>one groups some constants (basically "names") that belong together with their values into a dictionary</li>
<li>with that dictionary bound to class variable a class is created and instan... | 2 | 2009-12-10T00:04:37Z | 1,877,901 | <p>In the same spirit as Kugel, but noticing that <a href="http://docs.python.org/dev/library/collections.html#collections.namedtuple" rel="nofollow"><code>collections.namedtuple</code></a> is very similar.. it is a tuple, thus immutable, and it has field names. Namedtuple was introduced in Python 2.6.</p>
<p>Here is ... | 3 | 2009-12-10T00:27:43Z | [
"python",
"code-review",
"constants",
"factory"
] |
Request for comments: python class factory for group of constant values | 1,877,830 | <p>The following python module is meant to be a basis for "constant" handling in python. The use case is the following:</p>
<ul>
<li>one groups some constants (basically "names") that belong together with their values into a dictionary</li>
<li>with that dictionary bound to class variable a class is created and instan... | 2 | 2009-12-10T00:04:37Z | 1,877,908 | <p>I think a common idiom is</p>
<pre><code>class numericConstant:
One = 1
Two = 2
#usage
print (numericConstant.One + numericConstant.Two)
</code></pre>
<p>The drawback is that it doesn't prevent someone overwriting the "constant" values, i.e.</p>
<pre><code> numericConstant.One = 7 #oops...
</code></pre... | 1 | 2009-12-10T00:29:42Z | [
"python",
"code-review",
"constants",
"factory"
] |
Request for comments: python class factory for group of constant values | 1,877,830 | <p>The following python module is meant to be a basis for "constant" handling in python. The use case is the following:</p>
<ul>
<li>one groups some constants (basically "names") that belong together with their values into a dictionary</li>
<li>with that dictionary bound to class variable a class is created and instan... | 2 | 2009-12-10T00:04:37Z | 1,877,923 | <p>Your solution seems rather over-engineered. Just make a module and throw in your constants with capital letters.
We are all adults...</p>
<pre><code>#myconstants.py
ONE = 1
TWO = 2
THREE = 3
</code></pre>
| 2 | 2009-12-10T00:35:57Z | [
"python",
"code-review",
"constants",
"factory"
] |
Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError | 1,877,940 | <p>I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception.</p>
<p>I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther.</p>
<p>Info:</p>
... | 3 | 2009-12-10T00:42:23Z | 1,881,085 | <p>The error message is indicated that it can't find a reverse url for:</p>
<pre><code>
django.contrib.comments.views.comments.post_comment
</code></pre>
<p>So basically something isn't configured right in your urls. Without being able to see more of how things are setup it's difficult to know exactly what.</p>
... | 1 | 2009-12-10T13:47:31Z | [
"python",
"django",
"exception",
"django-templates",
"django-comments"
] |
Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError | 1,877,940 | <p>I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception.</p>
<p>I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther.</p>
<p>Info:</p>
... | 3 | 2009-12-10T00:42:23Z | 1,889,676 | <p>I had this same problem today. I was referencing a view in urls.py that I hadn't created yet.</p>
<p>From <a href="http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse</a></p>
<blockquote>
<p>As part of working out which UR... | 1 | 2009-12-11T17:40:36Z | [
"python",
"django",
"exception",
"django-templates",
"django-comments"
] |
Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError | 1,877,940 | <p>I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception.</p>
<p>I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther.</p>
<p>Info:</p>
... | 3 | 2009-12-10T00:42:23Z | 1,898,800 | <p>This error is saying that it found the view <code>django.contrib.comments.views.comments.post_comment</code></p>
<p>but no args () or kwargs{} were passed. </p>
<p>Its not passing a value for object.id into the url.</p>
<p>Take out the url tag and see if the id of the <code><div id="post_{{object.id}}"></co... | 1 | 2009-12-14T03:46:47Z | [
"python",
"django",
"exception",
"django-templates",
"django-comments"
] |
Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError | 1,877,940 | <p>I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception.</p>
<p>I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther.</p>
<p>Info:</p>
... | 3 | 2009-12-10T00:42:23Z | 8,685,498 | <p>I had the same exact problem, render_comment_form template tag was triggering it.</p>
<p>The issue is certainly with your URL config, you had it set the same way i did:</p>
<pre><code>(r'^comments/$', include('django.contrib.comments.urls'))
</code></pre>
<p><strong>The correct way is to remove the '$' after 'com... | 6 | 2011-12-31T00:54:14Z | [
"python",
"django",
"exception",
"django-templates",
"django-comments"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,013 | <p>You could use the above code and then:-</p>
<pre><code>lines = file.readlines()
lines = lines[:-1]
</code></pre>
<p>This would give you an array of lines containing all lines but the last one.</p>
| 6 | 2009-12-10T01:01:08Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,056 | <p>This doesn't use python, but python's the wrong tool for the job if this is the only task you want. You can use the standard *nix utility <code>head</code>, and run</p>
<pre><code>head -n-1 filename > newfile
</code></pre>
<p>which will copy all but the last line of filename to newfile.</p>
| 7 | 2009-12-10T01:13:51Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,062 | <p>On systems where <a href="http://docs.python.org/library/stdtypes.html#file.truncate" rel="nofollow">file.truncate()</a> works, you could do something like this:</p>
<pre><code>file = open('file.txt', 'rb')
pos = next = 0
for line in file:
pos = next # position of beginning of this line
next += len(line) # comp... | 3 | 2009-12-10T01:15:03Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,079 | <p>Assuming you have to do this in Python and that you have a large enough file that list slicing isn't sufficient, you can do it in a single pass over the file:</p>
<pre><code>last_line = None
for line in file:
if last_line:
print last_line # or write to a file, call a function, etc.
last_line = line
... | 3 | 2009-12-10T01:18:05Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,138 | <p>Though I have not tested it (please, no hate for that) I believe that there's a faster way of going it. It's more of a C solution, but quite possible in Python. It's not Pythonic, either. It's a theory, I'd say.</p>
<p>First, you need to know the encoding of the file. Set a variable to the number of bytes a charac... | 0 | 2009-12-10T01:36:31Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,308 | <p>here's another way, without slurping the whole file into memory</p>
<pre><code>p=""
f=open("file")
for line in f:
line=line.strip()
print p
p=line
f.close()
</code></pre>
| 0 | 2009-12-10T02:32:11Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 1,878,338 | <p>Here's a more general memory-efficient solution allowing the last 'n' lines to be skipped (like the <code>head</code> command):</p>
<pre><code>import collections, fileinput
def head(filename, lines_to_delete=1):
queue = collections.deque()
lines_to_delete = max(0, lines_to_delete)
for line in fileinput... | 0 | 2009-12-10T02:41:55Z | [
"python",
"text",
"line"
] |
Delete final line in file via python | 1,877,999 | <p>How can one delete the very last line of a file via python?</p>
<p>Example File:</p>
<pre><code>hello
world
foo
bar
</code></pre>
<p>Resulatant File:</p>
<pre><code>hello
world
foo
</code></pre>
<p>I've created the following code to find the number of lines in the file - but I do not know how to delete the spec... | 14 | 2009-12-10T00:57:00Z | 10,289,740 | <p>Because I routinely work with many-gigabyte files, looping through as mentioned in the answers didn't work for me. The solution I use:</p>
<pre><code>file = open(sys.argv[1], "r+", encoding = "utf-8")
#Move the pointer (similar to a cursor in a text editor) to the end of the file.
file.seek(0, os.SEEK_END)
#This... | 32 | 2012-04-23T23:32:06Z | [
"python",
"text",
"line"
] |
Django URLs configuration debugging? | 1,878,096 | <p>What's the best method to debug Django's url configurations? Sometime it just throw out a Unhandled Exception without any hints if there is an error in urls.py</p>
<p>Sometimes it throws out errors like "unbalanced parenthesis" but I still dont know which line in urls.py caused the error.</p>
| 0 | 2009-12-10T01:21:29Z | 1,878,135 | <p>For underlying application errors, I sometimes find it helpful to toggle the value of <code>TEMPLATE_DEBUG</code> in <code>settings.py</code> (<a href="http://docs.djangoproject.com/en/dev/ref/settings/#template-debug" rel="nofollow">django docs here</a>). Often this gives me the backtrace I need to spot syntax erro... | 2 | 2009-12-10T01:35:42Z | [
"python",
"django",
"url",
"debugging"
] |
Django URLs configuration debugging? | 1,878,096 | <p>What's the best method to debug Django's url configurations? Sometime it just throw out a Unhandled Exception without any hints if there is an error in urls.py</p>
<p>Sometimes it throws out errors like "unbalanced parenthesis" but I still dont know which line in urls.py caused the error.</p>
| 0 | 2009-12-10T01:21:29Z | 15,953,050 | <p>for unbalanced parenthises and other such syntax errors, I find it useful to run pylint on the file. If you use vim, there is a plugin to automatically do this upon save <a href="https://github.com/orenhe/pylint.vim" rel="nofollow">https://github.com/orenhe/pylint.vim</a></p>
| 0 | 2013-04-11T15:37:38Z | [
"python",
"django",
"url",
"debugging"
] |
Count Parenthesis in a file with a Python program? | 1,878,167 | <p>I Wanna fix a function through it i can count how many times are used the:(,),[,]
if the counts of ( are equal to those of )
and if the counts of [ are equal to those of ]
then i have valid syntax!</p>
<p>my first -dissapointed- try:</p>
<pre><code>filename=input("Give a file name:")
def parenthesis(filename):
... | 0 | 2009-12-10T01:45:40Z | 1,878,183 | <p>Do you want to ensure that they parens & braces are matched? That "[(])" fails? If not, you're along the right path, except that you need to change your "=" to "+=". You're discarding the values of previous lines.</p>
| 0 | 2009-12-10T01:50:12Z | [
"python",
"exception",
"file",
"parentheses"
] |
Count Parenthesis in a file with a Python program? | 1,878,167 | <p>I Wanna fix a function through it i can count how many times are used the:(,),[,]
if the counts of ( are equal to those of )
and if the counts of [ are equal to those of ]
then i have valid syntax!</p>
<p>my first -dissapointed- try:</p>
<pre><code>filename=input("Give a file name:")
def parenthesis(filename):
... | 0 | 2009-12-10T01:45:40Z | 1,878,201 | <p>I think if you change the:</p>
<pre><code> if line=='(':
c1=line.count('(')
elif line==')':
c2=line.count(')')
elif line=='[':
c3=line.count('[')
elif line==']':
c4=line.count(']')
elif lin... | 1 | 2009-12-10T01:55:18Z | [
"python",
"exception",
"file",
"parentheses"
] |
Count Parenthesis in a file with a Python program? | 1,878,167 | <p>I Wanna fix a function through it i can count how many times are used the:(,),[,]
if the counts of ( are equal to those of )
and if the counts of [ are equal to those of ]
then i have valid syntax!</p>
<p>my first -dissapointed- try:</p>
<pre><code>filename=input("Give a file name:")
def parenthesis(filename):
... | 0 | 2009-12-10T01:45:40Z | 1,878,202 | <p>Remove the 'while True' line and this bit:</p>
<pre><code>elif line=='':
break
</code></pre>
<p>and then replace this:</p>
<pre><code>for line in filename:
line=f.readline()
</code></pre>
<p>with this:</p>
<pre><code>for line in f:
</code></pre>
<p>Now you'll be looping over the lines in the file.</p>
... | 1 | 2009-12-10T01:55:31Z | [
"python",
"exception",
"file",
"parentheses"
] |
Count Parenthesis in a file with a Python program? | 1,878,167 | <p>I Wanna fix a function through it i can count how many times are used the:(,),[,]
if the counts of ( are equal to those of )
and if the counts of [ are equal to those of ]
then i have valid syntax!</p>
<p>my first -dissapointed- try:</p>
<pre><code>filename=input("Give a file name:")
def parenthesis(filename):
... | 0 | 2009-12-10T01:45:40Z | 1,878,210 | <p>My solution will try to help you understand a bit more precise way of doing this, and hopefully you'll learn a bit about data structures in the process.</p>
<p>To <em>properly</em> do this, you're going to want to use a <a href="http://en.wikipedia.org/wiki/Stack%5F%28data%5Fstructure%29" rel="nofollow"><strong>sta... | 0 | 2009-12-10T02:00:20Z | [
"python",
"exception",
"file",
"parentheses"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.