[issue12482] input() not working correctly on Mac OS X

2011-07-03 Thread Dmitriy Gorbachev

New submission from Dmitriy Gorbachev :

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 
db = loadDbase()
  File "/Users/DMITRY/PythonScripts/make_db_file_test.py", line 22, in loadDbase
key = input()
  File "", line 1, in 
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

--
assignee: ronaldoussoren
components: Macintosh
files: BugReport.zip
messages: 139697
nosy: dgorbachev, ronaldoussoren
priority: normal
severity: normal
status: open
title: input() not working correctly on Mac OS X
versions: Python 2.7
Added file: http://bugs.python.org/file22554/BugReport.zip

___
Python tracker 
<http://bugs.python.org/issue12482>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12482] input() not working correctly on Mac OS X

2011-07-05 Thread Dmitriy Gorbachev

Dmitriy Gorbachev  added the comment:

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 
To: dgorbac...@yahoo.com
Sent: Sun, July 3, 2011 4:18:35 PM
Subject: [issue12482] input() not working correctly on Mac OS X

Ned Deily  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 
<http://bugs.python.org/issue12482>
___

--

___
Python tracker 
<http://bugs.python.org/issue12482>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12482] input() not working correctly on Mac OS X

2011-07-05 Thread Dmitriy Gorbachev

Dmitriy Gorbachev  added the comment:

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 
To: dgorbac...@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  added the comment:

You are certainly using Python 2 with code designed for Python 3...
Can you check?

--
nosy: +amaury.forgeotdarc

___
Python tracker 
<http://bugs.python.org/issue12482>
___

--

___
Python tracker 
<http://bugs.python.org/issue12482>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com