python

Using numpy to build an array of all combinations of two arrays

Hi, I'm trying to run over the parameters space of a 6 parameter function to study it's numerical behavior before trying to do anything complex with it so I'm searching for a efficient way to do this. My function takes float values given a 6-dim numpy array as input. What I tried to do initially was this: 1) First I created a functio...

Dictionary with classes?

In Python is it possible to instantiate a class through a dictionary? shapes = {'1':Square(), '2':Circle(), '3':Triangle()} x = shapes[raw_input()] I want to let the user pick from a menu and not code huge if else statements on the input. For example if the user entered 2, x would then be a new instance of Circle. Is this possible?...

how do I use CommaSeparatedIntegerField in django?

there is almost no documentation for it here: http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield maybe someone could , by example, show me how to populate a commaseperatedintegerfield in django? -thanks. ...

Django and urls.py: How do I HttpResponseRedirect via a named url?

I'm writing a member-based web application, and I need to be able to redirect the page after login. I want to use the named url from my urls.py script in my views.py file for the login application, but I can't for the life of me figure out what to do. What I have is this: def login(request): if request.session.has_key('user'): if requ...

Decoding HTML entities with Python

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out what I am doing wrong. Take for example: "U.S. Adviser’s Blunt Memo on Iraq: Time ‘to Go Home’" I've tried BeautifulSoup, decode('iso-8859-1'), and django.utils.encoding's smart_str without any success. ...

Can pydoc generate subdirectories?

Is there any way to get pydoc's writedocs() function to create subdirectories for packages? For instance, let's say I have the following modules to document: foo.py dir/bar.py dir/init.py When I run pydoc.writedocs(), I get the following files: foo.html dir.bar.html I would like to get: foo.html dir/bar.html Is there any w...

python web programming

I started learning Python through some books and online tutorials. I understand the basic syntax and operations, but I realize that the correct way to understand the language would be to actually do a project on it. Now when i say a project, I mean something useful, maybe some web app. I started searching for web programming in python a...

Python: Why does `sys.exit(msg)` called from a thread not print `msg` to stderr?

Hello! Today I ran against the fact, that sys.exit() called from a child-thread does not kill the main process. I did not know this before, and this is okay, but I needed long time to realize this. It would have saved much much time, if sys.exit(msg) would have printed msg to stderr. But it did not. It turned out that it wasn't a real ...

How do you control MySQL timeouts from SQLAlchemy?

What's the right way to control timeouts, from the client, when running against a MySQL database, using SQLAlchemy? The connect_timeout URL parameter seems to be insufficient. I'm more interested in what happens when the machine that the database is running on, e.g., disappears from the network unexpectedly. I'm not worried about the ...

difference between two strings in python/php

I'm looking for an easy way to compare two similar strings and output the difference for instance if I have "abcdefghijklmnop" and "abcdefghi" the function would output "jklmnop" I need to know how to do this in both php and python ...

outer join modelisation in django

Hi, I have a many to many relationship table whith some datas in the jointing base a basic version of my model look like: class FooLine(models.Model): name = models.CharField(max_length=255) class FooCol(models.Model): name = models.CharField(max_length=255) class FooVal(models.Model): value = models.CharField(max_length...

How to find number of users, number of users with a profile object, and monthly logins in Django

Is there an easy way in Django to find the number of Users, Number of Users with profile objects, and ideally number of logins per month (but could do this with Google Analytics). I can see all the data is there in the admin interface, but I'm unsure of how to get to it in Python land. Has anyone seen any examples of counting number of ...

Handling Windows-specific exceptions in platform-independent way

Consider the following Python exception: [...] f.extractall() File "C:\Python26\lib\zipfile.py", line 935, in extractall self.extract(zipinfo, path, pwd) File "C:\Python26\lib\zipfile.py", line 923, in extract return self._extract_member(member, path, pwd) File "C:\Python26\lib\zipfile.py", line 957, in _extract_memb...

Google app engine ReferenceProperty relationships

Hi guys, I'm trying to get my models related using ReferenceProperty, but not have a huge amount of luck. I have 3 levels: Group, Topic, then Pros, and Cons. As in a Group houses many topics, and within each topic could be many Pros and Cons. I am able to store new Groups nice and fine, but I don't have any idea how to store topics und...

How do I iterate over the tuples of the items of two or more lists in Python?

Specifically, I have two lists of strings that I'd like to combine into a string where each line is the next two strings from the lists, separated by spaces: a = ['foo1', 'foo2', 'foo3'] b = ['bar1', 'bar2', 'bar3'] I want a function combine_to_lines() that would return: """foo1 bar1 foo2 bar2 foo3 bar3""" I admit I've already solv...

How can I generate a unique ID in Python?

I need to generate a unique ID based on a random value. ...

help me eliminate a for-loop in python

There has to be a faster way of doing this. There is a lot going on here, but it's fairly straightforward to unpack. Here is the relevant python code (from scipy import *) for i in arange(len(wav)): result[i] = sum(laser_flux * exp(-(wav[i] - laser_wav)**2) ) There are a bunch of arrays. result -- array of length (wav) laser_f...

No module named _sqlite3

I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error: File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <...

Django .."join" query?

Hi, guys, how or where is the "join" query in Django? i think that Django dont have "join"..but how ill make join? Thanks ...

usage of generators as a progression notifier

Hi! I am currently using generators as a quick way to get the progress of long processes and I'm wondering how is it done usually as I find it not very elegant... Let me explain first, I have a engine.py module that do some video processing (segmentation, bg/fg subtraction, etc) which takes a lot of time (from seconds to several minute...