running multiple scripts -- which way is more elegant?

Stephen Bunn scbunn at sbunn.org
Mon Jun 20 20:34:31 EDT 2011


On Mon, Jun 20, 2011 at 11:19 PM, Florencio Cano
<florencio.cano at gmail.com>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 <tjreedy at udel.edu> 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-0001.html>


More information about the Python-list mailing list