Is there a python equivalent of the matlab command keyboard?

February 16, 2013 in Python, Recipes

Sort of. Wherever you want to stop the execution of your code to have access to the python prompt (and to the current local variables) just insert the lines: To
…read more

What is the recommended shebang line for Python?

November 30, 2012 in Coding, Python, Recipes, Shell

#!/usr/bin/env python

How do I search a set of files and batch process them?

August 11, 2012 in Content Type, Python, Shell, Tutorials

Let’s consider the following scenario. You have a folder containing, amongst the others, a specific subset of files to which you want to apply a command and collect the output
…read more

How do I set up a USB communication with an NXT brick running nxtOSEK?

July 21, 2012 in LEGO, NXT Brick, Python, Tutorials

Introduction In this tutorial we will implement a simple application to study how to establish a communication between a Mac (running Snow Leopard, but everything should apply to newer versions
…read more

How do I generate a list of random integers with repetitions in Python?

February 6, 2011 in Coding, Python, Recipes

Use list comprehension. Say that you want to generate N random numbers between min and max extremes included. Then the expression you are looking for is: Do not forget to
…read more

How do I split a path in Python?

January 28, 2011 in Python, Recipes, Shell

This way: If p = ‘c:/Users/zeus/Documents/Test/venus.jpg’, then: dir_name is ’c:/Users/zeus/Documents/Test’ base is ‘venus’ ext is is ‘.jpg’ Do not forget to import os

How do I search a list in Python?

December 4, 2010 in Coding, Python, Recipes

This code snippet will search the element that meets a certain condition in a list using generators. Use try/except and StopIteration to see if the list has been completely scanned.

Where are the Python standard exception listed?

December 4, 2010 in Coding, Python, Recipes

Here. If none of these is suitable just use raise Exception(“Your Exception Message”)