python

Printing numbers in python

I have a script that generates some numbers (specifically times in epoch form). Everytime it generates a number, I append the number to an array (called VALUES) and print both the array and that number. However, the number does not contain as many places after the decimal as the number in the array. For example, a sample output will ...

Send Raw hex data in jython udp packet

I'm experience with Java, but I have to integrate a java library into a co-workers python code. Enter jython, yay! We are trying to send a UDP packet with a very specific data section. We are building up the packet like so: version = 0x0001 referenceNumber = 0x2323 bookID = byteArray('df82818293819dbafde818ef') For easy of explanati...

How to install SSL for python 2.5 on Debian 4?

Hi, how to install SSL for Python 2.5 on Debian? I have tried: sudo easy_install ssl But getting: python setup.py build looking for /usr/include/openssl/ssl.h looking for /usr/include/krb5.h running build running build_py running build_ext building 'ssl._ssl2' extension creating build/temp.linux-i686-2.5 creating build/temp.linux-...

Problems adding path and calling external program from Python

I have an executable called "foo" in "/home/myname/mydir/" and am trying to call it from Python, but I am doing something basic and wrong here. Can you help me? import os, sys sys.path.append("/home/myname/mydir/") os.system("foo") # os.system("./foo") doesn't work either Thanks ...

Only allow 1 instance of a python script.

What is the best way to insure that only 1 copy of a python script is running? I am having trouble with python zombies. I tired creating a write lock using open("lock","w"), but python doesn't notify me if the file already has a write lock, it just seems to wait. ...

Modify python script to run on every file in a directory

Hi, so I have a python script which takes the filename as a command argument and processes that file. However, because I have 263 files which need the same processing, I was wondering whether the command argument section could be modified with a for loop to consecutively run through all the files in a folder? Cheers, Sat EDIT: The code...

Python - Find dominant/most common color in an image

Hi, I'm looking for a way to find the most dominant color/tone in an image using python. Either the average shade or the most common out of RGB will do. I've looked at the Python Imaging library, and could not find anything relating to what I was looking for in their manual, and also briefly at VTK. I did however find a PHP script whic...

Why does python think this is a local variable?

I have a global variable I called Y_VAL which is initialized to a value of 2. I then have a function, called f() (for brevity), which uses Y_VAL. def f(): y = Y_VAL Y_VAL += 2 However, when trying to run my code, python gives the error message: UnboundLocalError: local variable 'Y_VAL' referenced before assignment If I re...

How to get a progress bar for urllib2?

I currently use the following code to upload one file to a remote server: import MultipartPostHandler, urllib2, sys cookies = cookielib.CookieJar() opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler) params = {"data" : open("foo.bar") } request=opener.open("http://127.0.0.1/api.php", params) response = request.read(...

python and search?!

hello everybody... am looking for method and function watch i can search in web page ! ok I'll explain it : i tell my python file .. go to www.example.com and search for that world "Hello guest" and if my python file found that world "Hello guest" my python file print "the world found!" and if he don't found he print "the world not found...

Django (1.2) Forms: ManyToManyField Help Text

I hope I'm wrong, but it looks to me like the only way to have no help_text for a ManyToManyField is write an __init__ method for the form and overwrite self.fields[fieldname].help_text. Is that really the only way? I prefer to use CheckboxSelectMultple widgets, so am I really going to have to define an __init__ method for any form that ...

In Python, how does a for loop with `range` work?

for number in range(1,101): print number Can someone please explain to me why the above code prints 1-100? I understand that the range function excludes the last number in the specified range, however, what is the 'number' part of the syntax? I more used to C++ & Java where i'd write the code like: for (i = 1; i<101; i++) {return ...

Fitting a pareto distribution with (python) Scipy

I have a data set that I know has a Pareto distribution. Can someone point me to how to fit this data set in Scipy? I got the below code to run but I have no idea what is being returned to me (a,b,c). Also, after obtaining a,b,c, how do I calculate the variance using them? import scipy.stats as ss import scipy as sp a,b,c=ss.pareto...

Interpolation over an irregular grid

So, I have three numpy arrays which store latitude, longitude, and some property value on a grid -- that is, I have LAT(y,x), LON(y,x), and, say temperature T(y,x), for some limits of x and y. The grid isn't necessarily regular -- in fact, it's tripolar. I then want to interpolate these property (temperature) values onto a bunch of dif...

Pythonic syntax for appending an arbitrary class object list property

Is there an analog of setattr() that allows for appending an arbitrary list property of an instantiated class object? If not, is there a recommended way of doing so? This is a trivialized version of what I'm doing currently: foo = SomeClass() ... attr = "names" value = "Eric" values = getattr(foo, attr) values.append(value) setattr(foo...

Quick and dirty reports based on a SQL query

I never thought I'd ever say this but I'd like to have something like the report generator in Microsoft Access. Very simple, just list data from a SQL query. I don't really care what language is used as long as I can get it done fast. C#,C++,Python,Javascript... I want to know the quickest (development sense) way to display data from ...

How do I use repoze.who/repoze.what with SPNEGO?

I'm trying to do single sign-on (SSO) with an intranet web application written in Pylons and I'd like to use repoze.what for authorization. I have Apache configured with mod_sspi and it correctly authenticates the user and sets the REMOTE_USER environment variable. However, I can't figure out how to convince repoze.who that the user is,...

Using random.choice in conjuction with if statements

So I'm really new to programming, I just started learning Python yesterday and I'm having a little trouble. I've looked through a few tutorials and haven't come up with how to answer my question on my own, so I'm coming to you guys. quickList = ["string1", "string2"] anotherList1 = ["another1a", "another1b"] anotherList2 = ["another2a"...

Python Rpy R data processing optimization

I am writing a data processing program in Python and R, bridged with Rpy2. Input data being binary, I use Python to read data out and pass them to R, then collect results to output. Data are organized into pieces, each being around 100 Bytes (1Byte per value * 100 values). They just work now, but the speed is very low. Here are some o...

Merging Multiple KML Files

I cannot find a script to easily merge kml files; any ideas? Ideally I'd like something along the lines of kmlmerge $file $file, as I'm already working on a shell script for managing multiple kismet drone nodes. ...