Python

How to suppress opening a browser in a python script

Some Python scripts use the webbrowser module to launch a browser for a given URL. If you're on a headless server, it'll launch a text-based browser (eg. in Debian it's w3m) which might not be desired (many websites are less than usable in text-based browsers and the launch of such an URL in a text-based browser is more an annoyance than help). You can easily avoid this behaviour.

Python script to list libvirt domains with their descriptions

Unfortunately neither the virsh command, nor virt-manager give you the option to list your virtual machines with their descriptions. If you've a couple of dozen (or even hundred) VMs, the short VM name is pretty soon going to be not enough to find the given VM you're looking for.

Running multiprocessing Python code in Wine

If you try to use the multiprocessing module in Python 2.6 in a Wine environment, you'll hit a bug. You'll have to patch the Lib\multiprocessing\connection.py file, wrap the call to win32.SetNamedPipeHandleState in the Pipe function in an exception handler block and silently catch WindowsError exceptions where the return value is zero (these are not errors, but an exception is thrown nontheless).

Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, etc)

"This is a tale of two approaches to regular expression matching. One of them is in widespread use in the standard interpreters for many languages, including Perl. The other is used only in a few places, notably most implementations of awk and grep. The two approaches have wildly different performance characteristics ..."
A very interesting article on regular expression matching algorithms.

Using Python's IDLE with the preinstalled Python 2.5.x of Leopard

This short post describes how to keep Leopard's built-in Python distribution and install IDLE on top of it.
The three steps to follow are:
  1. Install only PythonApplications-2.5.pkg from the official Python for Mac DMG (it's in Contents / Packages / MacPython.mpkg)
  2. Create a symlink:
    cd /Library/Frameworks
    sudo ln -s /System/Library/Frameworks/Python.framework/ Python.framework
  3. Erase "/Applications/MacPython 2.5/Python Launcher.app" and "/Applications/MacPython 2.5/Build Applet.app"

How to debug issues with KDE System Settings config screens

Some (maybe all?) of the "System settings" configuration screens in KDE are implemented in Python scripts (found in /var/lib/python-support/python2.5/). It might happen that one of the configuration screens does not load, instead you get some error messages complaining that something failed. In my example the "Monitor and Display" configuration failed to load and as such, I could not change resolution.

Syndicate content