2 Replies - 441 Views - Last Post: 29 September 2012 - 09:01 AM Rate Topic: -----

#1 geographerkate  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 12

input in python 2.6 vs 3.1

Posted 29 September 2012 - 08:54 AM

I'm working my way through Python for the Absolute Beginner (by Michael Dawson) to build a better programming foundation for my ArcGIS scripts class because I've never programmed before and searching online forums just confuses me more. The book uses python 3.1, and a lot of the example programs involve user input. For example:
name = input("Hi. What's your name? ")

print(name)

print("Hi,", name)

input("\n\nPress the enter key to exit.")



But when I enter my name in my Python 2.6 program and press enter, the program closes. I think it's a difference between the two versions of the software (rather than my error) because when I downloaded the program from the book's website, not only was the code the same as mine, the same thing happened when I ran the program.

Is there an easy substitution I can make to make that kind of code work in 2.6, or would it be better to download 3.1 (even though we are using 2.6 for class, so I'd rather use that as much as possible)?

I apologize if this is a stupid or inappropriate question.

Is This A Good Question/Topic? 0
  • +

Replies To: input in python 2.6 vs 3.1

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6037
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: input in python 2.6 vs 3.1

Posted 29 September 2012 - 08:58 AM

From the docs on what's new in Python 3.x:

Quote

PEP 3111: raw_input() was renamed to input(). That is, the new input() function reads a line from sys.stdin and returns it with the trailing newline stripped. It raises EOFError if the input is terminated prematurely. To get the old behavior of input(), use eval(input()).

Was This Post Helpful? 1
  • +
  • -

#3 geographerkate  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 12

Re: input in python 2.6 vs 3.1

Posted 29 September 2012 - 09:01 AM

Fantastic! Problem solved by subbing raw_input() for input(). Thank you so much!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1