python

'Query' object has no attribute 'kind' when using appcfg.py download_data

I'm having problems with bulk downloads -- all of my data is not being pulled down. I'm still debugging, but I see in my console: Traceback (most recent call last): File "/Users/matthew/local/opt/google_appengine/google/appengine/tools/adaptive_thread_pool.py", line 150, in WorkOnItems status, instruction = item.PerformWork(self.__th...

Should properties do nontrivial initialization?

I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted. So here's the steps my object does: Construct an object, with a ke...

PIL: Thumbnail and end up with a square image

Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need to end up displaying the image like this: <img src="/media/image.png" style="height:36px; width:36px" /> Can I have a letterbox style with either transparent or white around the image? ...

PIL: Image resizing : Algorithm similar to firefox's

I'm getting about the same bad looking resizing from all the 4 algorithms of PIL >>> data = utils.fetch("http://wavestock.com/images/beta-icon.gif") >>> image = Image.open(StringIO.StringIO(data)); image.save("/home/ptarjan/www/tmp/metaward/original.png") >>> >>> image = Image.open(StringIO.StringIO(data)); image.resize((36,36), Image.A...

python Invalid literal for float

Hi all. I am running a code to select chunks from a big file. I am getting some strange error that is "Invalid literal for float(): E-135" Does anybody know how to fix this? Thanks in advance. Actually this is the statement that is giving me error float (line_temp[line(line_temp)-1]) This statement produces error line_temp is a st...

Python: manipulating sub trees

I'm a nooby. I'd like to acknowledge Allen Downey, Jeffrey Elkner and Chris Meyers and 'How to think like a computer scientist' for what I know. I'm building a genetics inspired program to generate equations that match some provided problem. The node class looks like this: class Node(object): ''' ''' def __init__(self, car...

Handling big numbers in code

Hello, Im working on a programming problem where i need to handle a number involving 100000 digits . Can python handle numbers this big ? Thank You ...

Convert binary string to list of integers using Python

Hi, I am new to Python. Here's what I am trying to do: Slice a long binary string into 3 digit-long chunks. Store each "chunk" into a list called row. Convert each binary chunk into a number (0-7). Store the converted list of numbers into a new list called numbers. Here is what I have so far: def traverse(R): x = 0 ...

Django : select_related with ManyToManyField

I have : class Award(models.Model) : name = models.CharField(max_length=100, db_index=True) class Alias(models.Model) : awards = models.ManyToManyField('Award', through='Achiever') class Achiever(models.Model): award = models.ForeignKey(Award) alias = models.ForeignKey(Alias) count = models.IntegerField(default=1) ...

Reliably detect Windows in Python

I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The platform.platform function comes close but only returns a string. Unfortunately I don't know what to search for in that string for it to yield a reliable result. Does anyone know w...

Globbing the processing of an object's attributes in Python?

Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True) first_name = models.CharField(max_length=255, null=True, blank=True) middle_names = models.CharField(max_length=255, null=True, blank=True) birth_year = WideYear(null=True, blank=True) birth...

MySQL INSERT data does not get stored in proper db, only temporary?

I'm having trouble with MySQL or Python and can't seem to isolate the problem. INSERTs only seem to last the run of the script and are not stored in the database. I have this script: import MySQLdb db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="example") dbcursor = db.cursor() dbcursor.execute("select * fro...

Verify CSV against given format

I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to: "<String>","<String>",<Int>,<Float> That will be processed later. I would like to verify the file fits a specified format so that the program that shall later use the file doesnt receive unexpected input and that there ar...

PyGTK: IM Client Window

I'm trying to write something very similar to an IM client (for learning purposes only). I don't know how to write the Chat window. I want to display Users picture, name and message as any other IM client. The problem is that I don't know which gtk widget is best suited for it. Currently I use TextView and TextBuffers but I can't display...

Applescript - pygame, application bundle

I'm trying to learn pygame, And I found the best way to have the finished game (assuming python 2.6 and pygame installed) is to have an applescript that runs it, and saved as an app bundle (with python files etc. inside the bundle). Here is what I have: do shell script "cd " & the quoted form of the POSIX path of (path to me) & "Content...

how to convert base64 /radix64 public key to a pem format in python

is there any python method for converting base64 encoded key to a pem format . how to convert ASCII-armored PGP public key to a MIME encoded form. thanks ...

IF statement causing internal server error with webpy

I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl' placeholders = { 'site_name' : 'pypular' } # If we passed placeholders vars, append them if extra_placeholders != None: for k, v in extra_placehol...

C++ with Python embedding: crash if Python not installed

I'm developing on Windows, and I've searched everywhere without finding anyone talking about this kind of thing. I made a C++ app on my desktop that embedded Python 3.1 using MSVC. I linked python31.lib and included python31.dll in the app's run folder alongside the executable. It works great. My extension and embedding code definitely ...

Django: Simple rate limiting

Many of my views fetch external resources. I want to make sure that under heavy load I don't blow up the remote sites (and/or get banned). I only have 1 crawler so having a central lock will work fine. So the details: I want to allow at most 3 queries to a host per second, and have the rest block for a maximum of 15 seconds. How could ...

Upgrade python in linux

I have a linux VPS that uses an older version of python (2.4.3). This version doesn't include the UUID module, but I need it for a project. My options are to upgrade to python2.6 or find a way to make uuid work with the older version. I am a complete linux newbie. I don't know how to upgrade python safely or how I could get the UUID modu...