python

Python "Event" equivalent in Java?

What's the closest thing in Java (perhaps an idiom) to threading.Event in Python? ...

DJANGO - How do you access the current model instance from inside a form.

class EditAdminForm(forms.ModelForm): password = username.CharField(widget=forms.TextInput()) password = forms.CharField(widget=forms.PasswordInput()) password_confirm = forms.CharField(widget=forms.PasswordInput(), initial=???) You can see what I'm trying to do here. How would I go about pre-populating the pasword_confirm ...

sound lib python

im looking for a sound lib for python that can tall me per frame the volume of a sound file or a software that can do a noise gate,preferd command line software thanx!! ...

Unable to make a factorial function in Python

My code import sys number=int(sys.argv[1]) if number == 0 fact=1 else fact=number for (x=1; x<number; x++) fact*=x; // mistake probably here print fact I get the error File "factorial.py", line 5 if number == 0 ^ SyntaxError: invalid syntax How can you make a factorial function in Pyt...

Pylons is confusing: help!

Hi. I'm a long-time PHP developer looking to try out Python for web development. I've used Python in the past a bit, but I'm still quite new at it. I've taken a look at Pylons, and I have to say that it's extremely confusing to me. All the documentation I can find are just "copy and paste this" tutorials which don't seem to explain muc...

Unable to see Python's approximations in mathematical calculations

Problem: to see when computer makes approximation in mathematical calculations when I use Python Example of the problem: My old teacher once said the following statement You cannot never calculate 200! with your computer. I am not completely sure whether it is true or not nowadays. It seems that it is, since I get a lot zeros for it...

Context-sensitive string splitting, preserving delimiters

I have a string of the form "foo-bar-1.23-4", and I need to split at the first hypen followed by a numeral, such that the result is ['foo-bar', '1.23-4']. I've tried the following: >>> re.split('-\d', 'foo-bar-1.23-4', 1) ['foo-bar', '.23-4'] and >>> re.split('-(\d)', 'foo-bar-1.23-4', 1) ['foo-bar', '1', '.23-4'] with suboptimal r...

Get a dict of all variables currently in scope and their values

Consider this snippet: globalVar = 25 def myfunc(paramVar): localVar = 30 print "Vars: {globalVar}, {paramVar}, {localVar}!".format(**VARS_IN_SCOPE) myfunc(123) Where VARS_IN_SCOPE is the dict I'm after that would contain globalVar, paramVar and localVar, among other things. I'd like to basically be able to reference all th...

Convert param into python ?

Hello everyone, I am trying to learn web programming in python. I am converting my old php-flash project into python. Now, I am confused about how to set param value and create object using python. FYI I used a single php file, index.php to communicate with flash.swf. So, my other php files like login.php, logout.php, mail.php, xml.php ...

Python 2.6 - Upload zip file - Poster 0.4

Hi Folks, I came here via this question: http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script And by and large it's what I need, plus some additional. Besides the zipfile som additional information is needed and the POST_DATA looks something like this: POSTDATA =-----------------------------293432744627...

Get the index of an element in a queryset

Hi I have a QuerySet, let's call it qs, which is ordered by some attribute which is irrelevant to this problem. Then I have an object, let's call it obj. Now I'd like to know at what index obj has in qs, as efficiently as possible. I know that I could use .index() from Python or possibly loop through qs comparing each object to obj, bu...

Splitting a string @ once using different seps

datetime = '0000-00-00 00:00:00'.split('-') Right now it just splits it at the hyphen, but is it possible to split this string at both -'s and :'s ? ...

can I use expect on windows without installing cygwin?

expect is a module used for spawning child applications and controlling them. I'm interested in python/ruby. ...

Does Key.from_path hit the datastore?

I have a list of key names that I want to bulk fetch (the key names are stored in a StringListProperty attached to an entity). My general plan was to do: usernames = userrefInstance.users # A collection of strings on another model. keys = [Key.from_path('User', key_name) for username in usernames] users = db.get(keys) My questio...

Django unit testing with date/time-based objects

Suppose I have the following Event model: from django.db import models import datetime class Event(models.Model): date_start = models.DateField() date_end = models.DateField() def is_over(self): return datetime.date.today() > self.date_end I want to test Event.is_over() by creating an Event that ends in the futur...

Encrypt a string using a public key

I need to take a string in Python and encrypt it using a public key. Can anyone give me an example or recommendation about how to go about doing this? ...

Best Practise for transferring a MySQL table to another server?

Hello dear fellow SOers, I have a system sitting on a "Master Server", that is periodically transferring quite a few chunks of information from a MySQL DB to another server in the web. Both servers have a MySQL Server and an Apache running. I would like an easy-to-use solution for this. Currently I'm looking into: XMLRPC RestFul Ser...

Making application multilingual

I have a application written in wxPython which I want to make multilingual. Our options are using gettext http://docs.python.org/library/gettext.html seprating out all UI text to a messages.py file, and using it to translate text I am very much inclined towards 2nd and I see no benefit in going gettext way, using 2nd way i can have ...

What is the most secure python "password" encryption

Hi, I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has accomplished t...

How to do cleanup reliably in python?

I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references. I think It'd solve if I'd find a reliable way to ho...