Newbie on importing

Lee Harr missive at frontiernet.net
Fri Jun 20 22:21:29 CEST 2003


> That example is still less than clear...
> 
>>import sys
>>
>>Imports the module named 'sys'.
> 
> Which get me access to what in 'sys'?
> 
>>from sys import *
>>
>>Imports all names from sys (including names referring to functions).
> 
> Likewise, what additional thing are available when doing this? 
> Is 'import sys' a subset of 'from sys import *'?
> 
>


$python
Python 2.2.3 (#1, Jun  9 2003, 18:01:50)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__']
>>> import sys
>>> dir()
['__builtins__', '__doc__', '__name__', 'sys']
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__',\
 '__stdin__', '__stdout__', '_getframe', 'argv', 'builtin_module_names',\
 'byteorder', 'copyright', 'displayhook', 'exc_info', 'exc_type',\
 'excepthook', 'exec_prefix', 'executable', 'exit', 'getdefaultencoding',\
 'getdlopenflags', 'getrecursionlimit', 'getrefcount', 'hexversion',\
 'maxint', 'maxunicode', 'modules', 'path', 'platform', 'prefix',\
 'ps1', 'ps2', 'setcheckinterval', 'setdlopenflags', 'setprofile',\
 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version',\
 'version_info', 'warnoptions']
>>>

$python
Python 2.2.3 (#1, Jun  9 2003, 18:01:50)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__']
>>> from sys import *
>>> dir()
['__builtins__', '__doc__', '__name__', 'argv', 'builtin_module_names',\
 'byteorder', 'copyright', 'displayhook', 'exc_info', 'exc_type',\
 'excepthook', 'exec_prefix', 'executable', 'exit', 'getdefaultencoding',\
 'getdlopenflags', 'getrecursionlimit', 'getrefcount', 'hexversion',\
 'maxint', 'maxunicode', 'modules', 'path', 'platform', 'prefix', 'ps1',\
 'ps2', 'setcheckinterval', 'setdlopenflags', 'setprofile',\
 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout',\
 'version', 'version_info', 'warnoptions']
>>>

 




More information about the Python-list mailing list