python

How can I query objects with a date field, using a specific month and year?

I need to make a gql query against a set of some objects which have a date field. I am very new to python and also the GAE so I am a bit igorant to this. I am looking in the documentation but cannot find quite what I am looking for. Basically I have made the following class method Event.getEventsForMonth(cls, month,year): So I am t...

Python deep getsizeof list with contents ?

I was surprised that sys.getsizeof( 10000*[x] ) is 40036 regardless of x: 0, "a", 1000*"a", {}. Is there a deep_getsizeof which properly considers elements that share memory ? (The question came from looking at in-memory database tables like range(1000000) -> province names: list or dict ?) (Python is 2.6.4 on a mac ppc.) Added: 10000*...

Python :: How to open a page in the Non Default browser.

I was trying to create a simple script to open a locally hosted web site for testing the css in 2 or more browsers. The default browser is IE7 and it opens the page fine but when I try to open a non default browser such as Firefox or Arora it just fails. I am using the webbrowser module and have tried this several way as detailed in va...

How can I check compilation errors in python?

#!/usr/bin/python str = "this" if(1): print "Hi" else: print str.any_random_function() This doesn't fail when I run the program. I tried py_compile but that didn't indicate the error in the 'else' loop either. Now how can I compile the program and detect errors reliably in python code? Thanks. ...

Is there any metaprogramming patterns catalog for Python?

I have just read Python Cookbook. The book is amazing. I think the best use of this book is that it provides lots of examples that show python in real problem applications. Many of the idioms include metaprogramming techniques. I wonder if there is any catalog that summarizes metaprogramming idioms in Python? Python Cookbook is very ...

What IDE to use for Google App Engine development in Python?

I'm trying to figure out what IDE to use for Google App Engine development in Python. I'm completely new to Python, coming from a C#/.NET background. I initially went down the route of getting the Eclipse plugin for Google App Engine development only to find out it was for Java development only. Currently, I'm just using Notepad++...

Parse boolean arithmetic including parentheses?

Is there a single regular expression that can parse a string (in Python and Javascript, does not need to be the same expression) that represents simple boolean arithmetic? For example I want to parse this string: a and (b and c) and d or e and (f or g) Assuming that: * parentheses do not nest * the terms a, b, ..., z are not sub-expre...

Python List Exclusions

I have a dictionary of lists with info such as var1=vara, var1=varb, var2=vara etc. This can have lots of entries, and I print it out ok like this for y in myDict: print(y+"\t"+myDict[y]) I have another list which has exclusions in like this var2, var3 etc. This may have < 10 entries and I can print that ok like this for x ...

GAE email me errors

Can GAE be configured to bust me an email when there's an error? ...

Is there a Python library for connecting to a PostgreSQL 8.4 server using certificate authentication?

We are in the process of upgrading from PostgreSQL 8.3 to PostgreSQL 8.4, in a large part so that we can start using certificate-based authentication. We have some Python 2.x code that accesses the database that uses PyGreSQL. Is there a way to get it or any other Python library to use a cert to access PostgreSQL? Looking through the P...

In wxPython, What is the Standard Process of Making an Application Slightly More Complex Than a Wizard?

I am attempting to create my first OS-level GUI using wxPython. I have the book wxPython in Action and have looked at the code demos. I have no experience with event-driven programming (aside from some Javascript), sizers, and all of the typical GUI elements. The book is organized a little strangely and assumes I know far more about O...

How to separate one list in two via list comprehension or otherwise

If have a list of dictionary items like so: L = [{"a":1, "b":0}, {"a":3, "b":1}...] I would like to split these entries based upon the value of "b", either 0 or 1. A(b=0) = [{"a":1, "b":1}, ....] B(b=1) = [{"a":3, "b":2}, .....] I am comfortable with using simple list comprehensions, and i am currently looping through the list L t...

python : mysql : Return 0 when no rows found

Table structure - Data present for 5 min. slots - data_point | point_date 12 | 00:00 14 | 00:05 23 | 00:10 10 | 00:15 43 | 00:25 10 | 00:40 When I run the query for say 30 mins. and if data is present I'll get 6 rows (one row for each 5 min. stamp). Simple Query -...

virtual serial port on Arch linux

Hello, I am using Arch linux and I need to create virtual serial port on it. I tried everything but it seems doesnt work. All I want is to connect that virtual port to another virtual port over TCP and after that to use it in my python application to communicate with python application to other side. Is that posible? Please help me. Th...

Python: file with programmer-defined attributes

Using Python 2.5, I'd like to create a temporary file, but add (& modify) attributes of my own. I've tried the following: class TempFileWithAttributes ( ) : __slots__ = [ '_tempFile' , 'Value' ] def __init__ ( self ) : self._tempFile = tempfile.TemporaryFile() object.__setattr__ ( self, '_tempFile', t...

Convert a timedelta to days, hours and minutes

I've got a timedelta. I want the days, hours and minutes from that - either as a tuple or a dictionary... I'm not fussed. I must have done this a dozen times in a dozen languages over the years but Python usually has a simple answer to everything so I thought I'd ask here before busting out some nauseatingly simple (yet verbose) mathema...

python: convert UUID to a string which is a C unsigned char[16] initializer

(in case you're curious about motivation: this will be used in a scons build to generate a C file containing a GUID) I found the question about generating a GUID in python. But I don't really know much about programming python. Could someone help me convert this to a string of the form "{0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, 0x**, ...

Django forms: how do I display the initial blank form?

Hello, I have this view function: def search(request): if request.method == 'GET': form = SearchForm(request.GET) if form.is_valid(): last_name = form.cleaned_data['last_name'] first_name = form.cleaned_data['first_name'] lawyers = Lawyer.objects.all() [ other if state...

Calling a python function from bash script

I have an "alarm email" function inside a python module. I want to be able to call this function from a bash script. I know you can call a module using 'python ' in the script, but I'm not if you can or how you would call a specific function within the module. ...

Simple Python Challenge: Fastest Bitwise XOR on Data Buffers

Challenge: Perform a bitwise XOR on two equal sized buffers. The buffers will be required to be the python str type since this is traditionally the type for data buffers in python. Return the resultant value as a str. Do this as fast as possible. The inputs are two 1 megabyte (2**20 byte) strings. The challenge is to substantially bea...