Can import a user-specified module?

Bjorn Pettersen BPettersen at NAREX.com
Tue Aug 13 21:28:37 EDT 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