[issue16607] Bad examples in documentation

2012-12-13 Thread John Hampton

John Hampton added the comment:

Ok, but perhaps in order to aviod confusion the documentation could be changed 
so that the examples are complete or have an additional new line as needed.

Well, they are complete.  And it's only an issue with the interpreter.  If you 
were to copy and paste the examples into a file, say example.py, and run that 
with python via:

python example.py

then they would work as they are supposed to.  If you backup in the tutorial to:

http://docs.python.org/3/tutorial/interpreter.html#interactive-mode

You will read an explanation of the interpreter prompts.

It may be that there is a way to make it clearer, but to update those examples 
would require similar adjustments all over the docs.  It would also only 
benefit the case where one were trying to run the code in the interpreter, and 
would make it more annoying to copy and paste into a file.  So, I don't think 
changing anything is worth it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16607
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16607] Bad examples in documentation

2012-12-12 Thread John Hampton

John Hampton added the comment:

The documentation is correct.  The problem that you seem to be having are due 
to copy and pasting in the interpreter.

The source of you first error is that after you copy

 def scope_test():
... def do_local():
... spam = local spam
... def do_nonlocal():
... nonlocal spam
... spam = nonlocal spam
... def do_global():
... global spam
... spam = global spam
... 

into the interpreter, you press enter and the blank line tells the interpreter 
that you're done defining the class.  However, if you look at the docs, the 
following statements:

spam = test spam
do_local()
print(After local assignment:, spam)
do_nonlocal()
print(After nonlocal assignment:, spam)
do_global()
print(After global assignment:, spam)

are supposed to be part of the class.  A similar issue exists for the issues 
you're experiencing with the loops.  Except it's the opposite.  In this case:

 for element in [1, 2, 3]:
... print(element)
... for element in (1, 2, 3):
  File stdin, line 3
for element in (1, 2, 3):
  ^
SyntaxError: invalid syntax

the interpreter is expecting a blank line after the print statement to indicate 
that the loop is done.  Since the second loop starts on the lien after print, 
it thinks there is an indentation error.

--
nosy: +pacopablo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16607
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com