python

How can I have Google App Engine clear memcache every time a site is deployed?

The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime. Update 1 Using jldupont's answer I put the followin...

wxPython GridSizer not attached to panel?

I'm trying to build a level editor for a game I'm working on. It pulls data from a flat file and then based on a byte-by-byte search it'll assemble a grid from pre-set tiles. This part of the app I should have no issues with. The problem is that my test version of the editor which just loads a 16x16 grid of test tiles from 00 to FF is lo...

Remove row or column from 2D list if all values (in that row or column) are None

I have a grid (6 rows, 5 columns): grid = [ [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], ] I augment the grid and it might turn into ...

Python: How to avoid explicit 'self'?

I have been learning Python by following some pygame tutorials. Therein I found extensive use of the keyword self, and coming from a primarily Java background, I find that I keep forgetting to type self. For example, instead of self.rect.centerx I would type rect.centerx, because, to me, rect is already a member variable of the class. ...

SimpleHTTPServer, shoutdown and blocked request handlers

I have an instance of SimpleHTTPServer, however when I try to call "shutdown" on it and there is a request handler that is blocked - the whole process will block. It does so even if I run the "serve_forever" method in a deamon thread. See example code at http://codepad.org/cn8EYdfg Any advice? ...

Purpose of Python's __repr__

def __repr__(self): return '<%s %s (%s:%s) %s>' % ( self.__class__.__name__, self.urlconf_name, self.app_name, self.namespace, self.regex.pattern) What is the significance/purpose of this method? ...

why my code 'next' function not be calle in this example.

class a(object): w={'a':'aaa','b':'bbb'} def __iter__(self): return iter(self.w) def next(self):#this is not be called print 'sss' for i in self.w: return i b=a() for i in b: print i and what is Relations between __iter__ and next function. thanks ...

who can give me a code example on '__enter__' and '__exit__',i can't understand Completely only use api.

this is i saw in someone's code: def __enter__(self): return self def __exit__(self, type, value, tb): self.stream.close() thanks from __future__ import with_statement#for python2.5 class a(object): def __enter__(self): print 'sss' return 'sss111' def __exit__(self ,type, value, t...

Interaction between Java App and Python App

Hi, I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text. I have another application written in Java which knows how to collect non processed texts. Current state, the python app works in batch mode every x minutes. I want to make...

How to access fields in a struct imported from a .mat file using loadmat in Python?

Following this question which asks (and answers) how to read .mat files that were created in Matlab using Scipy, I want to know how to access the fields in the imported structs. I have a file in Matlab from which I can import a struct: >> load bla % imports a struct called G >> G G = Inp: [40x40x2016 uint8] Tgt: [8...

Export with alphabetical sort in Python ConfigParser

Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD: I'm using python 2...

Cross Product of 2 different vectors in Python

May i know how to find the cross product of 2 different vectors without the use of programming libraries? E.g given vector a = (1, 2, 3) vector b = (4, 5, 6) ...

Need init.d script for Python application

I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here). I found one sample here http://homepage.hispeed.ch/py430/python/daemon (PS. I ...

Why is my Python version slower than my Perl version?

I've been a Perl guy for over 10 years but a friend convinced me to try Python and told me how much faster it is than Perl. So just for kicks I ported an app I wrote in Perl to Python and found that it runs about 3x slower. Initially my friend told me that I must have done it wrong, so I rewrote and refactored until I could rewrite and r...

Filter with field has relationship in Django?

I have these models in Django: class Customer(models.Model): def __unicode__(self): return self.name name = models.CharField(max_length=200) class Sale(models.Model): def __unicode__(self): return "Sale %s (%i)" % (self.type, self.id) customer = models.ForeignKey(Customer) total = models.DecimalField...

Python: Colorbands in the PIL-Module

I have this code from the PIL-handbook but I get an error message. from PIL import Image, ImageEnhance, ImageChops im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg") # split the image into individual bands source = im.split() R, G, B = 0, 1, 2 # select regions where red is less than 100 mask = source[R].point(lambda i: i < ...

Using SimpleHTTPServer for unit testing

Hello, I'm writing a Python module that wraps out a certain web service API. It's all REST, so relatively straightforward to implement. However, I found a problem when it comes to unit testing: as I don't run the services I made this module for, I don't want to hammer them, but at the same time, I need to retrieve data to run my tests...

Plane equation for 3D vectors.

Hi, all.I want to find a 3D plane equation given 3 points.I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what i am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form. So that i can ...

Which is more fundamental: Python functions or Python object-methods?

I am trying to get a conceptual understanding of the nature of Python functions and methods. I get that functions are actually objects, with a method that is called when the function is executed. But is that function-object method actually another function? For example: def fred(): pass If I look at dir(fred), I see it has an att...

How to make a 3D plot in python?

Hi all. I am currently have a n by 3 matrix array. I want plot the three columns as three axises. how can i do that? I have googled and people suggested using matlab, but I am really having a hardtime with understanding it. Can someone teach me? Thanks in advance sorry for the missing infomation. Its in python and I want a scatter plot....