[docs] import.sys behavior in IDLE re: Modules tutorial section 6.2

Robin Zimmermann robin.zimm at gmail.com
Thu Jan 2 19:37:20 CET 2014


To whom it may concern:

I've been slowly working through the tutorial in the Python v3.3.3
documentation, and I ran into a weird thing with the first example in
Section 6.2 on http://docs.python.org/3/tutorial/modules.html -
"Standard Modules".

The first command-line example block says:

>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print('Yuck!')
Yuck!
C>

I had just opened a new IDLE window*, typed "import sys", hit enter,
then typed "sys.ps1" and hit enter. The Python shell returned the
following error:

----

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    sys.ps1
AttributeError: 'module' object has no attribute 'ps1'

----

In my confusion, I tried a couple more times; the transcript of
everyhing following the above AttributeError follows:

----

>>> ps1
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    ps1
NameError: name 'ps1' is not defined
>>> sys.ps1
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    sys.ps1
AttributeError: 'module' object has no attribute 'ps1'
>>> dir sys
SyntaxError: invalid syntax
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__loader__',
'__name__', '__package__', '__stderr__', '__stdin__', '__stdout__',
'_clear_type_cache', '_current_frames', '_debugmallocstats',
'_getframe', '_home', '_mercurial', '_xoptions', 'api_version',
'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names',
'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook',
'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook',
'exec_prefix', 'executable', 'exit', 'flags', 'float_info',
'float_repr_style', 'getcheckinterval', 'getdefaultencoding',
'getfilesystemencoding', 'getprofile', 'getrecursionlimit',
'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace',
'getwindowsversion', 'hash_info', 'hexversion', 'implementation',
'int_info', 'intern', 'last_traceback', 'last_type', 'last_value',
'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks',
'path_importer_cache', 'platform', 'prefix', 'setcheckinterval',
'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace',
'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info',
'warnoptions', 'winver']

----

Finally, without closing the IDLE window, I opened the Command Prompt**:

----

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Packbat>python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.ps1
'>>> '
>>>

----

My best guess is that IDLE is not a perfectly faithful implementation
of the command line; if this is the case, I feel it would be helpful
either to modify the tutorial to note this explicitly or to contact
the developers of IDLE regarding the discrepancy, if not both.

Thank you for your time and trouble!
- Robin Zimmermann

----

Footnotes:

* I had accidentally opened two IDLE windows, and closed one before
continuing, if that would be relevant; that said, when I closed the
program, reopened it, and typed the same commands, the error message
was the same.

** I am running the 32-bit version of Windows 7 Professional, Service
Pack 1, on an HP ProBook 4525s; I can give you more hardware
information if it would be relevant.


More information about the docs mailing list