python

how to insert a small image on the corner of a plot with matplotlib?

Hi, What i want is really simple. I have a small image file called "logo.png" that i want to display on the upper left corner of my plots. But you cant find any example of that in the examples gallery of matplotlib Im using django, and my code is something like this def get_bars(request) ... fig = Figure(facecolor='#F0F0F0',fig...

Python Regular expression must strip whitespace except between quotes

As the title says, I need a way to remove all whitespace from a string, except when that whitespace is between quotes. result = re.sub('".*?"', "", content) This will match anything between quotes, but now it needs to ignore that match and add matches for whitespace.. ...

How come this way of ending a thread is not working?

I just came out with my noob way of ending a thread, but I don't know why it's not working. Would somebody please help me out? Here's my sample code: import wx import thread import time import threading class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent = None, id = -1, title = "Testing", pos=(35...

python: cannot concatenate 'str' and 'tuple' objects (it should works!)

I have a code: print "bug " + data[str.find(data,'%')+2:-1] temp = data[str.find(data,'%')+2:-1] time.sleep(1) print "bug tuple " + tuple(temp.split(', ')) And after this my application displays: bug 1, 2, 3 Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", ...

Crashing the logging formatter?

I have a logging component in my program. The setup of the formatter is straightforward: sh.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) I notice that my program is having problems. After a certain point, the formatter reverts to the default configuration (i.e., ignores the formatting I supplied). On closer inspecti...

Which is the best way to allow configuration options be overridden at the command line in Python?

I have a Python application which needs quite a few (~30) configuration parameters. Up to now, I used the OptionParser class to define default values in the app itself, with the possibility to change individual parameters at the command line when invoking the application. Now I would like to use 'proper' configuration files, for example...

What's the difference between pycurl and curl in python

Newbie question: Python 2.6, Ubuntu 10.04, I can import both pycurl and curl, the former having different names for functions (set_option vs. setopt). What's the difference between the two modules? ...

How to create the histogram of an array with masked values, in Numpy?

In Numpy 1.4.1, what is the simplest or most efficient way of calculating the histogram of a masked array? numpy.histogram and pyplot.hist do count the masked elements, by default! The only simple solution I can think of right now involves creating a new array with the non-masked value: histogram(m_arr[~m_arr.mask]) This is not very...

Secure use of GAE application namespace

Hi there, I'd like to have a mapping of users to accounts, and then have users directed to a namespace corresponding to their account. Having looked at the appengine_config.py from the suggested example, there appear to be a few suggested ways to determine what the namespace ought to be, i.e. Server name Google Apps Domain Cookie I...

doesPythonLikeCamels

Are Java style camelCase names good practice in Python. I know Capilized names should be reserved by convention for Class names. Methods should be small letters according to good style, or actually I am not so sure. Is there PEP about naming? COMMENTS: Sorry for camels :) , I learned from answer PEP8, that my title is actually properly...

Ways for combining Adobe AIR and Python - Python

Hi folks, I need to use Python because: I have implemented many scripts and libraries using Python in order to solve a certain problem. I would like to use AIR because: I really love the flexibility of building UIs using HTML and Javascript, also implementing beautiful UI designs is actually very easy. Any ideas if I can integrate the...

How to create an in-memory zip file with directories without touching the disk?

In a python web application, I'm packaging up some stuff in a zip-file. I want to do this completely on the fly, in memory, without touching the disk. This goes fine using ZipFile.writestr as long as I'm creating a flat directory structure, but how do I create directories inside the zip? I'm using python2.4. http://docs.python.org/libr...

pydev doesn't find python library after installation

Hi, I'm using Django and PyDev/Eclipse. I just installed django-treebeard with setup.py install and it got installed in my site-packages directory C:\Python26\Lib\site-packages. I can successfully import it in the python shell with import treebeard. However PyDev complains that it cannot resolve it when I try to import it. Unfortunate...

Building a Python extension with bjam (Boost.Build) on Mac OS X

So far as I can tell what happens is this: In python.jam, it works out which version of Python I am using and which library directories to look in; It adds -Wl-R arguments to the g++ command line to include those directories; The ld command complains that it does not have a -R option. So either (a) I have a defective version of ld, o...

Django: Advice on designing a model with varying fields.

I'm looking for some advice/opinions on the best way to approach creating a sort-of-dynamic model in django. The structure needs to describe data for Products. There are about 60 different possible data points that could be relevant, with each Product choosing about 20 of those points (with much overlapping) depending on its ProductTyp...

what is the code for identifying various musical instruments from a given sound file-python

hi, plz can u help me with the code for python for this ...

How to read a musical file using python and identify the various frequency levels of the notes??

please help me with the python...this is my project topic... ...

Is it possible to memcache a json result in App Engine?

I think my question is already clear enough, but to make it even more clear i will illustrate it with my example. I'm currently returning many json every request, which I would like to cache in some way. I thought memcache would be great, but I only see that they use memcache for caching queries. ...

What's a good way to provide additional decoration/metadata for Python function parameters?

We're considering using Python (IronPython, but I don't think that's relevant) to provide a sort of 'macro' support for another application, which controls a piece of equipment. We'd like to write fairly simple functions in Python, which take a few arguments - these would be things like times and temperatures and positions. Different ...

How to assure that filehandle.write() does not fail due to str/bytes conversions issues?

I need to detect if a filehandle is using binary mode or text mode - this is required in order to be able to encode/decode str/bytes. How can I do that? When using binary mode myfile.write(bytes) works, and when in text mode myfile.write(str) works. The idea is that I need to know this in order to be able to encode/decode the argument ...