use strings to call functions

Klaus Neuner klausneuner72 at
Mon Feb 8 11:57:33 CET 2010


I am writing a program that analyzes files of different formats. I
would like to use a function for each format. Obviously, functions can
be mapped to file formats. E.g. like this:

if file.endswith('xyz'):
elif file.endswith('abc'):


Yet, I would prefer to do something of the following kind:

func = file[-3:]
apply_func(func, file)

Can something of this kind be done in Python?


More information about the Python-list mailing list