[英]python : cannot instantiate more than one or two variables (SyntaxError raised)
Since yesterday, I'm having a strange issue when testing new Python scripts. 从昨天开始,在测试新的Python脚本时我遇到了一个奇怪的问题。 When running the script, I get a 'SyntaxError: invalid syntax' on one of the first variable assignment. 运行脚本时,在第一个变量分配之一上出现“ SyntaxError:无效语法”。
For exemple, this simple code I made for loading screen options from a text file (that exists in the same directory) : 例如,我编写了以下简单代码,用于从文本文件(位于同一目录中)加载屏幕选项:
#!/usr/bin/env python2.7
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('config.txt')
fullscreen = bool(config.get('Screen', 'fullscreen')
width = int(config.get('Screen', 'width')
height = int(config.get('Screen', 'height')
...
When run in the terminal, returns : 在终端中运行时,返回:
File "./config.py", line 8
width = int(config.get('Screen', 'width')
^
SyntaxError: invalid syntax
More strangely, when I comment the fullscreen line out, I get the same error... but on the next line (height = ...). 更奇怪的是,当我注释掉全屏显示行时,我得到了相同的错误...但是在下一行(高度= ...)。 Meaning the last one was indeed syntax valid? 意思是最后一个确实在语法上有效吗? Also the problem only occurs on the new files, older ones work perfectly (well, at least there's no error :) ). 同样,问题仅出现在新文件上,旧文件可以正常工作(嗯,至少没有错误:))。 And, last but not least... when I'm using another text editor (like kate, I usually use vim), writing the exact same code raises no error either 最后但并非最不重要的一点……当我使用另一个文本编辑器(如kate时,我通常使用vim)时,编写完全相同的代码也不会引起错误
I tried to reinstall vim as I thought that was where the problem came from, but it's still the same. 我试图重新安装vim,因为我以为这是问题的根源,但还是一样。
Thanks for your time and sorry for my english, Charles 感谢您的时间,对不起我的英语,查尔斯
You're missing a trailing right bracket to close bool
: 您缺少右方括号来关闭bool
:
fullscreen = bool(config.get('Screen', 'fullscreen'))
^
And the same with int
: 与int
相同:
width = int(config.get('Screen', 'width'))
^
height = int(config.get('Screen', 'height'))
^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.