python

opencv macport python bindings

using the MacPorts install of OpenCV does not seem to install the python bindings anywhere. Are they included, where do they go? ...

Django South removes foreign key REFERENCES from SQLite3 schema. Why? Is it a problem?

When using syncdb the following schema is created: CREATE TABLE "MyApp_supervisor" ( "id" integer NOT NULL PRIMARY KEY, "supervisor_id" integer NOT NULL REFERENCES "MyApp_employee" ("id"), "section_id" integer NOT NULL REFERENCES "MyApp_section" ("id") ); When using migrate, it is changed to: CREATE TABLE "MyApp_superviso...

Lowest common multiple for all pairs in a list

I have some code that calculates the lowest common multiple for a list of numbers. I would like to modify this code to return a list of values that represents the lowest common multiple for each pair in my number list. def lcm(numbers): return reduce(__lcm, numbers) def __lcm(a, b): return ( a * b ) / __gcd(a, b) def __gcd(a,...

How do you call a private module function from inside a class?

I have a module that looks something like this: def __myFunc(): ... class MyClass(object): def __init__(self): self.myVar = __myFunc() and I get the error: NameError: global name '_MyClass__myFunc' is not defined How can I call this function from inside the class? edit: Since posting this, I've discovered I can av...

Shading an area between two points in a matplotlib plot

How do you add a shaded area between two points in a matplotlib plot? In the example matplotlib plot below, I manually added the shaded, yellow area using Skitch. I'd like to know how to do this sans-Skitch. ...

What is the most up to date Python asterisk AGI framework for asterisk?

I have done some AGI development in the past with PERL and PHP, but my current project is using Python. I have found the frameworks listed here: http://www.voip-info.org/wiki/view/Asterisk+AGI , but they are all pretty old and do not seem kept up to date. I'd like to know if there are any others out there specifically for asterisk 1.6....

python django database synch

I use django in project. I have many cron jobs which operate with database. I want to replace cron jobs on other machine and synchronize processed data with main server. But my host provider doesnt allow external connections to db. How to organize sync. best way? I know what i can pass it via POST request with my own written protocol, bu...

Optional Arguments in Python

What are the advantages of having Optional args in Python. Instead of overloading one function (or method) with args + optional args, wouldn't Polymorphism with Inheritance suffice? I am just trying to understand the burning reason to have this feature. or is it the case of being able to do one thing many ways? P.S: I can see that it m...

Is there anything wrong with creating a Python Pickle powered website?

I have been toying with this idea for quite awhile now, but haven't seen any information on people doing it. I have a small website project where I need to load and modify 1 object. This object is pretty simple, and shouldn't be more than a few kb. Instead of running a DB for this small amount of data, why not just use pickle and/or shel...

questions on python virtual environments

I'm on a mac, and I know that any package I install goes to a specific folder in something like /Library/.... Now when I create a virtual environment, will it create a folder structure to store any libs underneath the virtual environment to isolate things? e.g. /home/user/mypythonvirtenv /home/user/mypythonvirtenv/python2.6/.... Doe...

SVG Glyphs in Pyqt

How do I render glyphs in pyqt using the svggraphicsItem? ...

Improving __init__ where args are assigned directly to members

I'm finding myself writing a lot of classes with constructors like this: class MyClass(object): def __init__(self, foo, bar, foobar=1, anotherfoo=None): self.foo = foo self.bar = bar self.foobar = foobar self.anotherfoo = anotherfoo Is this a bad code smell? Does Python offer a more elegant way of ...

Does python manage.py runserver use paster as the server?

A little confused, does python manage.py runserver use the paster web server or is this a django specific server? ...

Creating a new virutalenv hangs

I have a macbookpro. I downloaded virtualenv.py from pylonsbook.com/virutalenv.py when I type: python virtualenv.py --no-site-packages env it outputs: New python executable in env/bin/python then it just hangs, I don't get the prompt in terminal. I've restarted the computer and I get the same result, what's wrong? ...

QGraphicsView not displaying QGraphicsItems

Using PyQt4. My goal is to load in "parts" of a .png, assign them to QGraphicsItems, add them to the scene, and have the QGraphicsView display them. (Right now I don't care about their coordinates, all I care about is getting the darn thing to work). Currently nothing is displayed. At first I thought it was a problem with items being a...

Tying to change the Pylons version my website is using but this causes a DistributionNotFound exception

About a month ago I setup Pylons on my VPS in a virtual environment using the go-pylons.py script they provide. I've, since then, been working on my website and have it all up and running. It works great. Recently though I discovered that I created my virtual python environment using Python2.5. I now want to change this to Python2.7 I'...

python csv reader - convert string to int on the for line when iterating

I'm interested in not having to write map the int function to the tuple of strings where I currently have it. See the last part of my example: import os import csv filepath = os.path.normpath("c:/temp/test.csv") individualFile = open(filepath,'rb') dialect = csv.Sniffer().sniff(individualFile.read(1000)) individualFile.seek(0) re...

python multiprocessing pool, wait for processes and restart custom processes

Hi I used python multiprocessing and do wait of all processes with this code: ... results = [] for i in range(num_extract): url = queue.get(timeout=5) try: print "START PROCESS!" result = pool.apply_async(process, [host,url],callback=callbac...

Django models.py Circular Foreign Key

I have a django app which basically is just a photo album. Right now I have two models: Image and Album. Among other things, each Album has a foreign key to an Image to be its thumbnail and each Image has a foreign key to the Album it belongs in. However, when I try to use manage.py syncdb or manage.py sqlall I get errors saying the clas...

Python, Sorting

Hello, i have a list. name|num|num|num|num name|num|num|num|num name|num|num|num|num How i can sort this list on need me field (2,3,4,5) ? Sorry for my enlish. Update Input: str|10|20 str|1|30 Sort by first field (1,10): str|1|30 str|10|20 Sort by second field(20,30): str|10|20 str|1|30 ...