python

Programmatically focusing a hippo.CanvasEntry?

Consider this Python program which uses PyGtk and Hippo Canvas to display a clickable text label. Clicking the text label replaces it with a Hippo CanvasEntry widget which contains the text of the label. import pygtk pygtk.require('2.0') import gtk, hippo def textClicked(text, event, row): input = hippo.CanvasEntry() input.set...

Python Dependency Injection Framework

Is there a framework equivalent to Guice (http://code.google.com/p/google-guice) for Python? ...

Get timer ticks in Python

I'm just trying to time a piece of code. The pseudocode looks like: start = get_ticks() do_long_code() print "It took " + (get_ticks() - start) + " seconds." How does this look in Python? More specifically, how do I get the number of ticks since midnight (or however Python organizes that timing)? ...

Get all items from thread Queue

Hello, I have one thread that writes results into a Queue. In another thread (GUI), I periodically (in the IDLE event) check if there are results in the queue, like this: def queue_get_all(q): items = [] while 1: try: items.append(q.get_nowait()) except Empty, e: break return items ...

How to skip the docstring using regex

I'm trying to insert some import lines into a python source file, but i would ideally like to place them right after the initial docstring. Let's say I load the file into the lines variable like this: lines = open('filename.py').readlines() How to find the line number, where the docstring ends? ...

What is the best SNMP implementation for Python?

I'm doing some GUI prototyping with Python for an SNMP application. Looking around there seem to be a number of python libraries I could use. As I'm prototyping I value a nice clean easy API over speed and preferably a commonly packaged library. Obviously the package should be open source. So far I've been looking PySNMP, Twisted-Snmp, p...

Customized command line parsing in Python

I'm writing a shell for a project of mine, which by design parses commands that looks like this: COMMAND_NAME ARG1="Long Value" ARG2=123 [email protected] My problem is that Python's command line parsing libraries (getopt and optparse) forces me to use '-' or '--' in front of the arguments. This behavior doesn't match my requirements. An...

.order_by() Isnt working how it should/how i expect it to

In my django project i am using Product.objects.all().order_by('order') in a view, but it dosnt seem to be working properly. This is its output: Product Name Sort Evolution 2 Polarity 1 Jumbulaya 3 ...

Emacs and Python

I recently started learning Emacs. I went through the tutorial, read some introductory articles, so far so good. Now I want to use it for Python development. From what I understand, there are two separate Python modes for Emacs: python-mode.el, which is part of the Python project; and python.el, which is part of Emacs 22. I read all in...

Most pythonic way of counting matching elements in something iterable

I have an iterable of entries on which I would like to gather some simple statistics, say the count of all numbers divisible by two and the count of all numbers divisible by three. My first alternative, While only iterating through the list once and avoiding the list expansion (and keeping the split loop refactoring in mind), looks rath...

Date change notification in a Tkinter app (win32)

Does anyone know if it is possible (and if yes, how) to bind an event (Python + Tkinter on MS Windows) to a system date change? I know I can have .after events checking once in a while; I'm asking if I can somehow have an event fired whenever the system date/time changes, either automatically (e.g. for daylight saving time) or manually....

Open-source fractal maps

I'm interested in creating a game that uses fractal maps for more realistic geography. However, the only fractal map programs I have found are Windows-only, for example Fractal Mapper. Needless to say, they are also not open-sourced. Are there any open-sourced fractal map creators available, preferably in Python or C/C++? Ideally I woul...

Template Lib (Engine) in Python running with Jython

Im searching a Template Lib or Template Engine for generating HTML (XML) that runs under Jython (Jython 2.5 Alpha is ok). ...

Accurate timestamping in Python

I've been building an error logging app recently and was after a way of accurately timestamping the incoming data. When I say accurately I mean each timestamp should be accurate relative to each other (no need to sync to an atomic clock or anything like that). I've been using datetime.now() as a first stab, but this isn't perfect: >>> ...

Python 2.5 dictionary 2 key sort

I have a dictionary of 200,000 items (the keys are strings and the values are integers). What is the best/most pythonic way to print the items sorted by descending value then ascending key (i.e. a 2 key sort)? a={ 'keyC':1, 'keyB':2, 'keyA':1 } b = a.items() b.sort( key=lambda a:a[0]) b.sort( key=lambda a:a[1], reverse=True ) print b ...

Good Ruby or Python OpenSource projects that need help?

Anyone know any good Ruby or Python OpenSource projects that are in need of some help at the junior level? I seen this link: http://stackoverflow.com/questions/38881/how-to-find-opensource-projects-looking-for-help but I am looking for some opinion. ...

What is the best way to sample/profile a PyObjC application?

Sampling with Activity Monitor/Instruments/Shark will show stack traces full of C functions for the Python interpreter. I would be helpful to see the corresponding Python symbol names. Is there some DTrace magic that can do that? Python's cProfile module can be useful for profiling individual subtrees of Python calls, but not so much for...

Hiding a password in a (python) script

I have got a python script which is creating an ODBC connection. The ODBC connection is generated with a connection string. In this connection string I have to include the username and password for this connection. Is there an easy way to obscure this password in the file (just that nobody can read the password when I'm editing the fi...

Python module dependency problem

Ok I have two modules, each containing a class, the problem is there classes refrence each other. Lets say for example I had a room module and a person module containing CRoom and CPerson. The CRoom class contains infomation about the room, and a CPerson list of every one in the room. The CPerson class however sometimes needs to use t...

Best way to store and use a large text-file in python

I'm creating a networked server for a boggle-clone I wrote in python, which accepts users, solves the boards, and scores the player input. The dictionary file I'm using is 1.8MB (the ENABLE2K dictionary), and I need it to be available to several game solver classes. Right now, I have it so that each class iterates through the file line...