python

Python mkdir giving me wrong permissions

Hello all again :D I'm (trying) to create a folder and create a file within it. Whenever i create that folder (via Python), it creates a folder that gives me no permissions at all and read-only mode. When i try to create the file i get an IOError. Erro: <type 'exceptions.IOError'> I tried creating (and searching) for a description...

How do I extract a ieee-be binary file embedded in a zipfile?

I have a set of zip files which contains several ieee-be encoded binary and text files. I have used Pythons ZipFile module and can extract the contents of the text file def readPropFile(myZipFile): zf = zipfile.ZipFile(myZipFile,'r') # Open zip file for reading zFileList=zf.namelist() # extract list of files embedded in _myZipFi...

Is there a convenient way to alias only conflicting columns when joining tables in SQLAlchemy?

Sometimes it is useful to map a class against a join instead of a single table when using SQLAlchemy's declarative extension. When column names collide, usually in a one-to-many because all primary keys are named id by default, you can use .alias() to prefix every column with its table name. That is inconvenient if you've already written...

Python, Perl And C/C++ With GUI

Hello, I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages? ...

Using the same handler for multiple wx.TextCtrls?

I'm having a bit of trouble with a panel that has two wxPython TextCtrls in it. I want either an EVT_CHAR or EVT_KEY_UP handler bound to both controls, and I want to be able to tell which TextCtrl generated the event. I would think that event.Id would tell me this, but in the following sample code it's always 0. Any thoughts? I've only t...

Python Infinity - Any caveats?

So Python has positive and negative infinity: float("inf"), float("-inf") This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of? ...

Can someone explain this unexpected Python import behavior?

Hi all, I've run into some behavior from Python 2.6.1 that I didn't expect. Here is some trivial code to reproduce the problem: ---- ControlPointValue.py ------ class ControlPointValue: def __init__(self): pass ---- ControlPointValueSet.py ---- import ControlPointValue ---- main.py -------------------- from ControlPointValu...

paths not being consistent python django.

I'm trying to import sorl-thumbnail into my app in django. Now the way that i have the site set up, using mod_wsgi on centos5 with cpanel the path for the apps must have the project name when importing... which is a pain. Obviously this is a cause of concern with portability of the app. I'm importing sorl-thumbnail, in previous apps i'v...

python attribute lookup without any descriptor magic?

I've started to use the python descriptor protocol more extensively in the code I've been writing. Typically, the default python lookup magic is what I want to happen, but sometimes I'm finding I want to get the descriptor object itself instead the results of its __get__ method. Wanting to know the type of the descriptor, or access stat...

chaining queries together in Django.

I have a query that gets me 32 avatar images from my avatar application: newUserAv = Avatar.objects.filter(valid=True)[:32] I'd like to combine this with a query to django's Auth user model, so I can get the last the last 32 people, who have avatar images, sorted by the date joined. What is the best way to chain these two together? ...

The advantages of having static function like len(), max(), and min() over inherited method calls

Hi! i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min() what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method calls? why guido chose thi...

SAS and Web Data

I have been taking a few graduate classes with a professor I like alot and she raves about SAS all of the time. I "grew up" learning stats using SPSS, and with their recent decisions to integrate their stats engine with R and Python, I find it difficult to muster up the desire to learn anything else. I am not that strong in Python, but...

Real time update of relative leaderboard for each user among friends

Ive been working on a feature of my application to implement a leaderboard - basically stack rank users according to their score. Im currently tracking the score on an individual basis. My thought is that this leaderboard should be relative instead of absolute i.e. instead of having the top 10 highest scoring users across the site, its...

Is it possible access other webpages from within another page

Basically, what I'm trying to do is simply make a small script that accesses finds the most recent post in a forum and pulls some text or an image out of it. I have this working in python, using the htmllib module and some regex. But, the script still isn't very convenient as is, it would be much nicer if I could somehow put it into an...

How to check if a FileField has been modified in the Admin of Django ?

Hello, I am trying to do a model with a file that shouldn't be modified. But the comment of the file can be. Here is what I did, but we cannot modify the comment. How can I test if a new file (using the browse button) as been sent and in this case only, create a new instance of the model ? If no upload of a new file, update the comment...

Python Package For Multi-Threaded Spider w/ Proxy Support?

Instead of just using urllib does anyone know of the most efficient package for fast, multithreaded downloading of URLs that can operate through http proxies? I know of a few such as Twisted, Scrapy, libcurl etc. but I don't know enough about them to make a decision or even if they can use proxies.. Anyone know of the best one for my pur...

Trace/BPT trap when calling urllib.urlopen

For some reason I'm getting a Trace/BPT trap error when calling urllib.urlopen. I've tried both urllib and urllib2 with identical results. Here is the code which throws the error: def get_url(url): from urllib2 import urlopen if not url or not url.startswith('http://'): return None return urlopen(url).read() # FIXME! I sho...

To find first N prime numbers in python

Hi All, I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number. For eg.: User...

Is it possible exclude test directories from coverage.py reports?

I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files? Here's a screenshot of my HTML report as an example. You can see that the report includes tests/test_credit_card. At first I was trying to omit the tests/ directory from...

python: sth like parametrized inheritance

I want my classes X and Y to have a method f(x) which calls a function func(x, y) so that X.f(x) always calls func(x, 1) and Y.f(x) always calls func(x, 2) class X(object): def f(self, x): func(x, 1) class Y(object): def f(self, x): func(x, 2) But I want to place f in a common base class B for X and Y. How can...