Get named module's file location
Roy Smith
roy at panix.com
Fri Dec 23 15:00:17 EST 2011
In article
<4652751.858.1324669248908.JavaMail.geo-discussion-forums at prj1>,
Gnarlodious <gnarlodious at gmail.com> wrote:
> I am rolling my own, and learning Python at the same time.
Hmmm. The imp module is kind of deep magic for a first introduction to
the language. But, whatever.
> One more question. Say I want to assemble a list of tuples like this:
>
> modules = ['wsgiref', 'http']
> import imp
> [(imp.find_module(module)[1], os.path.getmtime(imp.find_module(module)[1]))
> for module in modules]
>
> Can I in some way assign imp.find_module(module)[1] to a variable and reuse
> it? Is this a job for lambda?
I think what you want to do is rewrite the list comprehension as a
regular loop.
my_list = []
for module in modules:
m = imp.find_module(module)[1]
my_list.append(m, os.path.getmtime(m))
More information about the Python-list
mailing list