[Q] module name available in 'from ... import ...' statement
kwatch
kwatch at gmail.com
Mon Apr 30 19:19:54 EDT 2007
What is the condition of module name which is available in
'from .. import ..' statement ?
----------------------------------------
import os
print os.path # <module 'posixpath' from '/usr/local/
lib/python2.5/posixpath.pyc'>
from posixpath import sep # (no errors)
from os.path import sep # (no errors, wow!)
path = os.path
from path import sep # ImportError: No module named path
----------------------------------------
I found that library 'os.py' exists but 'os/path.py' doesn't exist
in '/usr/local/lib/python2.5'.
It means that file 'os/path.py' is not required to perform
'from os.path import sep' statement.
Could you teach me the condition of module name which is available
in 'from ... import ...' statement?
The goal what I want to do is to create a module by 'new' module
and specify that module name in 'from ...' statement.
----------------------------------------
# create a module
import new
foo = new.module('foo')
foo.pi = 3.14159
foo.x2 = lambda x: 2*x
# specify it in 'from' statement
from foo import pi, x2 # ImportError: No module named foo
----------------------------------------
--
regards,
kwatch
More information about the Python-list
mailing list