python

Inheritance in Python Such That All Base Functions Are Called

Basically, what I want is to do this: class B: def fn(self): print 'B' class A: def fn(self): print 'A' @extendInherit class C(A,B): pass c=C() c.fn() And have the output be A B How would I implement the extendInherit decorator? ...

How to create an integer array in Python?

It should not be so hard. I mean in C, int a[10]; is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module. ...

What is Jython and is it useful at all?

I know Python. When will I need Jython? What are the drawbacks. I assume it is slow? Please detail it out! thanks. ...

Django search capabilities

Is there a easy way to add a search capability on fields in Django? Also please let me know what is Lucene search. ...

Python static methods - how to call a method from another method

When I have regular methods for calling another method in a class I have to do this class test: def __init__(self): pass def dosomething(self): print "do something" self.dosomethingelse() def dosomethingelse(self): print "do something else" but when I have static methods I can't write self....

Need help understanding how this recursive function is working

Here's a function (credit to user Abbot, for providing it in another question) def traverse(ftp): level = {} for entry in (path for path in ftp.nlst() if path not in ('.', '..')): ftp.cwd(entry) level[entry] = traverse(ftp) ftp.cwd('..') return level Here's what I don't understand: When python ent...

How do I read binary C++ protobuf data using Python protobuf?

The Python version of Google protobuf gives us only: SerializeAsString() Where as the C++ version gives us both: SerializeToArray(...) SerializeAsString() We're writing to our C++ file in binary format, and we'd like to keep it this way. That said, is there a way of reading the binary data into Python and parsing it as if it were a...

rdflib graph not updated. Why?

I am trying to understand this behavior. It's definitely not what I expect. I have two programs, one reader, and one writer. The reader opens a RDFlib graph store, then performs a query every 2 seconds import rdflib import random from rdflib import store import time default_graph_uri = "urn:uuid:a19f9b78-cc43-4866-b9a1-4b009fe91f52" s...

Virtualenv: global site-packages vs the site-packages in the virtual environment

If I have a certain package installed both in the global site-packages and in the local one, which package will get imported? Will that even work or will I get an error? Which packages should I put in the global site-packages and which in the local one? ...

How do I distinguish "module not found" from "module threw exception" on ImportError?

In Python, import does_not_exist raises ImportError, and import exists exists.py: import does_not_exist will also raise ImportError. How should I tell the difference in code? ...

Text extraction from email in Python

My users will send me posts by email ala Posterous I'm using Google Apps Engine (GAE) to receive and parse emails. GAE returns the text part of the message. I need to extract the post from the plain text part of the message. The plain text can be "contaminated" with promotional headers, footers, signatures, etc. Also I would like to ...

Using Google App Engine to display a Rss/Atom feed

Im thinking of setting up a Google App that simply displays an RSS or Atom feed. The idea is that every once in a while (a cron job or at the push of a magic button) the feed is read and copied into the apps internal data, ready to be viewed. This would be done in Python. I found this page that seems to explain what I want to do. But th...

Unable to get Wacom events from /dev/input/event*.

I have created a pygtk program to monitor the keyboard status and mouse clicks across any application (i.e. not just for my application). This uses evdev by Micah Dowty which basically monitors /dev/input/event* for output and decodes the information in a way that I can display the information to the user. The program works perfectly fo...

Object appended to a list instance appears in a different instance of that list.

Hi, I was writing this little piece of code as an exercise in object-oriented programming. Here I'm trying to define a house as a list of rooms and each room as a list of devices (lamps, for example). First I created all the objects and them appended the two rooms to the house and a different device to each room. Pretty basic. The pro...

Writing my own django-cms plugin. Any recommendations?

I don't see any possibility for creating a table in django-cms. I need this functionnality so I am evaluating the possibility to write my own plugin. I am getting started with this product. I've read the documentation carefully and I see more or less how to do that. However, I would be happy to hear some tips and tricks before starting...

Python vs. Java -- Which would you pick to do concurrent programming and why?

Also, if not python or java, then would you more generally pick a statically-typed language or a dynamic-type language? ...

How would I call 32bit exes in Windows 64bit with python?

I want to call a exe from python on a 64bit version of vista. I know to use subprocess, but all the 32bit apps are store in C:\Program Files (x86)\, and it doesn't like the spaces I believe. i have tried escape characters, doesn't fire, any ideas? ...

Why is this invalid syntax?

Why is this complaining about an invalid syntax? #! /usr/bin/python recipients = [] recipients.append('[email protected]') for recip in recipients: print recip I keep getting: File "send_test_email.py", line 31 print recip ^ SyntaxError: invalid syntax ...

Python IO Gurus: what are the differences between these two methods?

I have two methods for writing binary files: the first works with data received by a server corresponding to a file upload (i.e., handling a form whose enctype="multipart/form-data"), and the second works with file data sent as email attachments (i.e., file data obtained by parsing an email message message body using get_payload()). The...

Checking File Permissions in Linux with Python

I'm writing a script to check permissions of files in user's directories and if they're not acceptable I'll be warning them, but I want to check permissions of not just the logged in user, but also group and others. How can i do this? It seems to me that .access() in Python can only check the permissions for the user running the script. ...