开发者

Learn python the hard way exercise 17 help, mistake in the book?

I'm liking this book开发者_JAVA百科 so far, but I run into an issue with exercise 17. It won't run:

neil@neil-K52F:~/python$ python ex17.py ex17from.txt ex17to.txt
  File "ex17.py", line 8
    indata input.read()
               ^
SyntaxError: invalid syntax

The book makes me create a variable named input. Is this a legal variable name?


The code you posted simply puts one identifier next to another, without anything (but a space) in between. That's as meaningless and invalid in Python as it is in English. The code in the book has an assignment in there (i.e. indata = ...).


Normally you set a value for your input/raw_input(python 2.x)

x = input("Text Here")

You may also call a data type function on input method

x = float(input("Enter a Number")
x = int(input("Enter an Integer")

I use these all the time in Python 2.7 where raw_input() stores the value as a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜