简体   繁体   English

python if语句的原子氢错误“解析时出现意外的EOF”! (但其他声明除外)

[英]Atom Hydrogen error “unexpected EOF while parsing” for python `if` statement!? (but not other statements)

Seems to be a problem w/ how Atom / Hydrogen interprets the code. 似乎是与Atom / Hydrogen解释代码有关的问题。 for loops it will give me the option to "fold" or "collapse" by clicking the carrot in the line number. for循环,通过单击行号中的胡萝卜,我可以选择“折叠”或“折叠”。 Yet, if blocks/statements have no such luck. 但是, if封锁/声明没有这种运气。

Editor name and version: Atom 1.35.1 编辑器名称和版本:Atom 1.35.1

Platform: Mac OS Sierra 10.12.6 平台:Mac OS Sierra 10.12.6

Color scheme: One Dark/Solarized Dark 配色方案:一种深色/日晒深色

错误图片:

## this works: 
for i in range(10): 
    print( i)

## this doesn't: 
if not False: 
    print("test worked")

## this example doesn't throw an error, but only executes the "if" and not the else parts: 
x= False
if x == True:
    print("test")
elif x == None:
    print ('test anyway')
else:
    print('test again')

I've completely uninstalled atom and deleted all known remaining files (see enter link description here , then reinstalled and problem persists. 我已经完全卸载了atom并删除了所有已知的剩余文件(请参阅在此处输入链接描述 ,然后重新安装,问题仍然存在。

Try selecting all the code you want to run before calling the run command. 在调用run命令之前,尝试选择所有要运行的代码。

The other option is to use cells and the hydrogen:run-cell command: 另一个选择是使用cellshydrogen:run-cell命令:

# %% Works if you run cells individually with `ctrl+shift+enter`
for i in range(10):
    print( i)

# %% this will now too: 
if not False: 
    print("test worked")

# %%
x= False
if x == True:
    print("test")
elif x == None:
    print ('test anyway')
else:
    print('test again')

Unless you select the code you want to run or use cells, Hydrogen tries to figure it out using atom grammar and code folding. 除非您选择要运行或使用单元的代码,否则Hydrogen会尝试使用原子语法和代码折叠将其找出来。 Usually it will get it right, but Python indentation and whitespace sometimes throws it off. 通常它会正确处理,但是Python缩进和空格有时会使其无法正常运行。

Feel free to open an issue if you think this bug should be prioritized, but it may depend on atom apis upstream and the workaround is easy enough I think. 如果您认为应该优先考虑此错误,请随时提出一个问题,但是它可能取决于上游的api api,而且我认为解决方法很容易。

The folding of if statements seems to be a bug in the languages-python plugin, eg., see https://github.com/atom/language-python/pull/300 (they are working on it). if语句的折叠似乎是languages-python插件中的错误,例如,请参见https://github.com/atom/language-python/pull/300 (他们正在研究)。

They encouraged me to open a bug issue in hydrogen. 他们鼓励我打开一个氢气问题。 Viola: https://github.com/nteract/hydrogen/issues/1589 中提琴: https : //github.com/nteract/hydrogen/issues/1589

I believe the solution will be to upgrade once versions are rolled up. 我相信解决方案将是在版本汇总后进行升级。 This doesn't seem to be a configuration/settings problem at this point. 目前,这似乎不是配置/设置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM