python

Python object @property help

I'm trying to create a point class which defines a property called "coordinate". However, it's not behaving like I'd expect and I can't figure out why. class Point: def __init__(self, coord=None): self.x = coord[0] self.y = coord[1] @property def coordinate(self): return (self.x, self.y) @coo...

Can I write Python applications using PyObjC that target NON-jailbroken iPhones?

Is it currently possible to compile Python and PyObjC for the iPhone such that AppStore applications can written in Python? If not, is this a purely technical issue or a deliberate policy decision by Apple? ...

Configure Django project in a subdirectory using mod_python. Admin not working.

HI guys. I was trying to configure my django project in a subdirectory of the root, but didn't get things working.(LOcally it works perfect). I followed the django official django documentarion to deploy a project with mod_python. The real problem is that I am getting "Page not found" errors, whenever I try to go to the admin or any view...

Problem with Pysmell on Vim

I've installed pysmell, and I think I did it right because I can 'import pysmell' and make PYSMELLTAGS... But when I try to autocomplete in Vim (^x^o), I get an error. I'll just post an image, since I can't seem to copy the error. I've tried asking on the Google Code page, but I didn't get any response. Pysmell error image ...

One-liner Python code for setting string to 0 string if empty

What is a one-liner code for setting a string in python to the string, 0 if the string is empty? # line_parts[0] can be empty # if so, set a to the string, 0 # one-liner solution should be part of the following line of code if possible a = line_parts[0] ... ...

java to python conversion: x509 / dsa / sha1withdsa crypto howto?

I've got the following Java code that I'm trying to convert to python, and I'm not really sure how to do this: import java.security.spec.X509EncodedKeySpec; import java.security.KeyFactory; import java.security.PublicKey; import java.security.Signature; byte[] key = KeyReader.read(filestream) //KeyReader.read(inputstream) just reads...

python variable scope

I have started to learn about python and is currently reading through a script written by someone else. I noticed that globals are scattered throughout the script (and I don't like it).. Besides that, I also noticed that when I have code like this def some_function(): foo.some_method() # some other code if __name__ == '__main__...

Good way of handling NoneType objects when printing in Python

How do I go about printin a NoneType object in Python? # score can be a NonType object logging.info("NEW_SCORE : "+score) Also why is that sometime I see a comma instead of the + above? ...

Parameter binding using GQL in Google App Engine

Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here and this controller: class Random(webapp.RequestHandler): def get(self): rand2 = random.random() posts_query = db.GqlQuery("SELECT * FROM Posts WHERE rand1 > :rand2 ORDER BY rand LIMIT 1") #Assigning values for Django templa...

Accesing dictionary with class attribute

Hi all, now i am working with python. So one question about dict .... suppose i have a dict that config = {'account_receivable': '4', 'account_payable': '5', 'account_cogs': '8', 'accoun t_retained_earning': '9', 'account_income': '6', 'account_expense': '31', 'durat ion': 2, 'financial_year_month': 9, 'financial_year_day': 15, 'accou...

Is it crazy to not rely on a caching system like memcached nowadays ( for dynamic sites )?

I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent. I figure I'll just rewrite it from scratch because it's really outdated and in this rewrite I want to implement a caching system. It'd be nice if I could ge...

Attribute Error in Python

I'm trying to add a unittest attribute to an object in Python class Boy: def run(self, args): print("Hello") class BoyTest(unittest.TestCase) def test(self) self.assertEqual('2' , '2') def self_test(): suite = unittest.TestSuite() loader = unittest.TestLoader() suite.addTest(loader.loadTestsFromT...

accessing base class primitive type in python

I am trying to derive a class from a python primitive, the float, for the purpose of printing a different repr string when it's printed out. How do I access the underlying data from the derived class when I do this? Here's a simplified example of what I am trying to do: class efloat(float): def __repr__(self): return "here...

What wrong when SimpleXMLRPC and DBusGMainLoop working in the same time

In python I try create a service that maintain calling event between SflPhone(dbus service) and external app, when I start SimpleXMLRPCServer my service no longer response for any calling event, such as on_call_state_changed function was not called. When I comment out thread.start_new_thread(start_server(s,)) everything is work well. ...

How to make this method non-recursive?

Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest. There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. The function should, given a st...

Python: Memory leak debugging

I have a small multithreaded script running in django and over time its starts using more and more memory. Leaving it for a full day eats about 6GB of RAM and I start to swap. Following http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks I see this as the most common types (with only 800M of memory used): (Pdb) objgraph....

How to fetch rows from below table using google app engine GQL query (python)?

List_name Email ========== ================== andrew [email protected] adam [email protected] smith [email protected] john [email protected] andrew [email protected] adam [email protected] smith [email protected] john [email protected] andrew [email protected] adam [email protected] smith ...

How to add bi-directional manytomanyfields in django admin?

In my models.py i have something like: class LocationGroup(models.Model): name = models.CharField(max_length=200) class Report(models.Model): name = models.CharField(max_length=200) locationgroups = models.ManyToManyField(LocationGroup) admin.py (standard): admin.site.register(LocationGroup) admin.site.register(Report) ...

Regexp to literally interpret \t as \t and not tab

Hi, I'm trying to match a sequence of text with backslashed in it, like a windows path. Now, when I match with regexp in python, it gets the match, but the module interprets all backslashes followed by a valid escape char (i.e. t) as an escape sequence, which is not what I want. How do I get it not to do that? Thanks /m EDIT: well, ...

back-to-back histograms in matplotlib

There is a nice function that draws back to back histograms in Matlab. I need to create a similar graph in matplotlib. Can anyone show a working code example? ...