简体   繁体   English

用 Sublime Text 3 编写的 Python 代码将无法运行

[英]Python code written in Sublime Text 3 won't run

I am trying to run some simple code via my Linux terminal that I wrote in Sublime Text 3.我正在尝试通过我在 Sublime Text 3 中编写的 Linux 终端运行一些简单的代码。

There is no issue in my code, it looks like the following code:我的代码没有问题,它看起来像以下代码:

# Some Initialization
while True:
    if (i == 1):
        # Do  something

When I run the code via the terminal it won't reach the contents of the if statement even when i == 1 is True (I printed and checked that).当我通过终端运行代码时,即使i == 1True (我打印并检查过),它也不会到达if语句的内容。

Is there some way to configure Sublime Text 3 to fix the issue?有没有办法配置 Sublime Text 3 来解决这个问题?

For example, the following code won't enter the if statement:例如,以下代码不会输入if语句:

i = 1
print(i == 1) # it prints True on the terminal
if (i == 1): # the statement is True but won't enter the statement
    print('Hello World!')

If the error is something regarding the variable i , it is because you haven't initialised any value for i .如果错误与变量i有关,那是因为您没有为i初始化任何值。

You can initialise i :您可以初始化i

i = 0

before starting the while loop.在开始while循环之前。

If this is not the case, what is the detailed error message?如果不是这种情况,详细的错误消息是什么?

Try executing it inside sublime text 3 by going to tools>Build System>Python and then pressing Ctrl+B.尝试sublime text 3 中执行它,方法是转到工具>构建系统>Python,然后按 Ctrl+B。 I am not a 100% sure since I don't have Linux but this might work我不是 100% 确定,因为我没有 Linux 但这可能有效

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

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