FAQ

On Mon, Jun 20, 2011 at 11:19 PM, Florencio Cano wrote:
import config_script obviously doesn't work and __import__(config_script)
works from the python interpreter but fails in the script (ImportError:
Import by filename is not supported.)
You can use this:

exec("import " + module_name)

Thanks for the hint. I will give that a try.
On Tue, Jun 21, 2011 at 2:48 AM, Terry Reedy wrote:


The main problem of your second method is that you repeat the check
function in each script. That will be a problem if you ever want to modify
it. I might put is into a separate file and import into each script.
repeating the check function in each script is what I think I want. The
check function is what would scan the system and make sure that compliance
is met. I'm slightly confused about how that would become an issue later and
what you mean about importing each of them ????

import config_script obviously doesn't work and
__import__(config_script) works from the python interpreter but fails in
the script (ImportError: Import by filename is not supported.)
Look at builtin function __import__(filename).
Terry Jan Reedy

I looked into __import__(filename) but that was not working for me, based
upon the error in my previous message. I will give Florencio Cano's solution
of using exec a try. If there are any other ideas out there I'm all ears :)

Thanks everybody for the replies and guidance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110621/72d00dda/attachment.html>

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 7 of 7 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedJun 20, '11 at 4:13a
activeJun 21, '11 at 12:34a
posts7
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase