python

Does python yield imply continue?

I have a for loop that checks a series of conditions. On each iteration, it should yield output for only one of the conditions. The final yield is a default, in case none of the conditions are true. Do I have to put a continue after each block of yields? def function(): for ii in aa: if condition1(ii): yield som...

why model has the key_name don't has the key().id() on google-app-engine

if i use this : class A(db.Model): a=db.StringProperty() class demo(BaseRequestHandler): def get(self): a=A() a.a='sss' a.put() raise Exception(a.key().id()) i can get the a.key().id() is 961 but if i add key_name="aaa" , the a.key().id() will be None : class A(db.Model): a=db.StringPrope...

execute functions in a queue

hi! i have a example who should show what i'd like to do queue = 2 def function(): print 'abcd' time.sleep(3) def exec_times(times): #do something function() def exec_queue(queue): #do something function() exec_times(3) #things need be working while it waiting for the function finish time.sleep(10) the resu...

How to get the number of args of a built-in function in Python?

I need to programmatically get the number of arguments that a function requires. With functions declared in modules this is trivial: myfunc.func_code.co_argcount But built-in functions don't have the func_code attribute. Is there another way to do this? Otherwise I can't use the built-ins and have to re-write them in my code. [additi...

Does anyone have a code example of AES encryption in python on Google App Engine?

Hi, I have a query string I need to encrypt using AES in CBC mode with zero padding, before finally encoding it to base64 and I need to run this on Google App Engine in Python. I've had a look around and can't be sure what works in GAE and what doesn't, I'm also finding it hard to get example code of some of those I believe should work...

how to Reference the variable via db.run_in_transaction on google-app-engine .

this is my code: class A(db.Model): a=db.StringProperty() class demo(BaseRequestHandler): def get(self): a='' def fn(): global a a=A(a='www') a.put() db.run_in_transaction(fn) raise Exception(a.key()) and the error is : raise Exception(a.key()) AttributeErr...

Set Django ModelForm visible fields at runtime?

I have a Django model: class Customer(models.Model): first_name=models.CharField(max_length=20,null=True, blank=True) last_name=models.CharField(max_length=25,null=True, blank=True) address=models.CharField(max_length=60,null=True, blank=True) address2=models.CharField(max_length=60,null=True, blank=True) city=models.CharField...

MySQL: conduct a fuzzy search

I have a names table in my database and I would wish to conduct a fuzzy search on it for example my database contains: Name ID John Smith 1 Edward Smith 2 Gabriel Gray 3 Paul Roberts 4 At the moment when I search the database via python I can only do exact match searching. But I would like to be able to do fuzzy searching w...

Python: is it possible to mix generator and a recursive function ?

Is there a way to make the something like the following code work? add = lambda n: (yield n) or add(n+1) (answers don't need to be in functional style) ...

Fabric auto-login in Windows

Relevant question: http://stackoverflow.com/questions/2339735/fabric-password I configured Putty to login with private-public keys (no password) using this guide: http://www.codelathe.com/blog/index.php/2009/02/20/ssh-without-password-using-putty/ It works. Now I want to run Fabric with no password prompt. This does not work and I...

Implementing class descriptors by subclassing the `type` class

I'd like to have some data descriptors as part of a class. Meaning that I'd like class attributes to actually be properties, whose access is handled by class methods. It seems that Python doesn't directly support this, but that it can be implemented by subclassing the type class. So adding a property to a subclass of type will cause i...

Django - Custom dashboard view authentication issues

Django version 1.1.1 I have a custom dashboard view set up to override the django admin default like: (r'^admin/$', 'dashboard.views.dashboard'), (r'^admin/', include(admin.site.urls)), dashboard view authenticates with the @staff_member_required decorator This has been working fine with all users having superuser permissions but whe...

how to parse the remainder: [0] on google-app-engine .

my code is : class demo(BaseRequestHandler): def get(self): a=[[1,2,3],[3,6,9]] self.render_template('map/a.html',{'geo':a}) and the html is : {% for i in geo %} <p><a href="{{ i[0] }}">{{ i[0]}}</a></p> {% endfor%} and the error is : raise TemplateSyntaxError, "Could not parse the remainder: %s" % to...

extend/append list

I would like to either extend or append a list to the content of another list: I've got the following: l = (('AA', 1.11,'DD',1.2), ('BB', 2.22, 'EE', 2.3), ('CC', 3.33, 'FF', 3.45)) ls = [('XX', 7.77), ('YY', 8.88), ('ZZ', 9.99)] m = ['first', 'second', 'third'] for i in range(len(l)): result = [] for n in m: if n == "fi...

Speeding up regular expressions in Python

I need to quickly extract text from HTML files. I am using the following regular expressions instead of a full-fledged parser since I need to be fast rather than accurate (I have more than a terabyte of text). The profiler shows that most of the time in my script is spent in the re.sub procedure. What are good ways of speeding up my proc...

Possible to pass more than 1 argument to a context processor in Django?

Is it possible to pass more than 1 argument to a context processor in Django? In other words, in addition to the HttpRequest object, I would like to pass 1 or more additional argument? ...

How does Python's super() work with multiple inheritance?

I'm pretty much new in Python object oriented programming and I have trouble understanding the super() function (new style classes) especially when it comes to multiple inheritance. For example if you have something like: class First(object): def __init__(self): print "first" class Second(object): def __init__(self): ...

Is Python-based software considered less-professional than C++/compiled software?

I'm working on a plugin for some software that I'm planning on selling someday. The software I'm making it for has both a C++ SDK and a Python SDK. The C++ SDK documentation appears incomplete in certain areas and isn't documented that well. The Python SDK docs appear more complete and in general are much easier to work with. So I'm t...

Python object oriented model

I have something like the follwing. A person having many colors of cars of the same model belonging to some state. I have designed a person class as having attributes person name, car model, car year, car state, and car color as attributes. And color should be a list as a person can have many cars of different colors but of the same mo...

Django comment moderation error: AlreadyModerated at /

I'm trying to add the comments framework to a weblog I'm creating in Django. Adding the comments system appears to be working fine until I attempt to enable comment moderation. I add the following code to my models.py as per the instructions on the above link. My model is called Post which represents a post in the weblog. class PostMod...