Get named module's file location

Chris Angelico rosuav at gmail.com
Fri Dec 23 14:52:22 EST 2011


On Sat, Dec 24, 2011 at 6:40 AM, Gnarlodious <gnarlodious at gmail.com> wrote:
> [(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?

Well, you can use an additional comprehension to provide a temporary
variable, if you really want to do it all as a single expression.

[(m, os.path.getmtime(m)) for m in (imp.find_module(module)[1] for
module in modules)]

ChrisA



More information about the Python-list mailing list