Python2 和 Python3

Python2 And Python3

这是 Python 2:

import re

print sum([int(i) for i in re.findall('[0-9]+',open(raw_input('What is the file you want to analyze?\n'),'r').read())])

但是为什么 Python 3 会出现语法错误?

Python3

import re

print sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())])

这是因为在 Python3 中,您应该在打印函数的参数周围使用方括号。

打印()

所以您的代码将在您编写后立即运行

print(sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())]) )