python

How do you remove duplicates from a list in Python whilst preserving order?

Is there a built-in that removes duplicates from list in Python, whilst preserving order? I know that I can use a set to remove duplicates, but that destroys the original order. I also know that I can roll my own like this: def uniq(input): output = [] for x in input: if x not in output: output.append(x) return output ...

Get the title of the current active Window/Document in Mac OS X

Refering to a previously asked question, I would like to know how to get the title of the current active document. I tried the script mention in the answers to the question above. This works, but only gives me the name of the application. For example, I am writing this question: When I fire up the script it gives me the name of the appl...

How do you test if a point is inside a circle?

In python, if you create a circle with: newcircle = circle(center_x, center_y, radius) How do you test if a given set of x/y coordinates are inside the circle? ...

Is there a way in python to apply a list of regex patterns that are stored in a list to a single string?

hi, i have a list of regex patterns (stored in a list type) that I would like to apply to a string. Does anyone know a good way to: Apply every regex pattern in the list to the string and Call a different function that is associated with that pattern in the list if it matches. I would like to do this in python if possible thanks ...

Can a lambda function call itself recursively in Python?

A regular function can contain a call to itself in its definition, no problem. I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no name to refer back to. Is there a way to do it? How? ...

Extracting info from large structured text files

I need to read some large files (from 50k to 100k lines), structured in groups separated by empty lines. Each group start at the same pattern "No.999999999 dd/mm/yyyy ZZZ". Here´s some sample data. No.813829461 16/09/1987 270 Tit.SUZANO PAPEL E CELULOSE S.A. (BR/BA) C.N.P.J./C.I.C./N INPI : 16404287000155 Procurador: MARCEL...

Python with Wiimote using pywiiuse module

After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class. I want to make a game with pygame incorporating a wiimote. I found pywiiuse which is a very basic wrapper for the wiiuse library using c types. I can NOT g...

How many threads is too many?

I am writing a server, and I branch each action off into a thread when the request is incoming. I do this because almost every request is a database query. I am using a threadpool library to cut down on construction/destruction of threads. My question is though - what is a good cutoff point for I/O threads like these? I know it would ju...

What does the LDAP response tuple (97, []) mean?

I am using python-ldap to try to authenticate against an existing Active Directory, and when I use the following code: import ldap l = ldap.initialize('LDAP://example.com') m = l.simple_bind_s([email protected],password) I get the following back: print m (97, []) What does the 97 and empty list signify coming from a Microsoft Ac...

How would you do the equivalent of preprocessor directives in Python?

Is there a way to do the following preprocessor directives in Python? #if DEBUG < do some code > #else < do some other code > #endif ...

Replace Nested For Loops... or not

I have a script that loops through a series of four (or less) characters strings. For example: aaaa aaab aaac aaad If have been able to implement it with nested for loops like so: chars = string.digits + string.uppercase + string.lowercase for a in chars: print '%s' % a for b in chars: print '%s%s' % (a, b) ...

Beginner-level Python threading problems

As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GUI responsive. I've go...

Java Scientific Packages similar to SciPy?

I've been looking around the internet for a Java scientific package that is "similar" to Scipy. The only thing I have really found is JScience but it seems not to offer plotting and such. Does anyone know of a good scientific package for Java? ...

Parsing a file with column data in Python

I have a file that contains the symbol table details.Its in the form of rows and columns. I need to extract first and last column. How can I do that? ...

How do I convert a string to a double in Python?

I would like to know how to convert a string containing digits to a double. ...

ORM (object relational manager) solution with multiple programming language support

Is there a good ORM (object relational manager) solution that can use the same database from C++, C#, Python? It could also be multiple solutions, e.g. one per language, as long as they can can access the same database and use the same schema. Multi platform support is also needed. Clarification: The idea is to have one database and ...

How come my class is behaving like a static class?

Hi to all, i have a module (a single .py file, actually), with a class called HashedDir. when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different. Eg: h1 = HashedDir('/path/to/dir') print h1.getList()['files'] # /path/to/di...

Help -- how to stop a Python script without error messages on the shell ???

I want to stop a Python script on seeing an error message. I dont want any error message on shell like exit(). How to do it ??? ...

Python reverse / inverse a mapping

Given a dictionary likeso: map = { 'a': 1, 'b':2 } How can one invert this map to get: inv_map = { 1: 'a', 2: 'b' } ...

calling methods on an instance with getattr [ python ]

I was trying to write some code that would check if an item has some attributes , and to call them . I tried to do that with getattr , but the modifications wouldn't be permanent . I made a "dummy" class to check upon this . Here is the code I used for the class : class X: def __init__(self):...