python

AppEngine: Will the items stored in a StringListProperty always remain in the same order?

After looking through the docs on App Engine and the StringListProperty or the ListProperty I can't seem to find whether there is a guarantee on the order of the items in the list. That is, I'd like to be certain that the list order stays the same despite putting and getting from the DataStore: instance = MyModel() instance.list_propert...

python lotus notes: odbc connect error

Hello Everybody... I am developing a client server application for a cross-database system. I am using Eclipse IDE with Python 2.5 and PyODBC2.5; need to read content from a Lotus Notes database, so run some basic query like - SELECT peronname FROM tablename. 'import pyodbc' is ok - python see it! But when I try to run conn = pyodbc...

when to use an alternative Python distribution?

Hello, I have been programming in Python for a few years now and have always used CPython without thinking about it. The books and documentation I have read always refer to CPython too. When does it make sense to use an alternative distribution (PyPy, Stackless, etc)? Thanks! ...

how to collate output in python logging memoryhandler + smtphandler

I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message. This seems like it should be trivi...

Python xml.dom.minidom Unicode

Hi there, I'm trying to create an xml document in python, however some of the strings i'm working with are encoded in unicode. Is there a way to create a text node using xml.dom.minidom using unicode strings? Is there another module I can use? Thanks. ...

CherryPy variables in html

I have a cherryPy program that returns a page that has an image (plot) in a table. I would also like to have variables in the table that describe the plot. I am not using any templating just trying to keep it really simple. In the example below I have the variable numberofapplicants where I want it but it does not output the value of the...

Python: static variable decorator

I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first. I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use the below syntax, if possible...

Embed Python in NI CVI(LabWindows)

I need to access LabWindows API and/or fucntions written in labwindows from Python. My approach so far I have been able to do so in Visual studio using SWIG to some extent, but my dll creation fails when i try to generate it in Labwindows using the source file and the SWIG generated wrapper file. ...

Getting a list of child entities in App Engine using get_by_key_name (Python)

My adventures with entity groups continue after a slightly embarrassing beginning (see Under some circumstances an App Engine get_by_key_name call using an existing key_name returns None). I now see that I can't do a normal get_by_key_name call over a list of entities for child entities that have more than one parent entity. As the Mode...

Automatically restart program when error occur

The program is like this: HEADER CODE urllib2.initialization() try: while True: urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except Exception, e: print e FOOTER CODE My question is when error occurs (timeout, connection reset by peer, etc), how to restart from urll...

Calculate web page size in python

How would I go about calculating the size of a web page (url) using Python. I tried urllib2 and grabbing the content-length header but it wasn't present. import urllib2 url = 'http://www.google.com/' r = urllib2.urlopen(url) #Not sure what to do from here ...

Tools/Modules to generate advanced reports from unittest.TestResult?

Hello folks! I am not satisfied by the text-formatting we use at my company for our unittest outputs, because it does not allow me to see, say, that a Test NEVER ever passed, or that a specific Test passed for the first time during that testRun. The current output does not allow me to have a clear view of the situation: All tests: 4***...

Determine if a script is running in pythonw?

I would like to redirect stderr and stdout to files when run inside of pythonw. How can I determine whether a script is running in pythonw or in python? ...

Python Error Handling with try/finally

I have a try/finally clause in my script. Is it possible to get the exact error message from within the finally clause? ...

In what version of Python was set initialisation syntax added

I only just noticed this feature today! s={1,2,3} #Set initialisation t={x for x in s if x!=3} #Set comprehension t=={1,2} What version is it in? I also noticed that it has set comprehension. Was this added in the same version? Resources Sets in Python 2.4 Docs What's new in Python 3.0 ...

Using non-hashable Python objects as keys in dictionaries

Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys: frozenset(a.items())#Can be put in the dictionary instead Is there a method of using arbitrary objects as keys in dictionari...

Preserve case in ConfigParser?

I've tried to use python's ConfigParser module to save settings. For my app it's important that I preserve the case of each name in my sections. The docs mention that passing str() to ConfigParser.optionxform() would accomplish this, but it doesn't work for me. The names are all lowercase. Am I missing something? <~/.myrc contents> [rul...

Pamie and python-win32 question

hello, currently im making some web scrap script. and i was choice PAMIE to use my script. actually im new to python and programming. so i have no idea ,if i use PAMIE,it really helpful to make script to relate with win32-python. ok my problem is , while im making script,i was encounter two probelm. first , i want to let work my script w...

Python Pipes - What Happens When Reading Output Incrementally

According to a section in this presumably accurate book, A common use of pipes is to read a compressed file incrementally; that is, without uncompressing the whole thing at once. The following function takes the name of a compressed file as a parameter and returns a pipe that uses gunzip to decompress the contents: de...

Including non-Python files with setup.py

How do I make setup.py include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.) I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the topmost __init__.py.) I want it to stay exac...