Skip to content

Commit ecd8157

Browse files
committed
Include a warning that scripts should not have the same name as standard
modules, or the module cannot be properly imported. (Based on a suggestion sent to python-docs.) Update the displayed dir() of the sys and __builtin__ module with Python 2.2.
1 parent 6016dbe commit ecd8157

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

‎Doc/tut/tut.tex‎

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,13 @@ \subsection{The Module Search Path \label{searchPath}}
22372237
containing the input script (or the current directory),
22382238
\envvar{PYTHONPATH} and the installation-dependent default. This allows
22392239
Python programs that know what they're doing to modify or replace the
2240-
module search path. See the section on Standard Modules later.
2240+
module search path. Note that because the directory containing the
2241+
script being run is on the search path, it is important that the
2242+
script not have the same name as a standard module, or Python will
2243+
attempt to load the script as a module when that module is imported.
2244+
This will generally be an error. See section~\ref{standardModules},
2245+
``Standard Modules.'' for more information.
2246+
22412247

22422248
\subsection{``Compiled'' Python files}
22432249

@@ -2363,9 +2369,15 @@ \section{The \function{dir()} Function \label{dir}}
23632369
>>> dir(fibo)
23642370
['__name__', 'fib', 'fib2']
23652371
>>> dir(sys)
2366-
['__name__', 'argv', 'builtin_module_names', 'copyright', 'exit',
2367-
'maxint', 'modules', 'path', 'ps1', 'ps2', 'setprofile', 'settrace',
2368-
'stderr', 'stdin', 'stdout', 'version']
2372+
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__',
2373+
'__stdin__', '__stdout__', '_getframe', 'argv', 'builtin_module_names',
2374+
'byteorder', 'copyright', 'displayhook', 'exc_info', 'exc_type',
2375+
'excepthook', 'exec_prefix', 'executable', 'exit', 'getdefaultencoding',
2376+
'getdlopenflags', 'getrecursionlimit', 'getrefcount', 'hexversion',
2377+
'maxint', 'maxunicode', 'modules', 'path', 'platform', 'prefix', 'ps1',
2378+
'ps2', 'setcheckinterval', 'setdlopenflags', 'setprofile',
2379+
'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'version',
2380+
'version_info', 'warnoptions']
23692381
\end{verbatim}
23702382

23712383
Without arguments, \function{dir()} lists the names you have defined
@@ -2388,15 +2400,27 @@ \section{The \function{dir()} Function \label{dir}}
23882400
\begin{verbatim}
23892401
>>> import __builtin__
23902402
>>> dir(__builtin__)
2391-
['AccessError', 'AttributeError', 'ConflictError', 'EOFError', 'IOError',
2392-
'ImportError', 'IndexError', 'KeyError', 'KeyboardInterrupt',
2393-
'MemoryError', 'NameError', 'None', 'OverflowError', 'RuntimeError',
2394-
'SyntaxError', 'SystemError', 'SystemExit', 'TypeError', 'ValueError',
2395-
'ZeroDivisionError', '__name__', 'abs', 'apply', 'chr', 'cmp', 'coerce',
2396-
'compile', 'dir', 'divmod', 'eval', 'execfile', 'filter', 'float',
2397-
'getattr', 'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'len', 'long',
2398-
'map', 'max', 'min', 'oct', 'open', 'ord', 'pow', 'range', 'raw_input',
2399-
'reduce', 'reload', 'repr', 'round', 'setattr', 'str', 'type', 'xrange']
2403+
['ArithmeticError', 'AssertionError', 'AttributeError',
2404+
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError',
2405+
'Exception', 'FloatingPointError', 'IOError', 'ImportError',
2406+
'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt',
2407+
'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented',
2408+
'NotImplementedError', 'OSError', 'OverflowError', 'OverflowWarning',
2409+
'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError',
2410+
'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError',
2411+
'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError',
2412+
'UnicodeError', 'UserWarning', 'ValueError', 'Warning',
2413+
'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__',
2414+
'__name__', 'abs', 'apply', 'buffer', 'callable', 'chr', 'classmethod',
2415+
'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr',
2416+
'dict', 'dir', 'divmod', 'eval', 'execfile', 'exit', 'file', 'filter',
2417+
'float', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id',
2418+
'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len',
2419+
'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object',
2420+
'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'raw_input',
2421+
'reduce', 'reload', 'repr', 'round', 'setattr', 'slice', 'staticmethod',
2422+
'str', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange',
2423+
'zip']
24002424
\end{verbatim}
24012425

24022426

0 commit comments

Comments
 (0)