我使用Sublime Text 2,Package Control和SublimeREPL來(嘗試)創建和運行Python代碼。該代碼是一個簡單的Brainfuck解釋器,如下所示。然而,這不是問題:SublimeREPL返回無用的錯誤,在空閒功能
import sys
def brainfuck(arg_bf_string):
bf_string = arg_bf_string
bf_string_pointer = 0
value_array = [0] * 65536
value_array_pointer = 0
running = True
while running:
if bf_string[bf_string_pointer] == ">":
value_array_pointer += 1
if bf_string[bf_string_pointer] == "<":
value_array_pointer -= 1
if bf_string[bf_string_pointer] == "+":
value_array[value_array_pointer] += 1
if bf_string[bf_string_pointer] == "-":
value_array[value_array_pointer] -= 1
if bf_string[bf_string_pointer] == ".":
sys.stdout.write(chr(value_array[value_array_pointer]))
if bf_string[bf_string_pointer] == ",":
value_array[value_array_pointer] = ord(raw_input("INP "))
if bf_string[bf_string_pointer] == "[":
if value_array[value_array_pointer] == 0:
loop_depth = 0
loop_pointer = bf_string_pointer + 1
loop_searching = True
while loop_searching:
if bf_string[loop_pointer] == "[":
loop_depth += 1
elif bf_string[loop_pointer] == "]" and loop_depth > 0:
loop_depth -= 1
elif bf_string[loop_pointer] == "]" and loop_depth == 0:
bf_string_pointer = loop_pointer
loop_searching = False
loop_pointer += 1
if bf_string[bf_string_pointer] == "]":
if value_array[value_array_pointer] != 0:
loop_depth = 0
loop_pointer = bf_string_pointer - 1
loop_searching = True
while loop_searching:
if bf_string[loop_pointer] == "]":
loop_depth += 1
elif bf_string[loop_pointer] == "[" and loop_depth > 0:
loop_depth -= 1
elif bf_string[loop_pointer] == "[" and loop_depth == 0:
bf_string_pointer = loop_pointer
loop_searching = False
loop_pointer -= 1
bf_string_pointer += 1
if bf_string_pointer > len(bf_string)-1:
running = False
def main():
brainfuck(raw_input("BF "))
我成功運行在IDLE這個代碼很順利,所以我敢肯定,代碼本身不是一個問題。
當使用SublimeREPL然而,運行它,我得到以下錯誤:
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
^
而且我不知道在哪裏這是一個從未來。我可以通過簡單地將文件加載到Sublime Text中,然後在REPL> File中選擇Tools> SublimeREPL> Eval來複制該文件。
我試過了> SublimeREPL> Python> Python - RUN當前文件。在執行此操作時,我會在REPL選項卡中收到以下內容:
C:\Python27\python.EXE: can't open file '$file_basename': [Errno 2] No such file or directory
***Repl Closed***
我可以鍵入提示符,但它完全沒有響應。我猜想我的Python安裝出了問題。我不知道該怎麼做或如何解決,或者如果這是我應該擔心的事情。
據我所知,我已經正確安裝了SublimeREPL,使用包控制並從設置 - 默認設置 - 設置 - 用戶複製SublimeREPL設置。我試過重新安裝我的Python安裝。任何幫助表示讚賞。
這是第一次。後續嘗試使用'Tools - > SublimeREPL - > Eval in REPL - > File'加載程序返回相同的錯誤:' 文件「」,第1行 Python 2.7.6(默認,2013年11月10日,19:24:18)win32上的[MSC v.1500 32位(Intel)] ^ SyntaxError:invalid syntax'。 '工具 - > SublimeREPL - > Python - > Python - RUN當前文件'仍然無法使用。 –