Skip to content
Advertisement

Virtualenv on Ubuntu with no site-packages

I’ve been using virtualenv lately while developing in python. I like the idea of a segregated development environment using the –no-site-packages option, but doing this while developing a PyGTK app can be a bit tricky. The PyGTK modules are installed on Ubuntu by default, and I would like to make a virtualenv (with –no-site-packages) aware of specific modules that are

When is not a good time to use python generators?

This is rather the inverse of What can you use Python generator functions for?: python generators, generator expressions, and the itertools module are some of my favorite features of python these days. They’re especially useful when setting up chains of operations to perform on a big pile of data–I often use them when processing DSV files. So when is it

Starting python debugger automatically on error

This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let’s say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am

How to get method parameter names?

Given that a function a_method has been defined like Starting from a_method itself, how can I get the argument names – for example, as a tuple of strings, like (“arg1”, “arg2”)? Answer Take a look at the inspect module – this will do the inspection of the various code object properties for you. The other results are the name of

Binary search (bisection) in Python

Is there a library function that performs binary search on a list/tuple and return the position of the item if found and ‘False’ (-1, None, etc.) if not? I found the functions bisect_left/right in the bisect module, but they still return a position even if the item is not in the list. That’s perfectly fine for their intended usage, but

List of IP addresses/hostnames from local network in Python

How can I get a list of the IP addresses or host names from a local network easily in Python? It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow. Edit: By local I mean all active addresses within a local network, such as 192.168.xxx.xxx. So, if the IP

What is the difference between re.search and re.match?

What is the difference between the search() and match() functions in the Python re module? I’ve read the Python 2 documentation (Python 3 documentation), but I never seem to remember it. I keep having to look it up and re-learn it. I’m hoping that someone will answer it clearly with examples so that (perhaps) it will stick in my head.

Python: can I have a list with named indices?

In PHP I can name my array indices so that I may have something like: Is this possible in Python? Answer This sounds like the PHP array using named indices is very similar to a python dict: See http://docs.python.org/tutorial/datastructures.html#dictionaries for more on this.

Advertisement