Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
howto get function from module, known by string names?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Carsten Haese, post: 2897281"] Why would you need to do that? What are you planning to do when you have determined that the module doesn't exist? Surely you're not planning on swallowing the error silently, because that would make your program very hard to debug. The Pythonic response is to raise an exception, but then you might as well just propagate the exception that __import__ already raises: .... func = getattr(__import__(module_string1), func_string2) .... return func(*args) .... Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 2, in myfunc ImportError: No module named asdf Hope this helps, [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
howto get function from module, known by string names?
Top