天天看点

Python 报错问题:Encountered "counter" at line 8, column 7. Was expecting one of:

源码:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

counter = 100 # 赋值整型变量

miles = 1000.0 # 浮点型

name = "John" # 字符串

print counter

print miles

print name

eclipse报错如下:

Encountered "counter" at line 8, column 7. Was expecting one of:     

 <NEWLINE> ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" 

 ...     "*" ...     "/" ...     "//" ...     "<<" ...     ">>" ...     "%" ...     "^" ...     "|" 

 ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     

 "!=" ...     "+=" ...     "-=" ...     "*=" ...     "@=" ...     "/=" ...     "//=" ...     

 "%=" ...     "&=" ...     "|=" ...     "^=" ...     "<<=" ...     ">>=" ...     "**=" 

 ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     "@" ...     

 ";" ...     "," ...     

Encountered "counter" at line 8, column 7. Was expecting one of:     

 <NEWLINE> ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" 

 ...     "*" ...     "/" ...     "//" ...     "<<" ...     ">>" ...     "%" ...     "^" ...     "|" 

 ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     

 "!=" ...     "+=" ...     "-=" ...     "*=" ...     "@=" ...     "/=" ...     "//=" ...     

 "%=" ...     "&=" ...     "|=" ...     "^=" ...     "<<=" ...     ">>=" ...     "**=" 

 ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     "@" ...     

 ";" ...     "," ...

原因:

python3.0版本后print需要用()

详细参考https://stackoverflow.com/questions/19878100/python-was-expecting-one-of-newline

修改如下:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

counter = 100 # 赋值整型变量

miles = 1000.0 # 浮点型

name = "John" # 字符串

print (counter)

print (miles)

print (name)