Get named module's file location

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Dec 23 17:39:57 EST 2011


On Fri, 23 Dec 2011 15:00:17 -0500, Roy Smith wrote:

>> 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))

+1


List comprehensions are so cool that sometimes people forget that not 
every loop has to be a list comp. There is no shortage of newlines in the 
world, and not everything needs to be on a single line.


-- 
Steven



More information about the Python-list mailing list