Pyglet only seems to use points. Is there a way to convert easily? Surely there must be a simple way because it's something obviously important, to be able to use pixels for text height.
class Font():
def __init__(self,font,size):
self.size = size
self.font = font
def return_surface(self,label):
surface =...
I have a reviews/ratings web application, a la Digg. My django app content has the following model:
class Content(models.Model):
title = models.CharField(max_length=128)
url = models.URLField(max_length=2048)
description = models.TextField(blank=True)
class Recommendation(models.Model):
user = models.ForeignKey(User)
...
I'm using an application that gives a timed output based on how many times something is done in a minute, and I wish to manually take the output (copy paste) and have my program, and I wish to count how many times each minute it is done.
An example output is this:
13:48 An event happened.
13:48 Another event happened.
13:49 A new ev...
I have written a python extension wrapping an existing C++ library live555 (wrapping RTSP client interface to be specific) in SWIG. The extension works when it is operated in a single thread, but as soon as I call the event loop function of the library, python interpreter never gets the control back. So if I create a scheduled task using...
I'd like to set non-integer primary keys for a table using some kind of hash function. md5() seems to be kind of long (32-characters).
What are some alternative hash functions that perhaps use every letter in the alphabet as well as integers that are perhaps shorter in string length and have low collision rates?
Thanks!
...
Suppose you take the strings 'a' and 'z' and list all the strings that come between them in alphabetical order: ['a','b','c' ... 'x','y','z']. Take the midpoint of this list and you find 'm'. So this is kind of like taking an average of those two strings.
You could extend it to strings with more than one character, for example the midpo...
i'm trying to make a group of defs in one file so then i just can import them whenever i want to make a script in python
i have tried this:
def get_dblink( dbstring):
"""
Return a database cnx.
"""
global psycopg2
try
cnx = psycopg2.connect( dbstring)
except Exception, e:
print "Unable to connect to DB. Error [%s]" % ( e,)
...
which one are you using on google app engine?
what were the reasons behind your decision?
...
How would you convert an arbitrary string into a unique integer, which would be the same across Python sessions and platforms? For example hash('my string') wouldn't work because a different value is returned for each Python session and platform.
...
Hi,
I have a XML file that is managed by other programs, I am writing a web service such that users are able to query this file. In essence i am using a xml based database instead of using sql as the model database in Django.
how do i do this? all the tutorials that i find use a sql database in the backend. is there a way to use the xm...
For some sensitive data I decided to store it AES-encrypted on disc. I've implemented the encryption using PyCrypto.
Furthermore, the data is important, and the stored encrypted data will be my only copy of it (backups aside), so I looked for some means of retrieving the data without using PyCrypto to have a fallback given the possibili...
I'm looking for a very quick way to generate an alphanumeric unique id for a primary key in a table.
Would something like this work?
def genKey():
hash = hashlib.md5(RANDOM_NUMBER).digest().encode("base64")
alnum_hash = re.sub(r'[^a-zA-Z0-9]', "", hash)
return alnum_hash[:16]
What would be a good way to generate random nu...
Hi, i was curious if there is some sort of way to change the look and feel of wxpython to something that is more standardized. I am writing a small application for windows and mac os x. And i noticed that Mac formats the layout and look of my application pretty terribly. I looked around online and could not find anything. Any ideas?
...
OK I love Python's zip() function. Use it all the time, it's brilliant. Every now and again I want to do the opposite of zip(), think "I used to know how to do that", then google python unzip, then remember that one uses this magical * to unzip a zipped list of tuples. Like this:
x = [1,2,3]
y = [4,5,6]
zipped = zip(x,y)
unzipped_x, unz...
I want to call a redefined private method from an abstract parent class. I am using django if that matters.
class Parent(models.Model):
def method1(self):
#do somthing
self.__method2()
def method2(self):
pass # I also tried calling up a prent method with super
class child(Parent):
def method1(sel...
This is probably a stupid question, but what's the best way to clear class variables between instances?
I know I could reset each variable individually in the constructor; but is there a way to do this in bulk?
Or am I doing something totally wrong that requires a different approach? Thanks for helping ...
class User():
def _...
json module was added in python 2.6 but GAE supports 2.5 only.
How can I use it there?
...
How can I access the number of rows affected by:
cursor.execute("SELECT COUNT(*) from result where server_state='2' AND name LIKE '"+digest+"_"+charset+"_%'")
...
I have an emergent bug that I've got to track down tomorrow. I know a previous hg revision which was good so I'm thinking about using hg bisect.
However, I'm on Windows and don't want to get into DOS scripting.
Ideally, I'd be able to write a Python unit test and have hg bisect use that. This is my first attempt.
bisector.py
#!/usr/b...
Why do I get a syntax error running this code? If I remove the highlighted section (return cards[i]) I get the error highlighting the function call instead.
Please help :)
def dealcards():
for i in range(len(cards)):
cards[i] = ''
for j in range(8):
cards[i] = cards[i].append(random.randint(0,9)
retu...