classification
Title: typo: opne in "doanddont"
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: cate, ezio.melotti, georg.brandl, jszakmeister
Priority: normal Keywords:

Created on 2009-06-06 09:58 by cate, last changed 2009-06-06 11:30 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
issue-6220-doanddont.patch jszakmeister, 2009-06-06 10:11 Patch for trunk.
Messages (6)
msg88992 - (view) Author: cate (cate) Date: 2009-06-06 09:58
http://docs.python.org/dev/howto/doanddont.html use twice in example the
"opne" function, which should be written as "open". From google it seems
that also 3.x is affected (but not really checked)
msg88993 - (view) Author: John Szakmeister (jszakmeister) * Date: 2009-06-06 10:11
Here's a patch for trunk.
msg88994 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-06-06 10:13
That "typo" is intentional, it's also written in the comment:
try:
    foo = opne("file") # misspelled "open"
except:
    sys.exit("could not open file!")

This example shows how a bare except will catch the NameError caused by
'opne' and return the wrong error message, whereas "except IOError" will
only catch IOErrors and show the NameError.
msg88995 - (view) Author: John Szakmeister (jszakmeister) * Date: 2009-06-06 10:16
That'll teach me to pay more attention before submitting a patch. 
Thanks Ezio!
msg88997 - (view) Author: John Szakmeister (jszakmeister) * Date: 2009-06-06 11:06
Actually, what's the second example trying to show:
try:
   foo = opne("file") # will be changed to "open" as soon as we run it
except IOError:
   sys.exit("could not open file")

I'm not sure what that comment really means?
msg88999 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-06-06 11:30
If we use the bare "except:" the message "could not open file!" is shown
and we would waste time trying to figure out why it can't be opened.

Instead, if we use "except IOError:", the first time we run the program
the error "NameError: name 'opne' is not defined" is raised, telling us
what's wrong. Once we know it, we can change 'opne' to 'open' and solve
the problem.

Indeed it could be clearer.
History
Date User Action Args
2009-06-06 11:30:56ezio.melottisetkeywords: - patch

messages: + msg88999
2009-06-06 11:06:16jszakmeistersetmessages: + msg88997
2009-06-06 10:16:53jszakmeistersetmessages: + msg88995
2009-06-06 10:15:52ezio.melottisetstatus: open -> closed
2009-06-06 10:13:25ezio.melottisetresolution: not a bug

messages: + msg88994
nosy: + ezio.melotti
2009-06-06 10:11:25jszakmeistersetfiles: + issue-6220-doanddont.patch

nosy: + jszakmeister
messages: + msg88993

keywords: + patch
2009-06-06 09:58:26catecreate