python regular expression replacing part of a matched string

i got an string that might look like this “myFunc(‘element’,’node’,’elementVersion’,’ext’,12,0,0)” i’m currently checking for validity using, which works fine myFunc\((.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\) now i’d like to replace whatever string is at the 3rd parameter.unfortunately i cant just use a stringreplace on whatever sub-string on the 3rd position since the same ‘sub-string’ could be anywhere else in that … Read more

MemoryStream analog in Python

Does some analog of C# MemoryStream exist in Python (that could allow me to write binary data from some source direct into memory)? And how would I go about using it? StringIO is one possibility: http://docs.python.org/library/stringio.html This module implements a file-like class, StringIO, that reads and writes a string buffer (also known as memory files). … Read more

psycopg2.InternalError: how can I get more useful information?

I’m running this command in a Python script: try: print sql_string cursor.execute(sql_string) except: print sys.exc_info() and getting: (<class ‘psycopg2.InternalError’>, InternalError(‘current transaction is aborted, commands ignored until end of transaction block\n’,), <traceback object at 0x1010054d0>) However if I try the sql_string from the psql command line, it works just fine. I know the script is connecting … 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

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

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

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): … 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 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 Attribution Source : … Read more