python

Make a tkinter window appear over all other windows

#!/usr/bin/env python # Display window with toDisplayText and timeOut of the window. from Tkinter import * def showNotification(notificationTimeout, textToDisplay): ## Create main window root = Tk() Button(root, text=textToDisplay, activebackground="white", bg="white", command=lambda: root.destroy()).pack(side=LEFT) r...

How can I do python/ruby/javascript style generators in actionscript?

I want to use coroutines in actionscript to implement a state machine. I'd like to be able to do something like the following function stateMachine():void { sendBytes(0xFFFF); var receiveBytes:ByteArray = yield() sendBytes(receiveBytes); } stateMachine.send( Socket.read() ) like in this blog entry ...

What's a better way to handle this in Python

Simple problem, I have it solved .. but python has a million ways to solve the same problem. I don't want the most terse solution, I just want one that makes more sense than the following: # sql query happens above, returns multiple rows rows = cursor.fetchall() cursor.close() cntdict = {} for row in rows: a, b, c = row[0], row[1], row...

Reading a file via open().read() vs storing it in a variable

I've written this small app in Python that will generate paragraphs of dummy text, kind of like this site, except it'll work offline. Right now you're supposed to provide a reasonably long text file (I'm currently using books from Project Gutenberg), which it will call open() and then read() on to get the initial string for the operation...

"This website is temporarily unavailable, please try again later." error on Google App Engine

I recently launched a site on Google App Engine using Python. I'm in Korea, but my client is in California, USA. He and others in his area periodically run into periods of time when they receive this error message instead of the site: This website is temporarily unavailable, please try again later. I cannot figure out what is causi...

Is there a better way to iterate over two lists, getting one element from each list for each iteration?

I have a list of Latitudes and one of Longitudes and need to iterate over the latitude and longitude pairs. Do you think it's be better to: A) (assume that equal lengths is already checked) for i in range(len(Latitudes): Lat,Long=(Latitudes[i],Longitudes[i]) *** EDIT .... or, B) for Lat,Long in [(x,y) for x in Latitudes for...

how to add all of these values in a python dictionary

last one for the night, want to see what clever ways there are with python to add all of the 'count' values from the following type of dictionary: {0: {'count': 1000}, 1: {'count': 2000}} so the end result should be an int value of 3000. ...

Mass string replace in python?

Say I have a string that looks like this: str = "The &yquick &cbrown &bfox &Yjumps over the &ulazy dog" You'll notice a lot of locations in the string where there is an ampersand, followed by a character (such as "&y" and "&c"). I need to replace these characters with an appropriate value that I have in a dictionary, like so: dict =...

Nested Methods? Why are they useful?

So I'm just learning some new stuff in C# & Python. Turns out both lanuages support nested methods (C# sort of does). Python: def MyMethod(): print 'Hello from a method.' def MyInnerMethod(): print 'Hello from a nested method.' MyInnerMethod() C# (using new features in .NET 3.5):* static void Main() { Con...

Is there a GEDCOM parser written in Python?

GEDCOM is a standard for exchanging genealogical data. I've found parsers written in C perl Ruby and even Factor but none so far written in Python. The closest I've come is the file _GedcomParse.py from the GRAMPS project, but that is so full of references to GRAMPS modules as to not be usable for me. I just want a simple standal...

How to make PHP output a sound (beep)?

What's the PHP verson of this python code? import winsound winsound.Beep(537, 2000) ...

Tornado Web Framework Mysql connection handling

I have recently been exploring the Tornado web framework to serve a lot of consistent connections by lots of different clients. I have a request handler that basically takes an RSA encrypted string and decrypts it. The decrypted text is an XML string that gets parsed by a SAX document handler that I have written. Everything works perf...

What is so bad with threadlocals

Everybody in Django world seems to hate threadlocals(http://code.djangoproject.com/ticket/4280, http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser). I read Armin's essay on this(http://lucumr.pocoo.org/2006/7/10/why-i-cant-stand-threadlocal-and-others), but most of it hinges on threadlocals is bad because it is inelegant. I...

Methods to create text preview from a font

I'm currently using ImageMagick's convert command to create text preview (.png) from .ttf font file. Overall, it's better in auto text positioning despite it failed to read some valid .ttf file sometimes. The speed is not great but acceptable. PIL's ImageFont looks like is not good at text aligning, often prints bottom-left corner of fi...

How to find duplicate elements in array using for loop in python like c/c++?

i have a list with duplicate elements: In python: list_a=[1,2,3,5,6,7,5,2] tmp=[] for i in list_a: if tmp.__contains__(i): print i else: tmp.append(i) i have used the above code to found the duplicate elements in the list_a. i dont want to remove the elements form list. But i want to use for loop her...

TinyMCE Spellchecker in Pylons

I've been trying to get the TinyMCE spellchecker working with my Pylons app. My first problem is actually capturing the post data in the first place. Firebug tells me that the following is being sent: {"id":"c0","method":"checkWords","params":["en",["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eius...

python write CD/DVD iso file

I'm making a cross-platform (Windows and OS X) with wxPython that will be compiled to exe later. Is it possible for me to create ISO files for CDs or DVDs in Python to burn a data disc with? Thanks, Chris ...

Fill list with objects and sort (Newbie)

I'm new to Python, so please forgive me when using wrong terms :) I'd like to have a list of several "objects", each of them having the same numeric attributes (A, B, C). This list should then be sorted by the value of attribute A. In Java I'd define a Class with my attributes as members, implement Sortable to compare A, put them all i...

Partial evaluation with pyparsing

I need to be able to take a formula that uses the OpenDocument formula syntax, parse it into syntax that Python can understand, but without evaluating the variables, and then be able to evaluate the formula many times with changing valuables for the variables. Formulas can be user input, so pyparsing allows me to both effectively handle ...

Python, Ruby, Haskell - Do they provide true multithreading?

We are planning to write a highly concurrent application in any of the Very-High Level programming languages. 1) Do Python, Ruby, or Haskell support true multithreading? 2) If a program contains threads, will a Virtual Machine automatically assign work to multiple cores (or to physical CPUs if there is more than 1 CPU on the mainboard...