Can import a user-specified module?

Bjorn Pettersen BPettersen at NAREX.com
Wed Aug 14 03:28:37 CEST 2002


> From: Sung Kim [mailto:skim at adobe.com] 
> 
> In Python, is something like the following pseudo-code 
> possible? Thank 
> you!
> 
> moduleName = GetNameFromUser ()
> 
> import moduleName
> 
> if moduleName.SomeFunction exists
> 	x = moduleName.SomeFunction ()

m = GetNameFromUser()
moduleName = __import__(m)

if hasattr(moduleName, 'SomeFunction'):
    x = moduleName.SomeFunction()

-- bjorn




More information about the Python-list mailing list