Tech stuff and info dump

python: generate a list of uppercase or lowercase letters in the alphabet

May 30th, 2010

To create a list of lower-case letters in the alphabet in python:

map(chr, range(97, 123))

To create a list of upper-case letters in the alphabet in python:

map(chr, range(65, 91))

Examples:

>>> map(chr, range(65, 91))
[‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’]

>>> a=map(chr, range(97, 123))
>>> a
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]


Filed under: python,script
May 30th, 2010 16:59:09

Save python history across sessions (linux, Ubuntu)

May 30th, 2010

To get python to save history across sessions you put the file .pystartup in your home directory and you add the line

Open a terminal and go to your home directory.

(In Ubuntu 10.04 and other versions, navigate to Applications -> Accessories -> Terminal to bring up a terminal window. You should already be in your home directory.)

Add the line

export PYTHONSTARTUP=/home/name_of_home_directory/.pystartup

to the .bashrc file, replacing name_of_home_directory with the name of your home directory.

(In Ubuntu 10.04 and other versions, you can open this file by typing

gedit .bashrc

at the command line. This will bring up a simple editor. Just add the line given above to the bottom of the file, save the file and close the gedit window.

The name of your home directory is the string that appears before the @ sign in your command line prompt, assuming you haven’t done anything to change this. For example, your prompt might look like this:

name_of_home_directory@mycomputer:~$

You can also find it by going to Places->Home Folder. The window that pops up will have the text

name_of_home_directory – File Browser

at the top.)

That should do it!

Thanks to archduke.


Filed under: Customisation,python
Tags:
May 30th, 2010 15:00:13