[Tutor] Importing sub modules
Steven D'Aprano
steve at pearwood.info
Fri Apr 1 00:16:21 CEST 2011
Prasad, Ramit wrote:
> The joins are really just random calls. I was just curious if importing os.path could avoid any reading/overhead that might occur by importing os.
No.
Python has no way of knowing what os.path is until it has imported os
and can do an attribute lookup on os.path. This is determined at runtime
by the os module, and depends on your operating system:
>>> import os.path
>>> os
<module 'os' from '/usr/lib/python2.4/os.pyc'>
>>> os.path
<module 'posixpath' from '/usr/lib/python2.4/posixpath.pyc'>
DO NOT try importing posixpath (or equivalent for other OSes) directly,
always use os.path.
--
Steven
More information about the Tutor
mailing list