Q:

Is is possible to join a variable and a number to make a new variable?

I am using Python 2.5. In the code below want to print either err1, err2 or err3  depending on the value of x. Is it possible to create the variables err1, err2 or err3 by joining "err" plus the value of x?
err1 = 'error foo1'
err2 = 'error foo2'
err3 = 'error foo3'

x = 1

print err + x

A:

You'd be better off re-writting it to use a dictionary if you want variable variable names.
err = {
    '1': 'This is Err1',
    '2': 'This is Err2',
    '3': 'This is Err3',
}

print err[str(x)]

