The Artima Developer Community
Sponsored Link

Python Answers Forum
Importing module which contains Dot

2 replies on 1 page. Most recent reply: Jan 9, 2005 4:13 PM by Baron Teh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Baron Teh

Posts: 4
Nickname: baron
Registered: Jan, 2005

Importing module which contains Dot Posted: Jan 7, 2005 12:04 AM
Reply to this message Reply
Advertisement
I'm trying to import a module containing dot in the filename, the pyton will report a syntax error.

eg: " import abc.1.2 " for the abc.1.2.py

How can i import it without renaming the file? Thanks.


Andy

Posts: 28
Nickname: adn
Registered: Jul, 2004

Re: Importing module which contains Dot Posted: Jan 7, 2005 2:45 AM
Reply to this message Reply
Interesting...

You can use the 'imp' module to import modules by filename:
>>> import imp
>>> open_file, file_name, description = imp.find_module('foo.bar')
>>> foo_bar = imp.load_module('foo.bar', open_file, file_name, description)
>>> foo_bar
<module 'foo.bar' from 'foo.bar.py'>

Voilla.

Baron Teh

Posts: 4
Nickname: baron
Registered: Jan, 2005

Re: Importing module which contains Dot Posted: Jan 9, 2005 4:13 PM
Reply to this message Reply
Thanks Andy, it is working.

Flat View: This topic has 2 replies on 1 page
Topic: Date Type? Previous Topic   Next Topic Topic: Adding windows directories to unix path?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use