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...
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...
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...
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...
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...
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...
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...
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...
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)
...
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...
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 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...
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...
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...
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...
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?
...
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):
...
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...
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...
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...