I am running this code to see the performance impact of the keyczar encryption library from google:
from keyczar import keyczar, keys
def main(iters):
key = keys.RsaPrivateKey.Generate()
msg = "ciao"
crypt = None
for i in range(iters):
print i, "\r",
crypt = key.Encrypt(msg)
for i in range(iters):
...
Possible Duplicate:
Getting python.exe path at run time
I have a python app that launches other apps with explicit calls to C:\python25\python.exe, but this doesn't work if the user has 2.6 installed or if they have it installed to another location. There is a %PYTHON% variable for the exe, but this is only available to the user...
After reading "Using your signals" I am wondering if it is possible to connect the signals to "sinks" in an "anonymous" way?
In order words, if the example following (snippet from reference above):
aCar = Car()
aCar.connect('engine-started', myCallback)
Is it possible just to connect myCallback to all the signal engine-started sourc...
I have two models A and B. All B objects have a foreign key to an A object. Given a set of A objects, is there anyway to use the ORM to get a set of B objects containing the most recent object created for each A object
Here's an simplified example:
Class Bakery(models.Model):
town = models.CharField()
Class Cake(models.Model):
...
Can somebody tell me why this should be wrong?
#Each new term in the Fibonacci sequence is generated
#by adding the previous two terms. By starting with 1 and 2,
#the first 10 terms will be:
#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#Find the sum of all the even-valued terms in the sequence
#which do not exceed four million.
sum=2
list...
I currently have these models:
class Category(models.Model):
name = models.CharField(max_length=200)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child')
description = models.TextField(blank=True,null=True)
class Item(models.Model):
name = models.CharField(max_length=500)
...
tag = mod...
Have a homework assignment that requires I output 4 different floats to two decimal places.
This is what I have:
print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l'
Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'?
Note: Using Python 2.6.
...
I have following list:
mylist = ['Hello,\r', 'Whats going on.\r', 'some text']
When I write "mylist" to a file called file.txt
open('file.txt', 'w').writelines(mylist)
I get for every line a little bit text because of the \r:
Hello,
Whats going on.
some text
How can I manipulate mylist to substitute the \r with a space? In the e...
Hey, I have a wxpython frame object with a status bar. I can do self.SetStatusText() without any trouble, but when I do self.GetStatusText() I get this error:
Traceback (most recent call last):
File
"D:\python\code\test.pyw",
line 87, in <module>
frame = mainframe() File "D:\python\code\test.pyw",
line 40, in __init__
...
I'm trying to enable IPv6 in a Python 2 application and am running into trouble. Whenever I try to bind to an IPv6 socket, a socket.error: getsockaddrarg: bad family exception is thrown. I can reproduce the error simply by doing:
import socket
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.bind(('', 12345))
This code work...
I want to perform some delete() and some save() methods on some objects that are not an instance of the current class I'm in. I'm trying to do this in an overloaded save() method of a class. Here is the scenerio:
class Item(models.Model):
name = models.CharField(max_length=500)
category = models.ForeignKey(Category, null=True,...
The question just came up!
I have seen in web apps we get flash images generated on the fly how is it achieved? Any api for programming languages (Java Python)?
PS: It's adobe flash movie / image or swf
...
I am aware of the ability to edit text with beautifulsoup, is it possible to edit the href links? I would like to be able to take say <a href="/foo/bar/"> and use beautifulsoup to change it to <a href="http://www.foobarinc.com/foo/bar/">. I am not sure how I would use beautifulsoup to do this? Any help, much appreciated.
...
After reading through the other questions on StackOverflow, I got a snippet of Python code that is able to make requests through a Tor proxy:
import urllib2
proxy = urllib2.ProxyHandler({'http':'127.0.0.1:8118'})
opener = urllib2.build_opener(proxy)
print opener.open('https://check.torproject.org/').read()
Since Tor works fine in Fir...
I am looking to se if this code can be optimized.
def gB(a,b,c):
x=len(b)
d=a.find(b)+x
e=a.find(c,d)
return a[d:e]
print gB("abc","a","c")
...
Following this tutorial on WxPython, I've noticed that in the Find/Replace Dialog example there are extra panels where it doesn't seem like they're actually doing anything. In fact, they seem to mess up even more the layout (though that is probably some mistake I made somewhere) For example, the tutorial has this code:
panel = wx.Panel(...
I've created a Sphinx document using sphinx-quickstart.
Are there any good examples/tutorials about customizing the look? Specifically to modify the header and add a logo.
Are there some projects with downloadable Sphinx docs? I would like to see how they've customized their look.
update: Adding a logo is supported in the default s...
In general, it's better to do a single query vs. many queries for a given object. Let's say I have a bunch of 'son' objects each with a 'father'. I get all the 'son' objects:
sons = Son.all()
Then, I'd like to get all the fathers for that group of sons. I do:
father_keys = {}
for son in sons:
father_keys.setdefault(son.father.key...
I've got a an app where I'm storing posts and their authors. Very
straightforward each post has one author model.
The problem is this: I fetch the last 10 posts using one call, using
fetch() with limit = 10. But when I print them out, GAE uses 10 extra
gets to access the author details, because the author object is a
reference prope...
Recently, a correspondent mentioned float.as_integer_ratio(), new in Python 2.6, noting that typical floating point implementations are essentially rational approximations of real numbers. Intrigued, I had to try π:
>>> float.as_integer_ratio(math.pi);
(884279719003555L, 281474976710656L)
I was mildly surprised not to see the more acc...