python

How can I figure out in my module if the main program uses a specific variable?

I know this does not sound Pythonic, but bear with me for a second. I am writing a module that depends on some external closed-source module. That module needs to get instantiated to be used (using module.create()). My module attempts to figure out if my user already loaded that module (easy to do), but then needs to figure out if the ...

Setting a property from the Pylons .ini file

Let's say I have a settings.py file in my app's root folder (/myapp/myapp/settings.py) with just a bunch of variables in it: var1 = '' var2 = '' Can I automatically set one of those variables from the .ini file? I tried this: myapp.settings.var1 = 'this is from development.ini' But when I call var1 it is still the empty string: i...

Adding Album Art using python in mp3 metadata

The code below doesnt seem to update the artwork of the mp3 file. Code:- #Editing the MetaData tag = eyeD3.Tag() print tag.link('location') //Returns 1 tag.setVersion([2,3,0]) print tag.addImage(0x08,'artwork.jpg') //Return None (Its sure that file is present) print tag.update() //Returns 1 The values returned by the function are co...

Python Drawing Portion of Image When Mouse Hover

Hi My question relates to Python GTK I have an image -a JPG - which I draw onto a drawing area. I want to reveal a portion of the image -say a 10pix by 10 px square -only where the mouse pointer is currently at. Everything 10 x 10 px square away from the mouse should hidden i.e. black. I'm am new to PyGtk please can anyone help? Tha...

Transaction within transaction

Hello, I want to know if open a transaction inside another is safe and encouraged? I have a method: def foo(): session.begin try: stuffs except Exception, e: session.rollback() raise e session.commit() and a method that calls the first one, inside a transaction: def bar(): stuffs t...

How do I pass a list parameter as multiple link-named elements instead of as an array in SOAPpy ?

I am trying to pass multiple instances of an element to a web servile that has the following wsdl <complexType name="OAMCommand"> <sequence> <element name="m-strName" type="xsd:string" minOccurs="1" maxOccurs="1"/> <element name="m-argVector" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> </sequence> </comple...

(How) Can I use string substitution for working w/ Django’s i18n {% trans %} tag?

I'm looking for something like this: {% trans "There are %{flowers}n flowers in the vase" < flowers:3 %} Now obviously syntax is fake, but it should be sufficient to demonstrate what I'm looking for. Should I cook something of my own? It looks like a common usecase, so I was quite surprised that quick web search didn't return anythi...

Jython image manipulation problem.

This program is supposed to take the outline of an image, then split it into different quadrants, then color it, such as the Andy Warhol Marilyn Monroe picture. Every function up to the "Warholize" function works but it gets stuck on c=getPixel(picEdge,x,y) under the warholize function at which I'm not sure what to do. Any help would...

Grabbing a random frame from a webcam with GStreamer in Python

I'm trying to write a program to control a robot by interpreting frames from a webcam and happened upon GStreamer. I've been able to stream video in Python from the webcam with GStreamer with help from this page: http://www.ndeschildre.net/2008/04/04/python-power/ However, I don't know how to ask for a single RGB-encoded frame from the...

How can I listen for a mouse event in Python on Mac?

I need to listen for global mouse events(not bound to an app) on my Mac in an app written in Python. I'm using PyObjC, but I can't figure out how to do it. Plain ObjC examples or other Python techniques also appreciated. My code so far: from Quartz import * def MyFunction(proxy, type, event): print event CGEventTapCreate(kCGHIDEv...

Any way of achieving the same thing as python -mpdb from inside the script?

Besides wrapping all your code in try except, is there any way of achieving the same thing as running your script like python -mpdb script? I'd like to be able to see what went wrong when an exception gets raised. ...

Is it a bad idea to change the app_label assignment on existing Django models?

I have the hair-brained idea of grouping models from different existing apps into one big new shiny app. There's not a super important reason I need to do this, but it would be nice to consolidate all of the code in one subdirectory and it would improve the site to group all the models together in the admin_index under the same module he...

Set a DTD using minidom in python.

I am trying to include a reference to a DTD in my XML doc using minidom. I am creating the document like: doc = Document() foo = doc.createElement('foo') doc.appendChild(foo) doc.toxml() This gives me: <?xml version="1.0" ?> <foo/> I need to get something like: <?xml version="1.0" ?> <!DOCTYPE something SYSTEM "http://www.path.t...

Convert SQL query to Django friendly format for application

I have an SQL query thats runs on the Postgres database of my Django based webapp. The query runs against the data stored by Django-Notifications (a reusable app) and returns a list of email addresses that have not opted out of a specific notice type. What I would really like to be able to do is to build an application that does this o...

Exceeding the size of lists in python

I'm trying to implement the sieve of eratosthenes in python, however when trying to find all primes up to the sqare root of for instance 779695003923747564589111193840021 I get an error saying result of range() has too many items. My question is, how do I avoid this problem, if I instantiate the list with a while loop I will get an error...

Requesting advice on persisting objects from a dynamic language to a document database

Hi, Do you have any insights into the most elegant way of persisting objects from a dynamic language in a document database? I have a solid background in C# and have just started programming in Python. At the same time I am trying to learn the ropes of MongoDB. Now I am wondering: what is the most elegant way to persist my data to t...

python, hash function selection

Hello Using Python and Django, I will let my users to give pdf based gifts to their friends, which the said friend will be able to claim pdf by entering to my site from the emailed link. Here is the plan User gives a gives to his friend, enters friends email In the background, a gift model is saved which will contain a uniquely gener...

Pickling array.array in 2.4 using cPickle

Hey All, I am working on a project built on python 2.4 (It is an embedded python project, so I don't have a choice on the version of python used). Throughout the application, we use array.array to store data. Support for pickling array.array objects was added to pickle (and cPickle) in 2.5. We have a viable workaround in 2.4 when usi...

Python/Django polling of database has memory leak

I've got a Python script running Django for database and memcache, but it's notably runnning as a standalone daemon (i.e. not responding to webserver requests). The daemon checks a Django model Requisition for objects with a status=STATUS_NEW, then marks them STATUS_WORKING and puts them into a queue. A number of processes (created usin...

In SciPy, using ix_() with sparse matrices doesn't seem to work so what else can I use?

In Numpy, ix_() is used to grab rows and columns of a matrix, but it doesn't seem to work with sparse matrices. For instance, this code works because it uses a dense matrix: >>> import numpy as np >>> x = np.mat([[1,0,3],[0,4,5],[7,8,0]]) >>> print x [[1 0 3] [0 4 5] [7 8 0]] >>> print x[np.ix_([0,2],[0,2])] [[1 3] [7 0]] I used ix...