How do you import a module with "." in its filename?

Keith Dart kdart at kdart.com
Wed Jul 31 07:01:49 EDT 2002


In article <Xns925C612DE2B4Aduncanrcpcouk at 127.0.0.1>, "Duncan Booth"
<duncan at nospamrcp.co.uk> penned these words:

> "Andrew P. Lentvorski" <bsder at mail.allcaps.org> wrote in
> news:mailman.1028080249.16165.python-list at python.org:
> 
>> So, how do I import a module with "." in its filename?
>> 
>> 
> fname = 'c:/test/a.test.py'
> f = file(fname, 'r')
> a_test = imp.load_module('a_test', f, fname, ('.py', 'r',
> imp.PY_SOURCE)) f.close()
> 
> See the module imp documentation for further details.
> 

But.... why bother? Why not just rename the original modules to
a_test.py, etc.? That's what I do.



-- 
--                           ^
                           \/ \/
                           (O O)
-- --------------------oOOo~(_)~oOOo----------------------------------------
Keith Dart
<mailto:kdart at kdart.com> 
<http://www.kdart.com/>  
----------------------------------------------------------------------------
Public key ID: B08B9D2C Public key: <http://www.kdart.com/~kdart/public.key>
============================================================================



More information about the Python-list mailing list