python

If slicing does not create a copy of a list nor does list() how can I get a real copy of my list?

I am trying to modify a list and since my modifications were getting a bit tricky and my list large I took a slice of my list using the following code tempList=origList[0:10] for item in tempList: item[-1].insert(0 , item[1]) del item[1] I did this thinking that all of the modifications to the list would affect tempList object...

Preventing file handle inheritance in multiprocessing lib

Using multiprocessing on windows it appears that any open file handles are inherited by spawned processes. This has the unpleasant side effect of locking them. I'm interested in either: 1) Preventing the inheritance 2) A way to release the file from the spawned process Consider the following code which works fine on OSX, but crashes o...

Sqlalchemy complex in_ clause

I'm trying to find a way to cause sqlalchemy to generate sql of the following form: select * from t where (a,b) in ((a1,b1),(a2,b2)); Is this possible? If not, any suggestions on a way to emulate it? Thanks kindly! ...

method for creating a unique validation key/number

I'm using django for a web-magazine with subscriber-content. when a user purchases a subscription, the site will create a validation key, and send it to the user email address. The validation key would be added to a list of "valid keys" until it is used. What is the best method for creating a simple yet unique key? Can someone suggest...

IMAP4_SSL with gmail in python

We are retrieving mails from our gmail account using IMAP4_SSL and python. The email body is retrieved in html format. We need to convert that to plaintext. Can anyone help us with that? ...

Python web framework with low barrier to entry

I am looking for a LAMPish/WAMPish experience. Something very transparent. Write the script, hit F5 and see the results. Very little, if any abstraction. SQLAlchemy and (maybe) some simple templating engine will be used. I need simple access to the environment - similar to the PHP way. Something like the COOKIE, SESSION, POST, GET obje...

Python: split a list based on a condition?

What's the best way, both aesthetically and from a performance perspective, to split a list of items into multiple lists based on a conditional? The equivalent of: good = [x for x in mylist if x in goodvals] bad = [x for x in mylist if x not in goodvals] is there a more elegant way to do this? Update: here's the actual use case, to ...

ODFPy documentation

I need to manipulate the ODF file format (open document format, the open office's internal format), and I need to do it in Python. It seem's ODFPy is a wonderful library for this porpouse. Unfortunately the official documentation is very poor, almost unuseful. And I can't find almost anything online (maybe it is not so popular?). Is th...

How do I infer the class to which a @staticmethod belongs?

I am trying to implement infer_class function that, given a method, figures out the class to which the method belongs. So far I have something like this: import inspect def infer_class(f): if inspect.ismethod(f): return f.im_self if f.im_class == type else f.im_class # elif ... what about staticmethod-s? else: ...

Terminating a Python Program

Hi, What command do you use in python to terminate a program? i.e. the equivalent of "end" in basic, or "quit" in BASH. I see that "break" takes you out of a loop, and "quit" is all tied up with "class" stuff that I do not comprehend yet. i tried import sys sys.exit() but it will display following error : Traceback (most recent c...

Python REPL for a running process

I am currently developing a simple application in python that connects to a server. At the moment, it's single-threaded (as multithreading is not currently required). However I would like - for debugging, maintenance and such to also be able to have a REPL via stdin. How do I go about that, if possible? Will I need to keep anything in ...

Error trapping when a user inputs incorect information

So, i have recently started learning python...i am writing a small script that pulls information from a csv and i need to be able to notify a user of an incorrect input for example the user is asked for his id number, the id number is anything from r1 to r5 i would like my script to be able to tell the user that they have input someth...

Referencing a class' method, not an instance's...

I'm writing a function that exponentiates an object, i.e. given a and n, returns an. Since a needs not be a built-in type, the function accepts, as a keyword argument, a function to perform multiplications. If undefined, it defaults to the objects __mul__ method, i.e. the object itself is expected to have multiplication defined. That par...

Embedding a 3-D editor (such as Blender) in a wxPython application

Is it possible to embed a 3-D editor inside my wxPython application? (I'm thinking Blender, but other suggestions are welcome.) My application opens a wxPython window, and I want to have a 3-D editor inside of it. Of course, I want my program and the 3-D editor to interact with each other. Possible? How? ...

Anyone know about this error: ssl() argument 1 must be _socket.socket, not _socketobject

I have a script that grabs some cookie from an https url. It works when I run it standalone. But I get the following error when I use it as a library from a large script. Has anyone seen this error and know what is the likely cause? File "/usr/grte/v1/piii-linux/lib/python2.4/urllib2.py", line 130, in urlopen return _opener.op...

Use Django Framework with Website and Stand-alone App

Hey, I'm planning on writing a web crawler and a web-based front end for it (or, at least, the information it finds). I was wondering if it's possible to use the Django framework to let the web crawler use the same MySQL backend as the website (without making the web crawler a "website" in it's self). Cheers, Pete ...

Create SQL query using SqlAlchemy select and join functions

I have two tables "tags" and "deal_tag", and table definition follows, Table('tags', metadata, Column('id', types.Integer(), Sequence('tag_uid_seq'), primary_key=True), Column('name', types.String()), ) Table('deal_tag', metadata, Column('dealid', types.Integer(), ForeignKey('deals.id')...

Which validating python XML api to use?

I new to xml stuff, so I have no idea which api I should use in python. Till now I used xmlproc, but I heard it is not developed any more. I have basically only one requirement: I want to validate against a dtd that I can choose in my program. I can't thrust the doctype thing. Performance does not really matter, so I would like to use ...

Dynamic loading of python modules

In python how do you dynamically add modules to a package while your programming is running. I want to be able to add modules to the package directory from an outside process, and be able to use those new modules in my program: import package def doSomething(name): pkg = __import__("package." + name) mod = getattr(pkg, name) ...

How to build a fully-customizable application (aka database), without lose performance/good-design?

Hi guys, im in the beginning of the complete restyle of an my web application, and i have some doubt about a good database-design that can be reliable, query-performance, and in the same time fully customizable by the users (users wont customize the database structure, but the funcionality of the application). So, my actual situation is...