python

Python - functions being called inside list bracket. How does it work?

I was looking for an algorithm to replace some content inside a list with another. For instance, changing all the '0' with 'X'. I found this piece of code, which works: list = ['X' if coord == '0' else coord for coord in printready] What I would like to know is exactly why this works (I understand the logic in the code, just not why...

What do these arguments refer to?

In the method of the class urllib2.HTTPDefaultErrorHandler what so the arguments - self, req, fp, code,msg, hdrs - refer to? ...

gtk: why do Gtk::Main::Iteration?

What's the point of doing the Gtk::Main::iteration() on the last two lines of the answer to this question? I'm using pygtk, so the equivalent question would be, why do gtk.main_iteration_do()? Isn't the main loop that's running already taking care of this? ...

Unable to print variables in Python when using def function

I am trying to implement a simple neural net. I want to print the initial pattern, weights, activation. I then want it to print the learning process (i.e. every pattern it goes through as it learns). I am as yet unable to do this - it returns the initial and final pattern (whn I put print p in appropriate places), but nothing else. Hints...

Can anyone tell me why I'm getting this error in SOAPpy?

server = SOAPpy.WSDL.Proxy(wdf) Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> server = SOAPpy.WSDL.Proxy(wdf) File "C:\Python27\lib\soapy\SOAPpy\WSDL.py", line 62, in __init__ self.wsdl = reader.loadFromStream(stream, wsdlsource) File "C:\Python27\lib\soapy\SOAPpy\wstools\WSDLTools.py", line 2...

Is it typical to have more than a dozen django applications in your project root for medium-high scale sites? Does it not feel bloated?

I was looking at the INSTALLED_APPS of django-mingus: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.sitemaps', 'django.contrib.flatpages', 'django.contrib.redirects', 'django_extensions', 'tagging', ...

How to display an image from web ?

I have written this simple script in python: import gtk window = gtk.Window() window.set_size_request(800, 700) window.show() gtk.main() now I want to load in this window an image from web ( and not from my PC ) like this: http://www.dailygalaxy.com/photos/uncategorized/2007/05/05/planet_x.jpg How can I do that ? P.S. I don't wan...

python regex question

What is the best way to search for matching words inside a string? Right now I do something like the following: if re.search('([h][e][l][l][o])',file_name_tmp, re.IGNORECASE): Which works but its slow as I have probably around 100 different regex statements searching for full words so I'd like to combine several using a | separator o...

Python: removing a TKinter frame

I want to remove a frame from my interface when a specific button is clicked. This is the invoked callback function def removeMyself(self): del self However, it doesn't remove itself. I'm probably just deleting the object in python without updating the interface ? thanks Update self.itemFrame = tk.Frame(parent) self.itemFrame....

Handle GPS Coordinate in Django

What is the best way to manage GPS coordinates (latitude and longitude) in django models ? I know that there is a module called GeoDjango but reading the tutorial seems dedicated to GIS and not simply to manage the latitude and longitude. I do not care to have convenient interface for the admin because int the application I'm creatin th...

Setting individual pixels in Pyglet

Is there a way to set individual pixel values for image data in Pyglet? I guess it can also be done by setting the OpenGL rendering mode to points, so if someone has insight on this, please share it as well. ...

Why wouldn't GAE store my logging.debug?

It seems logging.debug() doesn't appear in GAE logs, but logging.error() does. Does anyone have an idea how can I make logging.debug() appear in the GAE logs? ...

General convention for python libraries that also have an interface module?

Right now I've got a project that has the following layout: foo/ __init__.py __main__.py foo.py In this case, foo.py is actually the main api file, so developers are meant to do "from foo import foo", but I also wanted to make it so that end users could just run ~$ foo and get an interface. which, when I do a distutils install,...

How to display all words that contain these characters ?

I have a text file and I want to display all words that contains both z and x characters. How can I do that ? ...

Minimize subqueries with IN queries on AppEngine (python)

Is there any clever way to avoid making a costly query with an IN clause in cases like the following one? I'm using Google App Engine to build a Facebook application and at some point I (obviously) need to query the datastore to get all the entities that belong to any of the facebook friends of the given user. Suppose I have a couple o...

How to specify users/emails that get notified about new comments in Django?

Possible Duplicate: Django notification on comment submission How can I specify which users get notified about new comments using Django's comment and moderation framework? In the documentation it says that the site staff will get an email notification, but when I'm posting a new comment only the very first user (the one that ...

Accept lowercase or uppercase letter in Python

Working on a menu display where the letter "m" takes the user back to the main menu. How can I have it so that it works regardless if the letter "m" is uppercase or lowercase? elif choice == "m": ...

Pymacs error starting Emacs after installing Python

I installed python using one of the msi files. But when I start up emacs, it gives me: Problem 1, which I thought I'd fixed When I run cmd and type in python, I get "python" is not recognized as an internal or external command, operable program or batch file. So from online sources, (windows 7 btw) Went to System Properties and Envi...

TKinter: How can I set the default value of my slider to 100 ?

How can I set the default value of my slider to 100 ? self.slider = tk.Scale(self.leftFrame, from_=0, to=256, orient=tk.HORIZONTAL, command=updateValue) thanks ...

What makes some programming languages more powerful than others?

I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class. I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wonderin...