I’ve got many, many strings, all formatted like this: “lot1”, “lot2”, “lot3″… What I’d like to do is use a function argument to determine which variable to use. Here’s a pseudoexample:
def printlot(someInt):
print lot%i % (someInt)
Basically, I’d like to use multiple strings to form the name of another string to act with. This seems simple enough, but I haven’t learned how to do it in my two years of Pythoning.
You can access all visible variables as a dictionary using the
varsbuiltin function:Different scopes can be accessed with
globalsorlocals.Note, however, that this is generally considered “unpythonic” behaviour. Instead of creating many similarly-named variables, a more Pythonic approach would be to make a list or dictionary.