python

timeout a subprocess

Hi, I realize this might be a duplicate of http://stackoverflow.com/questions/1191374/subprocess-with-timeout. If it is, I apologize, just wanted to clarify something. I'm creating a subprocess, which I want to run for a certain amount of time, and if it doesn't complete within that time, I want it to throw an error. Would something al...

Python Metaclass to Parametrize Inheritance

I've read some tutorials on Python metaclasses. I've never used one before, but I need one for something relatively simple and all the tutorials seem geared towards much more complex use cases. I basically want to create a template class that has some pre-specified body, but takes its base class as a parameter. Since I got the idea fr...

How to continue the task when fabric meet an error

When i define a task run on several remote server, if the task run on server one and meet a error, fabric will stop and Abort the task. But I want to make fabric to ignore the error and run the task on next server. how to make it? for example: $ fab site1_service_gw [site1rpt1] Executing task 'site1_service_gw' [site1fep1] run: e...

Running multiple python version

I want to run multiple Python version in my box. Is there anything like version manager in Python where I can switch between multiple Python version without having to call the full path of the python binary? I have tried virtualenv and it seems to only cover problems running multiple python libraries version. Thanks for your help. ...

Testing in Python - how to use assertRaises in testing using unittest?

Hi, I am trying to do a simple test in Python using unittest, to see if a class throws an exception if it gets an unsuitable input for the constructor. The class looks like this: class SummaryFormula: def __init__( self, summaryFormula): self.atoms = {} for atom in re.finditer( "([A-Z][a-z]{0,2})(\d*)", summaryForm...

How to convert an array of strings to an array of floats in numpy?

How to get from ["1.1", "2.2", "3.2"] to [1.1, 2.2, 3.2] in numpy? ...

Why does id({}) == id({}) and id([]) == id([]) in CPython?

Why does CPython (no clue about other Python implementations) have the following behavior? tuple1 = () tuple2 = () dict1 = {} dict2 = {} list1 = [] list2 = [] # makes sense, tuples are immutable assert(id(tuple1) == id(tuple2)) # also make...

Python - question about decimal arithmetic

I have 3 questions pertaining to decimal arithmetic in Python, all 3 of which are best asked inline: 1) >>> from decimal import getcontext, Decimal >>> getcontext().prec = 6 >>> Decimal('50.567898491579878') * 1 Decimal('50.5679') >>> # How is this a precision of 6? If the decimal counts whole numbers as >>> # part of the precision, is...

C++ to pyQt movie player Widget conversion example ??

http://doc.qt.nokia.com/4.6/multimedia-videowidget.html http://doc.trolltech.com/4.2/widgets-imageviewer.html I´ve found those links above but I must say I´m not familiar with C++ at all and I could not convert to PyQt ... Would be extremely helpfull if someone could post a simple conversion code here, so I could dig into that. Thanks...

I embedded a matplotlib graph of a sphere into Tkinter, and can no longer orbit it!

I embedded a matplotlib graph of a sphere into Tkinter. Now for some reason I've lost the ability to orbit the object, when dragging the mouse. Anyone have an idea of why this happened and how to fix this? #!/usr/bin/env python import matplotlib matplotlib.use('TkAgg') from mpl_toolkits.mplot3d import axes3d,Axes3D import matplotli...

How best to get map from key list/value list in groovy?

In python, I can do the following: keys = [1, 2, 3] values = ['a', 'b', 'c'] d = dict(zip(keys, values)) assert d == {1: 'a', 2: 'b', 3: 'c'} Is there a nice way to construct a map in groovy, starting from a list of keys and a list of values? ...

deleting rows in numpy array

I have an array that might look like this: ANOVAInputMatrixValuesArray = [[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 0.53172222], [ 0.78008333, 0.5938125, 0.481, 0.39883333, 0.]] Notice that one of the rows has a zero value at the end. I want to delete any row that contains a zero, while keeping any row that contains non-zero v...

In Python, can you have variables within triple quotes? If so, how?

This is probably a very simple question for some, but it has me stumped. Can you use variables within python's triple-quotes? In the following example, how do use variables in the text: wash_clothes = 'tuesdays' clean_dishes = 'never' mystring =""" I like to wash clothes on %wash_clothes I like to clean dishes %clean_dishes """ pri...

Google App Engine (Python)- Strange behaviour of REMOTE_ADDR

In order to make the registration process on my website easy, I allow users to enter their email address which I will send a verification code to or alternatively they can solve a captcha. The problem is that in order to prevent robots from registering accounts (with fake emails) I limit the number of registrations allowed per IP addres...

Updating a graphs coordinates in matplotlib

I have below a code that will plot a sphere, it's proportions are defined by prop, I'd like it so when the button is pressed prop's value changes to 5 and the graph is adjusted accordingly. How do I go about this? I know tkinter has .configure(), which allows one to adjust widget settings. I'm looking for something similar so that I ca...

Help editing a picture in python

I have to suppose I'm given a picture, there shouldnt be any user inputs or calls to media.chose file, so given a picture return the average red value of all the Pixels in that Picture (as an int). If the average calculation results in a non-integer value, then truncate the result. For example, if you average the values 10, 6 and 4, the ...

Determine if a dice roll contains certain combinations?

I am writing a dice game simulator in Python. I represent a roll by using a list containing integers from 1-6. So I might have a roll like this: [1,2,1,4,5,1] I need to determine if a roll contains scoring combinations, such as 3 of a kind, 4 of a kind, 2 sets of 3, and straights. Is there a simple Pythonic way of doing this? I've...

Self-referencing classes in python?

In Python, can you have classes with members that are themselves pointers to members of the type of the same class? For example, in C, you might have the following class for a node in a binary tree: struct node { int data; struct node* left; struct node* right; } How would you equivalently create this in python? ...

How does Worldviz Vizard compares to Panda3D and Pygame?

Is anybody familiar with Worldviz-Vizard's 3D engine for python? How does it compare to Panda3D? I have a feeling that it might be easier to learn but far more limited. They only support python 2.4 which also makes me not want to try it. ...

python paramiko

Have installed Paramiko for Python and PyCrypto for Windows 7 machine. import paramiko ssh = paramiko.SSHClient() Tried the above commands but I keep getting this error msg: AttributeError: 'module' object has no attribute 'SSHClient' but this error message goes away if I key in the above commands one line at a time. Any help?...