This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年07月03日 19:23 by dgorbachev, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| BugReport.zip | dgorbachev, 2011年07月03日 19:23 | Contains files from"Programming Python", Mark Lutz,Chapter 1 | ||
| Messages (5) | |||
|---|---|---|---|
| msg139697 - (view) | Author: Dmitriy Gorbachev (dgorbachev) | Date: 2011年07月03日 19:23 | |
I am learning Python by running exercises from "Programming Python", Mark Lutz on both Windows and Mac. While exercises run flawlessly on Windows, sometimes they do not run on Mac. In particular, in Chapter 1, Step 2: Storing Records Persistently there is a script called make_db_file.py. The following function loadDbase (called by dump_db_file_test.py-see attached) is not working at all on Mac, but working fine of Windows. The code breaks on the line: key = input(). The Traceback message is as follows: Traceback (most recent call last): File "dump_db_file_test.py", line 2, in <module> db = loadDbase() File "/Users/DMITRY/PythonScripts/make_db_file_test.py", line 22, in loadDbase key = input() File "<string>", line 1, in <module> NameError: name 'bob' is not defined Where 'bob' is the first line of the text file "people-file" that make_db_file_test.py refers. All related files attached in BugReport.zip Best regards Dmitry |
|||
| msg139701 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2011年07月03日 20:08 | |
You are certainly using Python 2 with code designed for Python 3... Can you check? |
|||
| msg139703 - (view) | Author: Ned Deily (ned.deily) * (Python committer) | Date: 2011年07月03日 20:18 | |
The test case you've provide is working as expected but the code doesn't make a lot of sense as provided. The function loadDbase sets sys.stdin to a disk file but never sets it back again. If you run this in an interactive interpreter on any Unix-like system and call that function, it will leave sys.stdin still connected to the disk file which will give unexpected results. I don't have a copy of the book so I don't know how the author recommends to run things but it won't work as it stands (also, the function loadDbase is incomplete compared with the book's example files). You can remove the immediate problem by adding the following line just before the "return db" at the end of loadDbase: sys.stdin = sys.__stdin__ That will restore the original value of sys.stdin. You may want to ask questions like this on either the tutor mailing list or comp.lang.python. http://www.python.org/community/lists/ http://docs.python.org/library/sys.html#sys.__stdin__ |
|||
| msg139909 - (view) | Author: Dmitriy Gorbachev (dgorbachev) | Date: 2011年07月06日 00:04 | |
Hello Ned Thank you very much for your time and for your advice where to post questions like mine. I apologise for my mistake: instead of input() there was raw_input() function in the book, which works as expected on all platforms. Best regards Dmitry ----- Original Message ---- From: Ned Deily <report@bugs.python.org> To: dgorbachev@yahoo.com Sent: Sun, July 3, 2011 4:18:35 PM Subject: [issue12482] input() not working correctly on Mac OS X Ned Deily <nad@acm.org> added the comment: The test case you've provide is working as expected but the code doesn't make a lot of sense as provided. The function loadDbase sets sys.stdin to a disk file but never sets it back again. If you run this in an interactive interpreter on any Unix-like system and call that function, it will leave sys.stdin still connected to the disk file which will give unexpected results. I don't have a copy of the book so I don't know how the author recommends to run things but it won't work as it stands (also, the function loadDbase is incomplete compared with the book's example files). You can remove the immediate problem by adding the following line just before the "return db" at the end of loadDbase: sys.stdin = sys.__stdin__ That will restore the original value of sys.stdin. You may want to ask questions like this on either the tutor mailing list or comp.lang.python. http://www.python.org/community/lists/ http://docs.python.org/library/sys.html#sys.__stdin__ ---------- assignee: ronaldoussoren -> components: -Macintosh nosy: +ned.deily resolution: -> invalid stage: -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12482> _______________________________________ |
|||
| msg139911 - (view) | Author: Dmitriy Gorbachev (dgorbachev) | Date: 2011年07月06日 00:19 | |
Hi Amaury, Thank you very much for your email. Actually what happedded is that I mistakenly used input() function in place of raw_input() as it is in the book. raw_input correctly inputs bob and 'bob', while input() inputs correctly 'bob' only and complains about bob. I will definitely check the usage of input() with bob in Python 3 when I install it. Best regards Dmitry ----- Original Message ---- From: Amaury Forgeot d'Arc <report@bugs.python.org> To: dgorbachev@yahoo.com Sent: Sun, July 3, 2011 4:08:02 PM Subject: [issue12482] input() not working correctly on Mac OS X Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: You are certainly using Python 2 with code designed for Python 3... Can you check? ---------- nosy: +amaury.forgeotdarc _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12482> _______________________________________ |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:19 | admin | set | github: 56691 |
| 2011年07月06日 00:19:46 | dgorbachev | set | messages: + msg139911 |
| 2011年07月06日 00:04:01 | dgorbachev | set | messages: + msg139909 |
| 2011年07月03日 20:18:34 | ned.deily | set | status: open -> closed assignee: ronaldoussoren -> components: - macOS nosy: + ned.deily messages: + msg139703 resolution: not a bug stage: resolved |
| 2011年07月03日 20:08:02 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg139701 |
| 2011年07月03日 19:23:49 | dgorbachev | create | |