python

How can I measure the overall memory requirements of a Python program

I have a financial pricing application written in Python 2.4.4 which runs as an Excel plugin. Excel has a 1GB memory limit for all addins, so if any addin process tries to allocate more than 1Gb in total it will cause Excel to crash. I've recently made a change to the program which may have changed the overall memory requirements of th...

Finding closest match in collection of strings representing numbers

I have a sorted list of datetimes in text format. The format of each entry is '2009-09-10T12:00:00'. I want to find the entry closest to a target. There are many more entries than the number of searches I would have to do. I could change each entry to a number, then search numerically (for example these approaches), but that would se...

How to catch exit() in embedded C++ module from python code ?

Hello, I am embedding a c++ library (binding done with SIP) in my python application. Under certain circonstances (error cases), this library uses exit(), which causes my entire application to exit. Is there a way to catch this event, or do I need to modify the library to handle error cases differently ? Thank you very much, ...

have you seen? _mysql_exceptions.OperationalError "Lost connection to MySQL server during query" being ignored

Hi everyone, I am just starting out with the MySQLdb module for python, and upon running some SELECT and UPDATE queries, the following gets output: Exception _mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query') in bound method Cursor.del of MySQLdb.cursors.Cursor object at 0x8c0188c ignore...

What is the builtin name of the 'type' of functions, in Python?

What Python builtin returns <type 'function'>? >>> type(lambda: None) <type 'function'> Is there way of avoiding creating this lambda function, in order to get the type of functions in general? See http://www.finalcog.com/python-memoise-memoize-function-type for more details. Thanks, Chris. ...

How do i return a quoted string from a tuple?

I have a tuple of strings that i would want to extract the contents as a quoted string, i.e. tup=('string1', 'string2', 'string3') when i do this main_str = ",".join(tup) #i get main_str = 'string1, string2, string3' #I want the main_str to have something like this main_str = '"string1", "string2", "string3"' Gath ...

possible to intercept and rewrite email on outlook client side using ironpython?

I want to intercept and transform some automated emails into a more readable format. I believe this is possible using VBA, but I would prefer to manipulate the text with Python. Can I create an ironpython client-side script to pre-process certain emails? EDIT: I believe this can be done with outlook rules. In Outlook 2007, you can do...

How to use Python plugin reCaptcha client for validation?

Hi all, I want to make a captcha validation. I get the key from the recaptcha website and already succeed to put the public key to load the webpage with the challenge. <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=&lt;your_public_key&gt;"&gt; </script> <noscript> <iframe src="http://api.recaptcha.net/...

how disable psycopg2 connection pooling

i have configured pgpool-II for postgres connection pooling and i want to disable psycopg2 connection pooling. how do i do this? thanks! ...

How to create simplest p2p remote desktop OR any Robot(Java) equivalent in python ...

Hello all, I want to create a simplest remote desktop application using p2p communication. I did created one small p2p program in python. My Idea is- Transmit screenshots of remote computer periodically Transmit keyboard and mouse events wrapped in xml to remote desktop. Problem- I could transmit a information for keyboard and mo...

Class usage in Python

I write a lot of scripts in Python to analyze and plot experimental data as well as write simple simulations to test how theories fit the data. The scripts tend to be very procedural; calculate some property, calculate some other property, plot properties, analyze plot... Rather than just writing a procedure, would there be an benefits...

Maximum size of object that can be saved in memcached with memcache.py

Hi, I need to return a rather big file (11MB) to the user. For certain reasons, I can't just provide a direct url to the file (http://www.sample.com/mybigfile.exe); instead it must be accessed through code. Instead of having to read it from disk over and over, I thought of saving it in memcached (if this is not a good idea, let me know...

Django URL conf and view for retrieving multiple "tags" dynamically

In Django, I'm trying to write a URLconf and view that can take a theoretically unlimited number of "tags". The reason for this is to retrieve objects that have been tagged with different combinations of tags. For example, URLs like this are desireable: /topics/tag1/tag2/tag3 The above URL would retrieve "topics" that have been tagge...

Finding the command for a specific PID in Linux from Python

I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID. Any help would be great. Thanks. ...

Python Inspect - Lookup the data type for a property in a GAE db.model Class

class Employee(db.Model): firstname = db.StringProperty() lastname = db.StringProperty() address1 = db.StringProperty() timezone = db.FloatProperty() #might be -3.5 (can contain fractions) class TestClassAttributes(webapp.RequestHandler): """ Enumerate attributes...

Why do I get error, KeyError: 'wsgi.input'?

I'm using WSGI and trying to access the get/post data, using this code: import os import cgi from traceback import format_exception from sys import exc_info def application(environ, start_response): try: f = cgi.FieldStorage(fp=os.environ['wsgi.input'], environ=os.environ) output = 'Test: %s' % f['test'].value ...

Hiding Vertical Scrollbar in wx.TextCtrl

I have a wx.TextCtrl that I am using to represent a display with a fixed number of character rows and columns. I would like to hide the vertical scrollbar that is displayed to the right of the text pane since it is entirely unnecessary in my application. Is there a way to achieve this? Also...I would like to hide the blinking cursor tha...

Plotting color map with zip codes in R or Python

I have some US demographic and firmographic data. I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to http://maps.huge.info/ but a) with annotated text; b) pdf output; c) scriptable in R or Python. Is there ...

How can I omit words in the middle of a regular expression in Python?

I have a multi-line string like this: "...Togo...Togo...Togo...ACTIVE..." I want to get everything between the third 'Togo' and 'ACTIVE' and the remainder of the string. I am unable to create a regular expression that can do this. If I try something like reg = "(Togo^[Togo]*?)(ACTIVE.*)" nothing is captured (the first and last par...

Is it possible to have a python app authentication with a remote linux server?

The idea here is to have a python app, that when started, asks for a user/password combination. This user/password combination should be the same as the user/password of the remote linux server or in such case, and authentication system. Is this possible? How? Which APIs can I use? Thanks a lot. ...