python

How to add a custom implicit conversion to a C++ type in Boost::Python?

In my C++ code I have a class Foo with many methods taking a Bar type variable as an argument: class Foo { public: void do_this(Bar b); void do_that(Bar b); /* ... */ }; Bar has a number of constructors that create a new object from many common types such as int, std::string, float, etc: class Bar { public: Bar(int i); Bar(...

Has anyone succeeded in using Google App Engine with Python version 2.6 ?

Since Python 2.6 is backward compatible to 2.52 , did anyone succeeded in using it with Google app Engine ( which supports 2.52 officially ). I know i should try it myself. But i am a python and web-apps new bee and for me installation and configuration is the hardest part while getting started with something new in this domain. ( .......

string quoting issues in doctests

When I run doctests on different Python versions (2.5 vs 2.6) and different plattforms (FreeBSD vs Mac OS) strings get quoted differently: Failed example: decode('{"created_by":"test","guid":123,"num":5.00}') Expected: {'guid': 123, 'num': Decimal("5.00"), 'created_by': 'test'} Got: {'guid': 123, 'num': Decimal('5.00'), 'cre...

PHP - Print all statements that are executed in a PHP command line script?

In python, one can trace all the statements that are executed by a command line script using the trace module. In bash you can do the same with set -x. We have a PHP script that we're running from the command line, like a normal bash / python / perl / etc script. Nothing web-y is going on. Is there anyway to get a trace of all the lines...

Multipart form post to google app engine not working

I am trying to post a multi-part form using httplib, url is hosted on google app engine, on post it says Method not allowed, though the post using urllib2 works. Full working example is attached. My question is what is the difference between two, why one works but not the other is there a problem in my mulipart form post code? or the ...

Avoid program exit on I/O error

I have a Python script using shutil.copy2 extensively. Since I use it to copy files over the network, I get too frequent I/O errors, which lead to the abortion of my program's execution: Traceback (most recent call last): File "run_model.py", line 46, in <module> main() File "run_model.py", line 41, in main tracerconfigfile=...

Reimport a module in python while interactive

I know it can be done, but I never remember how. How can you reimport a module in python? The scenario is as follows: I import a module interactively and tinker with it, but then I face an error. I fix the error in the .py file and then I want to reimport the fixed module without quitting python. How can I do it ? ...

python api to fetch the public key from public key server

is there any python api which can fetch the public key from the public key server.... let me know thnks ...

Fastest way to convert a dict's keys & values from `unicode` to `str`?

I'm receiving a dict from one "layer" of code upon which some calculations/modifications are performed before passing it onto another "layer". The original dict's keys & "string" values are unicode, but the layer they're being passed onto only accepts str. This is going to be called often, so I'd like to know what would be the fastest w...

Can Python's optparse display the default value of an option?

Is there a way to make Python's optparse print the default value of an option or flag when showing the help with --help? ...

Why don't Django and CherryPy support HTTP verb-based dispatch natively?

It's not the same to POST to an URL than to GET it, DELETE it or PUT it. These actions are fundamentally different. However, Django seems to ignore them in its dispatch mechanism. Basically, one is forced to either ignore HTTP verbs completely or do this on every view: def my_view(request, arg1, arg2): if request.method == 'GET': ...

Call PHP code from Python

Hi, I'm trying to integrate an old PHP ad management system into a (Django) Python-based web application. The PHP and the Python code are both installed on the same hosts, PHP is executed by mod_php5 and Python through mod_wsgi, usually. Now I wonder what's the best way to call this PHP ad management code from within my Python code in ...

Non-editable text box in wxPython

How to create a non-editable text box with no cursor in wxPython to dump text in? ...

How do I validate XML document using RELAX NG schema in Python?

How do I validate XML document via compact RELAX NG schema in Python? ...

How can you ensure registered atexit function will run with AppHelper.runEventLoop() in PyObjC?

Hi all, I'm just wondering why I my registered an atexit function... e.g. import atexit atexit.register(somefunc) ... AppHelper.runEventLoop() Of course I know when will atexit won't work. When I comment out AppHelper.runEventLoop() the atexit function gets called. I also browsed my pyobjc egg, and I saw under __init__.py under objc ...

Python: using threads to call subprocess.Popen multiple times

I have a service that is running (Twisted jsonrpc server). When I make a call to "run_procs" the service will look at a bunch of objects and inspect their timestamp property to see if they should run. If they should, they get added to a thread_pool (list) and then every item in the thread_pool gets the start() method called. I have ...

Catching uncaught exceptions through django development server

I am looking for some way in django's development server that will make the server to stop at any uncaught exception automatically, as it is done with pdb mode in ipython console. I know to put import pdb; pdb.set_trace() lines into the code to make application stop. But this doesn't help me, because the line where the exception is thro...

text file format from array

Hi, I have no: of arrays, and i like to take it to text file in specific format, for eg., 'present form' a= [1 2 3 4 5 ] b= [ 1 2 3 4 5 6 7 8 ] c= [ 8 9 10 12 23 43 45 56 76 78] d= [ 1 2 3 4 5 6 7 8 45 56 76 78 12 23 43 ] The 'required format' in a txt file, a '\t' b '\t' d '\t' c 1 '\t' 1 2...

Finding Functions Defined in a with: Block

Here's some code from Richard Jones' Blog: with gui.vertical: text = gui.label('hello!') items = gui.selection(['one', 'two', 'three']) with gui.button('click me!'): def on_click(): text.value = items.value text.foreground = red My question is: how the heck did he do this? How can the conte...

How to read String in java that was written using python's struct.pack method

I have written information to a file in python using struct.pack eg. out.write( struct.pack(">f", 1.1) ); out.write( struct.pack(">i", 12) ); out.write( struct.pack(">3s", "abc") ); Then I read it in java using DataInputStream and readInt, readFloat and readUTF. Reading the numbers works but as soon as I call readUTF() I get EOFExcept...