Using a debugger and curses at the same time?

I’m calling python -m pdb myapp.py, when an exception fires, and I’d normally be thrown back to the pdb interpreter to investigate the problem. However this exception is being thrown after I’ve called through curses.wrapper() and entered curses mode, rendering the pdb interpreter useless. How can I work around this? Answer James` answer is a … Read more

One hour difference in Python

I have a datetime.datetime property var. I would like to know if it is less than one hour of the current time. Something like var.hour<datetime.datetime.today().hour – 1 Problem with the above syntax is that datetime.datetime.today().hour returns a number such as “10” and it is not really a date comparation but more of a numbers comparation. … Read more

Calling Python from Java through scripting engine (jython)?

I’m trying to call Jython from a Java 6 application using javax.script: import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class jythonEx { public static void main (String args[]) throws ScriptException { ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine pyEngine = mgr.getEngineByName(“python”); try { pyEngine.eval(“print \”Python – Hello, world!\””); } catch (Exception ex) { ex.printStackTrace(); } } … Read more

Setting the vim color theme for highlighted braces

How do you change the vim color scheme for highlighted braces? I’m looking to actually edit the .vim theme file to make the change permanent. Regards, Craig Answer The automatic highlight colour for matching brackets is called MatchParen. You can change the colour in your .vimrc by doing eg: highlight MatchParen cterm=bold ctermfg=cyan AttributionSource : … Read more

Directly call distutils’ or setuptools’ setup() function with command name/options, without parsing the command line?

I’d like to call Python’s distutils’ or setuptools’ setup() function in a slightly unconventional way, but I’m not sure whether distutils is meant for this kind of usage. As an example, let’s say I currently have a ‘setup.py’ file, which looks like this (lifted verbatim from the distutils docs–the setuptools usage is almost identical): from … Read more

Including a Django app’s url.py is resulting in a 404

I have the following code in the urls.py in mysite project. /mysite/urls.py from django.conf.urls.defaults import * urlpatterns = patterns(”, (r’^gallery/$’, include(‘mysite.gallery.urls’)), ) This results in a 404 page when I try to access a url set in gallery/urls.py. /mysite/gallery/urls.py from django.conf.urls.defaults import * urlpatterns = patterns(”, (r’^gallery/browse/$’, ‘mysite.gallery.views.browse’), (r’^gallery/photo/$’, ‘mysite.gallery.views.photo’), ) 404 error Using the … Read more

How to parse a directory tree in python?

I have a directory called “notes” within the notes I have categories which are named “science”, “maths” … within those folder are sub-categories, such as “Quantum Mechanics”, “Linear Algebra”. ./notes –> ./notes/maths ——> ./notes/maths/linear_algebra –> ./notes/physics/ ——> ./notes/physics/quantum_mechanics My problem is that I don’t know how to put the categories and subcategories into TWO SEPARATE … Read more

Python GTK+ widget name

How do I get a widget’s “name”? When I define a GUI using Glade, I can “name” the widgets of the window but how do I recover that property when I have a widget object instance? I’ve tried get_property(), get_name() and $widget.name to no avail. Update: I am using GtkBuilder file format (i.e. XML format). … Read more