python

python arbitrarily incrementing an iterator inside a loop

I am probably going about this in the wrong manner, but I was wondering how to handle this in python. First some c code: int i; for(i=0;i<100;i++){ if(i == 50) i = i + 10; printf("%i\n", i); } Ok so we never see the 50's... My question is, how can I do something similar in python? For instance: for line in cdata.split('\...

Python variables

Hey, I'm trying to create a basic program that will generate a number based on variables entered by the user. The formula is a = b / (c * d) This is a formula for finding specific heat, whereas b=energy, c=mass, and d= change in temperature. So my problem is that I'm not making this program for myself, otherwise I could just assign ...

Google App Engine get PolyModel as child class

When I run Google App Engine likeso: from google.appengine.ext import db from google.appengine.ext.db import polymodel class Father(polymodel.PolyModel): def hello(self): print "Father says hi" class Son(Father): def hello(self): print "Spawn says hi" When I run, e.g. s = Son() s.put() son_fr...

BitString error on Windows XP?

Scott, I'd like to thank you for your BitString program. I am working on interpreting data from a neutron detector, and I've found that this module is just the tool I need. Unfortunately, I have yet to get the module to successfully pass test-bitstring.py. I'm running Windows XP and Python 3.1. I've downloaded your file bitstring-0.4...

Easiest way to turn a list into an HTML table in python?

lets say I have a list like so: ['one','two','three','four','five','six','seven','eight','nine'] and I want to experiment with turning this data into a HTML table of various dimensions: one two three four five six seven eight nine or one four seven two five eight three six nine or one two three...

what happens to a python object when you throw an exception from it

My class contains a socket that connects to a server. Some of the methods of the class can throw an exception. The script I'm running contains an outer loop that catches the exception, logs an error, and creates a new class instance that tries to reconnect to the server. Problem is that the server only handles one connection at a time (...

Python Question about global counter in Django Application?

Hi Everyone I was wondering if there is "global counter" in Django application, like the way I store "global counter" in Servlet Context scope in Tomcat. Thanks something like getServletContext().getAttribute("counter"); counter++; ...

How do you bind a language (python, for example) to another (say, C++)?

I'm far from a python expert but I hear this one all the time, about its C/C++ bindings. How does this concept work, and how does Python (and Java) bind to C-based APIs like OpenGL? This stuff has always been a mystery to me. ...

tail -f in python with no time.sleep

I need to emulate "tail -f" in python, but I don't want to use time.sleep in the reading loop. I want something more elegant like some kind of blocking read, or select.select with timeout, but python 2.6 "select" documentation specifically says: "it cannot be used on regular files to determine whether a file has grown since it was last r...

Python: Referencing another project

I want to be able to run my Python project from the command line. I am referencing other projects, so I need to be able run modules in other folders. One method of making this work would be to modify the Pythonpath environment variable, but I think this is an abuse. Another hack would be to copy all the files I want into a single direc...

How can I make images so that appengine doesn't make transparent into black on resize?

I'm on the google appengine, and trying to resize images. I do : from google.appengine.api import images image = images.resize(contents, w, h) And for some images I get a nice transparent resize, and others I get a black background. How can I keep the transparency for all images? Original : http://www.stdicon.com/g-flat/application...

Python code seems to be getting executed out of order.

At work I have a programming language encoded in a database record. I'm trying to write a print function in python to display what the record contains. This is the code I'm having trouble with: # Un-indent the block if necessary. if func_option[row.FRML_FUNC_OPTN] in ['Endif', 'Else']: self.indent = self.indent - 1 ...

Writing python client for SOAP with suds

Dear python programmers, I want to convert a perl SOAP client into a python SOAP client. The perl client is initialized like $url = 'https://host:port/cgi-devel/Service.cgi'; $uri = 'https://host/Service'; my $soap = SOAP::Lite -> uri($uri) -> proxy($url); I tried to replicate this in python 2.4.2 with suds 0.3.6 doing fro...

How to find which view is resolved from url in presence of decorators

For debugging purposes, I'd like a quick way (e.g. in manage.py shell) of looking up which view that will be called as a result of a specific URL being requested. I know this is what django.core.urlresolvers.resolve does, but when having a decorator on the view function it will return that decorator. Example: >>>django.core.urlresolvers...

Compile Matplotlib for Python on Snow Leopard

I've killed half a day trying to compile matplotlib for python on Snow Leopard. I've used the googles and found this helpful page (http://blog.hyperjeff.net/?p=160) but I still can't get it to compile. I see comments from other users on that page, so I know I'm not alone. I already installed zlib, libpng and freetype independently. I...

How to use buildout to create localized version of my project?

Hi, I am trying to create a localized version of my project. I started from the following: mkdir my cd my wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py After the last command I get the following message: Warning: wildcards not supported in HTTP. --08:42:17-- http://svn.zope.org/checkout/zc.buil...

Generate random UTF-8 string in Python

I'd like to test the Unicode handling of my code. Is there anything I can put in random.choice() to select from the entire Unicode range, preferably not an external module? Neither Google nor StackOverflow seems to have an answer. Edit: It looks like this is more complex than expected, so I'll rephrase the question - Is the following co...

How to find and run my old (global) version of Python?

Hi, I have locally installed a newer version of Python. For that I did the following: $ cd $ mkdir opt $ mkdir downloads $ cd downloads $ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz $ tar xvzf Python-2.6.2.tgz $ cd Python-2.6.2 $ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4 $ make $ make install In .bash_prof...

How was the syntax chosen for static methods in Python?

I've been working with Python for a while and I find the syntax for declaring methods as static to be peculiar. A regular method would be declared: def mymethod(self, params) ... return A static method is declared: def mystaticethod(params) ... return mystaticmethod = staticmethod(mystaticmethod) If you don't add the s...

Python: time a method call and stop it if time is exceeded

I need to dynamically load code (comes as source), run it and get the results. The code that I load always includes a run method, which returns the needed results. Everything looks ridiculously easy, as usual in Python, since I can do exec(source) #source includes run() definition result = run(params) #do stuff with result The only pr...