is there a nmore pythonic way ?

shagshag13 shagshag13 at yahoo.fr
Tue Mar 11 05:40:18 EST 2003


hello,

i need to use module.function passed from command line, by now i use :

if __name__ == '__main__':
 args = sys.argv[1:]
 if len(args) == 0:
  ## print help information and exit:
  usage()
  sys.exit(2)

 im = '.'.join(sys.argv[1].split('.')[:-1])
 func = sys.argv[1].split('.')[-1:][0]

 exec("from %s import %s" % (im, func))

-> and then func()

is there a more correct way to do it ?

thanks,

s13.







More information about the Python-list mailing list