python

How to introspect django model fields?

Hello, I am trying to obtain class information on a field inside a model, when I only know name of the field and name of the model (both plain strings). How is it possible? I can load the model dynamically: from django.db import models model = models.get_model('myapp','mymodel') Now I have field - 'myfield' - how can I get the class ...

Sqlalchemy - Can we use date comparison in relation definition ?

Hi, I have this mapper defined: mapper(Resource, resource_table, properties = {'type' : relation(ResourceType,lazy = False), 'groups' : relation(Group, secondary = model.tables['resource_group'], backref = 'resources'), 'parent' : relation(Relation, uselist=False, primaryjoin = and_(relation_table.c.res_id == resourc...

python library for file upload and persistent connections?

Hi, I tried urllib{2}, pycurl and I'm looking at twisted's new http client. But: I found urllib2 difficult to perform a file upload pycurl multi looks right but unpythonic twisted's http client does not support persistent connection (didn't check the file upload capability) Is there any other alternative? ...

OperationalError creating an index in sqlite

EDIT: TL;DR version I typed this CREATE INDEX IF NOT EXISTS IDX_FILE_SIZE table_name (file_size); instead of this CREATE INDEX IF NOT EXISTS IDX_FILE_SIZE ON table_name (file_size); Don't do that. ...

can't call __add__ through __getattr__( __getattribute__ )

It is object of the class A, in conteiner's class tmpA. Not all method from A are in the tmpA. So for exapmle: A + B is present , tmpA + B isn't present. I try to call method from A for tmpA. I can to call simple method, such as change(), bit add - don't work. If to remove inheritance from object, the code work's. Help me, please. ...

What is the appropriate way to intercept WSGI start_response?

I have WSGI middleware that needs to capture the HTTP status (e.g. 200 OK) that inner layers of middleware return by calling start_response. Currently I'm doing the following, but abusing a list doesn't seem to be the “right” solution to me: class TransactionalMiddlewareInterface(object): def __init__(self, application, **config): ...

What are the helpful online resources there for Python beginners?

Specifically for the ff: topics: Windows installation Using mod_wsgi/mod_python Python best practices Python security stuff Using Pylons Thanks ...

Pointer argument to boost python

What's the best way to make a function that has pointer as argument work with boost python? I see there are many possibilities for return values in the docs, but I don't know how to do it with arguments. void Tesuto::testp(std::string* s) { if (!s) cout << " NULL s" << endl; else cout << s << endl; } >>> t.testp...

Multimedia processing in Python

I would like to use Python to simplify a series of partly manual multimedia processing steps. I'm aware of the possible performance issues but this would be partly a learning project, and partly for ease of maintenance. Specifically, I want to create enhanced podcasts from MP3 files, although starting from MP4 is reasonable given ease of...

how do I include a boolean AND within a regex?

Is there a way to get single regex to satisfy this condition?? I am looking for a "word" that has three letters from the set MBIPI, any order, but MUST contain an I. ie. re.match("[MBDPI]{3}", foo) and "I" in foo So this is the correct result (in python using the re module), but can I get this from a single regex? >>> for foo in (...

Which is best in Python: urllib2, PycURL or mechanize?

Ok so I need to download some web pages using Python and did a quick investigation of my options. Included with Python: urllib - seems to me that I should use urllib2 instead. urllib has no cookie support, HTTP/FTP/local files only (no SSL) urllib2 - complete HTTP/FTP client, supports most needed things like cookies, does not support ...

Counting Duplicates Integers in Python

How do I find the total number of duplicates in a string? i.e., if it was j= [1,1,1,2,2,2] it would find 4 duplicates? I've only been able to find counting which shows how many times each individual number occurred. ...

python-pam & pam_time module -- possible to check a user without password?

I've looked at the example script of python-pam and linux pam pages, but it's a bit confusing, at least for a beginner in PAM (that I am): http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/Linux-PAM_ADG.html http://packages.ubuntu.com/python-pam Is it possible to check if a user has or does not have access to login, without enteri...

Why does the "name" parameter to __setattr__ include the class, but __getattr__ doesn't?

The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value): print name def __getattr__(self, name): print name raise AttributeError(name) x = MyClass() x.test() x.__y Outputs: _MyClass__x __y Traceback (most recent call last): ... AttributeError:...

how can I make a suggestion for a new feature in python

Suppose I think I have a great idea for some feature that should be in python's standard library. Not something of the magnitude of a new keyword etc, just a suggestion for another decorator that would help a lot, IMO. How can I suggest such a feature to the consideration of the "python committee :)"? ...

Creating a custom Django form field that uses two <input>s.

How can I make a Django field that renders itself as a pair of input fields? Reasoning: I am trying to write a new custom field. I will use it for a captcha-like service. The service works by requesting a question - then receiving one and a token. The validation happens by sending the answer along with the token. I want to write a form ...

In python, why is "import *" bad?

It is recommended to not to use import * in python. Can anyone please share the reason for that, so that I can avoid it doing next time. Thanks and Regards ...

Is it possible to get the width of a character when using OpenGL bitmap fonts?

I am trying to align my bitmap font text in my OpenGL application but I can't find anything on getting the width of each character. This is my renderText function: def renderText( self, text, fontFace, position ): ..... (omitted code to make post shorter) glRasterPos2i( position[0], self.windowSize[1] - position[1] ) glPushA...

"No source for code" message in Coverage.py

I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message "No source for code" when running my nosetests with coverage. NoSource: No source for code: '/home/matthew/.hudson/jobs/myproject/workspace/tests/unit/ut...

Re-order list in Python to ensure it starts with check values.

Dear all, I'm reading in serial data using Pyserial, to populate a list of 17 values (1byte each) at a sampling rate of 256Hz. The bytes I ultimately want to use are the 5th to 8th in the list. Providing no bytes are dropped, the first two values of the stream are always the same ('165','90'). I'm getting quite a few dropped values th...