python

Faster App Engine Development Datastore Alternative

Hello, Is there a way to use a real database(SQLite, Mysql, or even some non-relational one) as datastore for development, instead of memory/file datastore that is provided. I saw few projects, GAE-SQLite(did not seem to be working) and one tip about accessing production datastore using remote api (still pretty slow for large datasets...

Python Program converted into Java

Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. Could someone please help with what I've done and umm give me som...

sum of bytes with unsigned long overflow in python

how to translate this piece of C code into Python >=2.6 ? unsigned long memSum(unsigned char *p, unsigned long len) { unsigned long i, sum=0; for(i=0; i<len; i++) sum = sum + *p++; return sum; } of course f=open("file_to_sum",'rb') m = f.read() f.close() sum( array.array('B', m) ) does not work ...

Pylons Uploading Distorted Images on Windows

I'm creating an web app in Pylons, and am working on an image upload action. This is currently running using egg:paste#http on my windows machine, in the basic development configuration described in the pylons documentation quickstart. When I POST an image to my application, then move the image to the web root directory, then pull the ...

How can I keep on-the-fly application-level statistics in an application running under Apache?

I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like: requests per second, broken down by types of request latency to make requests to various backend services via thrift (broken down by service and server) number of errors being served per sec...

Determining Whether a Directory is Writeable

Hi Stackoverflow, What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. ...

Group by hour in SQLAlchemy?

How do I group query results by the hour part of a datetime column in SQLAlchemy? ...

How to download a file via the browser from Amazon S3 using Python (and boto) at Google App Engine?

I have a python script running inside the Google App Engine with boto 1.9b that gets all keys inside a S3-Bucket. The output is formated as a HTML-Table. bucket_instance = conn_s3.get_bucket(bucketname) liste_keys = bucket_instance.get_all_keys() table = '<table>' for i in range(laenge_liste_keys): table = table + '<tr><td>'+str(lis...

Read XML with multiple top-level items using Python ElementTree?

How can I read an XML file using Python ElementTree, if the XML has multiple top-level items? I have an XML file that I would like to read using Python ElementTree. Unfortunately, it has multiple top-level tags. I would wrap <doc>...</doc> around the XML, except I have to put the <doc> after the <?xml> and <!DOCTYPE> fields. But figuri...

Python: getting filename case as stored in Windows?

Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system? E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this is inconsequential for vario...

Does python have the equivalent of Perl's regex "local" variable?

While searching for a solution to a python regular expression problem I found this page which demonstrates that [some version of] perl allows variables within regular expressions. e.g. a perl regex something like: ^(?{ local $d=0}\((?{ $d++ }.*?\)(?d--) Where variable $d is incremented and decremented depending on which part of the ...

py2exe and win32com

Can py2exe create standalone executables even ones requiring the win32com package? I've googled / searched SO to no avail. ...

Cannot solve mod_wsgi exception in Django setup

I'm working with my hosting provider to get a Django application up and running, but neither of us are very experienced and we've basically hit a complete dead end. I don't have direct access to the conf file but here's how its contents have been described to me: <IfModule mod_wsgi.c> WSGIScriptAlias /fredapp/ /home/fred/public_html/cg...

Python XML Parsing Confusion

Hey all- I'm using xml.dom.mindom in Python and have retrieved the book node in the below XML tree. I want to get a list of all children nodes. In this case, I would think there would only be one. <Book> <Title>Why is this so hard</Title> </Book When I call: nodeList = bookNode.childNodes print "nodeList has " + str(nodeList...

Preserving argument default values while method chaining

If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee() without having to c...

which style is preferred?

Option 1: def f1(c): d = { "USA": "N.Y.", "China": "Shanghai" } if c in d: return d[c] return "N/A" Option 2: def f2(c): d = { "USA": "N.Y.", "China": "Shanghai" } try: return d[c] except: return "N/A" So that I can then call: for c in ("China", "Japan"): for f in (f1, f2): prin...

Why does not the Python MSI installers come with Tcl/Tk header files?

The MSI installers downloadable from python.org does not include Tcl/Tk header (not source) files (that are required to compile some packages like matplotlib). Does anyone know of the rationale behind not including them? ...

Math and change field color

from django.db import models from django.contrib.auth.models import User class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 30) lot_no = models.CharField(max_length = 30) inventory = models.IntegerField() commited = models.IntegerField() reorder = ...

Python extensions that can be used in all varieties of python (jython / IronPython / etc.)

In the 'old days' when there was just cpython, most extensions were written in c (as platform independent as possible) and compiled into pyd's (think PyCrypto for example). Now there is Jython, IronPython and PyPy and the pyd’s do not work with any of them (Ironclad aside). It seems they all support ctypes and that the best approach MI...

How to serialize db.Model objects to json?

When using from django.utils import simplejson on objects of types that derive from db.Model it throws exceptions. How to circumvent this? ...