python

How to evaluate a custom math expression in Python

I'm writing a custom dice rolling parser (snicker if you must) in python. Basically, I want to use standard math evaluation but add the 'd' operator: #xdy sum = 0 for each in range(x): sum += randInt(1, y) return sum So that, for example, 1d6+2d6+2d6-72+4d100 = (5)+(1+1)+(6+2)-72+(5+39+38+59) = 84 I was using regex to replace all...

Java's equivalence to Python's "Got value: %s" % variable?

Java's equivalence to Python's "Got value: %s" % variable? ...

Extending a series of nonuniform netcdf data in a numpy array

Hello, I am new to python, apologies if this has been asked already. Using python and numpy, I am trying to gather data across many netcdf files into a single array by iteratively calling append(). Naively, I am trying to do something like this: from numpy import * from pupynere import netcdf_file x = array([]) y = [...some list of ...

google app engine error ,and i can't open it now.(python)

the error is : Errors occurred See the logfile 'D:\Program Files\Google\google_appengine\launcher\GoogleAppEngineLauncher.exe.log' for details why ? thanks ...

python calendar to calculate month backwards

Hi, we are trying to create a calendar function in python. we have created a small content management system, the requirement is, there will be a drop down list on the top right hand corner of the website, which will give the options - Months - 1 month, 2 months, 3 months and so on..., if the user selects 8 months then it should show the...

Python list comprehension to return edge values of a list

If I have a list in python such as: stuff = [1, 2, 3, 4, 5, 6, 7, 8, 9] with length n (in this case 9) and I am interested in creating lists of length n/2 (in this case 4). I want all possible sets of n/2 values in the original list, for example: [1, 2, 3, 4], [2, 3, 4, 5], ..., [9, 1, 2, 3] is there some list comprehension c...

vlc python bindings - how to receive keyboard input?

I'm trying to use VLC's python bindings to create my own little video player. The demo implementation is quite simple and nice, but it requires all the keyboard commands to be typed into the console from which the script was run. Is there any way I can handle keyboard input also when the video player itself has focus? Specifically, I ca...

Is there a production ready web application framework in Python?

I heard lots of good opinions about Python language. They say it's mature, expressive etc... I'm looking for production-ready enterprise application frameworks in Python. By "production ready" I mean : supports objective-relational mapping with caching and declarative desciption (like JPA, Hibernate etc..) controls oriented user interf...

How to stop the Bottle webserver when started from subprocess

Hello all, I would like to embed the great Bottle web framework into a small application (1st target is Windows OS). This app starts the bottle webserver thanks to the subprocess module. import subprocess p = subprocess.Popen('python websrv.py') The bottle app is quite simple @route("/") def index(): return template('index') ru...

python extract from switch output

I have some info back from a LAN switch as below Vlan 1 is administratively down, line protocol is down Vlan 2 is up, line protocol is up Helper address is 192.168.0.2 Vlan 3 is up, line protocol is up Helper address is not set Vlan 4 is up, line protocol is up Helper address is 192.168.0.2 Vlan 5 is down, line pro...

Wrapping a pure virtual method with multiple arguments with Boost.Python

Hello, I followed the "official" tutorial and others but still don't manage to expose this pure virtual method (getPeptide) : ms_mascotresults.hpp class ms_mascotresults { public: ms_mascotresults(ms_mascotresfile &resfile, const unsigned int flags, double ...

Activate a python virtual environment using activate_this.py in a fabfile on Windows

I have a Fabric task that needs to access the settings of my Django project. On Windows, I'm unable to install Fabric into the project's virtualenv (issues with Paramiko + pycrypto deps). However, I am able to install Fabric in my system-wide site-packages, no problem. I have installed Django into the project's virtualenv and I am able...

I can't login to my Django app when debug is set to False

I have a very strange problem, and I don't know how to fix or debug it. Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened): 1. I enter my login info, but It just redirects to the login page. 2. I restart the server, try to login, and it works fine, I get in. 3. a...

How to replace by regular expression to lowercase in python

I want to search key words (keys would be dynamic) and replace them in a certain format. For example: these data keys = ["cat", "dog", "mouse"] text = "Cat dog cat cloud miracle DOG MouSE" had to be converted to converted_text = "[Cat](cat) [dog](dog) [cat](cat) cloud miracle [DOG](dog) [MouSE](mouse)" Here is my code: keys = "cat...

Can Microsoft Visual C++ 2008 Redistributable Package be freely redistributed

I am planning to use py2exe to make an application developped with Python 2.6. It seems that my app need the VC redistribuables : http://www.py2exe.org/index.cgi/Tutorial#Step5 I've read this tutorial and the redistribuables license agreement and I am not sure if I can freely redistribute these files with my program. (I don't have VS20...

"UserWarning: Unbuilt egg for setuptools" - What does this actually mean?

Hiya. When I install things into a virtualenv using pip I often see the message "UserWarning: Unbuilt egg for setuptools". I always safely ignore it and go about my business and it doesn't seem to cause me any problems. But I've suddenly been smacked in the face with curiosity, and wondered if someone could explain what it means, exac...

what is a good way to do countif in python

I want to count how many members of an iterable meet a given condition. I'd like to do it in a way that is clear and simple and preferably reasonably optimal. My current best ideas are: sum(meets_condition(x) for x in my_list) and len([x for x in my_list if meets_condition(x)]) The first one being iterator based is presumably fast...

Embed a Python persistance layer into a C++ application - good idea?

say I'm about to write an application with a thin GUI layer, a really fat calculation layer (doing computationally heavy calibrations and other long-running stuff) and fairly simple persistance layer. I'm looking at building the GUI + calculation layer in C++ (using Qt for the gui parts). Now - would it be a crazy idea to build the pers...

AttributeError while adding colorbar in matplotlib

The following code fails to run on Python 2.5.4: from matplotlib import pylab as pl import numpy as np data = np.random.rand(6,6) fig = pl.figure(1) fig.clf() ax = fig.add_subplot(1,1,1) ax.imshow(data, interpolation='nearest', vmin=0.5, vmax=0.99) pl.colorbar() pl.show() The error message is C:\temp>python z.py Traceback (most re...

What's the simplest way to get the highest and lowest keys from a dictionary?

self.mood_scale = { '-30':"Panic", '-20':'Fear', '-10':'Concern', '0':'Normal', '10':'Satisfaction', '20':'Happiness', '30':'Euphoria'} I need to set two variables: max_mood and min_mood, so I can put some limits on a ticker. What's the easiest way to get the lowest and the highest keys? ...