python

PyImport_ImportModule("PyQt4.QtGui") fails

I've got a C++ windows app that is trying to load a PyQt4 object, similar to the way PyQt4 does it for providing python widgets in the QtDesigner. The app loads other Python modules just fine, but fails to load PyQt4.QtGui. Also, with straight Python, I can load PyQt4.QtGui just fine. The debug output when it attempts that is: 'devenv.e...

How To Create Per-Request Singleton in Pylons?

In our Pylons based web-app, we're creating a class that essentially provides some logging functionality. We need a new instance of this class for each http request that comes in, but only one per request. What is the proper way to go about this? Should we just create the object in middleware and store in in request.environ? Is there a ...

How to pass variables using Unittest suite

Hello I have test's using unittest. I have a test suite and I am trying to pass variables through into each of the tests. The below code shows the test suite used. class suite(): def suite(self): #Function stores all the modules to be tested modules_to_test = ('testmodule1', 'testmodule2') alltests = unittest.TestS...

Problem with sys.argv[1] when unittest module is in a script

Hello, I have a script that does various things and access paramenters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value = sys.argv[1] def hello(self): print self.value ...

Is there a python equivalent of Ruby's 'rvm'?

Q: Do we have anything functionally equivalent in Python to the Ruby version manager 'rvm'? (RVM lets you easily switch completely between different versions of the ruby interpreter and different sets of gems (modules). Everything concerning download-build-install-switch of interpreter(-s) and gems gets taken care of by invoking rvm...

pip: dealing with multiple Python versions?

Is there any way to make pip play well with multiple versions of Python? For example, I want to use pip to explicitly install things to either my site 2.5 installation or my site 2.6 installation. For example, with easy_install, I use easy_install-2.{5,6}. And, yes — I know about virtualenv, and no — it's not a solution to this particu...

Python proper use of __str__ and __repr__

Hey, My current project requires extensive use of bit fields. I found a simple, functional recipe for bit a field class but it was lacking a few features I needed, so I decided to extend it. I've just got to implementing __str__ and __repr__ and I want to make sure I'm following convention. __str__ is supposed to be informal and conci...

Lisp vs Python -- Static Compilation

Why can Lisp with all its dynamic features be statically compiled but Python cannot (without losing all its dynamic features)? ...

Cheking added file to upload python, pylons?

Hi! I try to upload file, how can i check if file is upload when i send empty input witch file upload i get AttributeError: 'unicode' object has no attribute 'filename' How can i check added file? ...

Printing Variable names and contents as debugging tool; looking for emacs/Python shortcut

I find myself adding debugging "print" statements quite often -- stuff like this: print("a_variable_name: %s" % a_variable_name) How do you all do that? Am I being neurotic in trying to find a way to optimize this? I may be working on a function and put in a half-dozen or so of those lines, figure out why it's not working, and then cu...

How to pack python files and its dependencies in a single executable file?

I've got a piece of software which consists of several python sources and a couple of c++ libraries. I'd like to pack them in a executable single file, just like java does with .jar files. Is there a way to do that? ...

OpenSSL signing and Google App Engine

Is there a way to sign values with a PEM formatted private key in Google App Engine (Python)? For example in PHP it could be achieved like this: $key = openssl_pkey_get_private($privateKey); openssl_sign($strToBeSigned, $signature, $key); echo "signature: ".base64_encode($signature); Is there a way to do the same thing with Python in...

Python MD5 Hash Faster Calculation

Hi everyone. I will try my best to explain my problem and my line of thought on how I think I can solve it. I use this code for root, dirs, files in os.walk(downloaddir): for infile in files: f = open(os.path.join(root,infile),'rb') filehash = hashlib.md5() while True: data = f.read(10240) if len(data) =...

using an alternative string quotation syntax in python

Just wondering... I find using escape characters too distracting. I'd rather do something like this: >>> print ^'Let's begin and end with sets of unlikely 2 chars and bingo!'^ Let's begin and end with sets of unlikely 2 chars and bingo! Note the ' inside the string, and how this syntax would have no issue with it, or whatever else i...

Google App Engine dev_appserver can't find PIL (I've installed it)

I recently upgraded my Google App Engine launcher on my Mac, running OSX 10.5.8, and afterwards my projects that work with images stopped working locally. It seems to be the same problem that I had when first using GAE locally to work with images, before I installed PIL. Here is the error I get: SystemError: Parent module 'PIL' not lo...

python : in which timezone is it a specific time right now?

i have users from all timezones, and i want to send out alerts at around 8AM in each users respective timezone. i need a python script that runs every hour [in a cron job] and i need to find out at which timezone it is 8AM right now, and i can use that info to select the users that have to receive the alerts. how do i go about doing t...

How do you check the presence of many keys in a Python dictinary?

I have the following dictionary: sites = { 'stackoverflow': 1, 'superuser': 2, 'meta': 3, 'serverfault': 4, 'mathoverflow': 5 } To check if there are more than one key available in the above dictionary, I will do something like: 'stackoverflow' in sites and 'serverfault' in sites The above is maintainable with o...

How do I coalesce a sequence of identical characters into just one?

Suppose I have this: My---sun--is------very-big---. I want to replace all multiple hyphens with just one hyphen. ...

ValueError: need more than 1 value to unpack

I run this code: from sys import argv script, user_name =argv prompt = '>' print "Hi %s, I'm the %s script." % (user_name, script) And I get the following error: Traceback (most recent call last): script, user_name =argv ValueError: need more than 1 value to unpack ...

How to make Django work with MySQL Connector/Python?

Has anyone made Django work with myconnpy? I've checked out http://github.com/rtyler/connector-django-mysql but the author said it's very outdated and not supported. If you've managed to make Django work with myconnpy, please share your experience. Thanks. ...