无法将新变量附加到我的python字典中

时间:2019-06-20 02:31:04

标签: python dictionary

我正在用python语言编写一种叫做PythonScript的语言,它是JavaScript和Python(不是Python 3)的混合体。

我正在添加变量,但是当我执行以下代码时,我没有得到预期的结果。

var scuffles = hi!

我已经尝试调试它,正如您将在我的代码中看到的那样,我制作了一个调试数组,发现它为空。我查阅了一些教程,但没有一个涵盖我想做的事情。

这是文件的一部分:


    import os
    import sys

    programDebugingArray1 = []
    functions = ["Console"]
    functionCodes = [["out \"TEST\""]]
    programVariables = {}

    def lex(cm,stri,nums,toWake):
        i = 0
        if cm == "":
            console()
    elif cm == "var" or cm == "=":
            pass
        elif cm == "--vars":
            print(programVariables)
        elif cm == "--debugManual1":
            print(programDebugingArray1)
        else:
            print("\""+cm+"\" was not recognized as a PythonScript command.")
        console()
    def console():
        commandToRun = ""
        tok = ""
        string = ""
        varValue = ""
        newVarName = ""
        Strings = []
        Numbers = []
        functionToCall = ""
        state = 0
        command = input()
        for char in command:
            tok += char
            if state == 1:
                string += char
            elif state == 2:
                if char == " ":
                    char = ""
                newVarName += char
            elif state == 3:
                varValue += char
            if (tok == "\"" or tok == "'") or (char == "\"" or char == "'"):
                if state == 0:
                    state = 1
                elif state == 1:
                    state = 0
                    string = string[0:len(string) - 1]
                    Strings.append(string)
                    string = ""
                tok = ""
                char = ""
            elif tok == " ":
                tok = ""
            elif tok == "var" and state == 0:
                state = 2
                tok = ""
            elif tok == "=" and state == 2:
                state = 3
                tok = ""
            elif tok == "!" and state == 3:
                programDebugingArray1.append(newVarName)
                programDebugingArray1.append(varValue)
                state == 0
                programVariables[newVarName] = varValue
                tok = ""
            elif tok == "--vars" and state == 0:
                commandToRun == "--vars"
                tok = ""
            elif tok == "--debugManual1" and state == 0:
                commandToRun == "--debugManual1"
                tok = ""
        if commandToRun == "":
            commandToRun = command
        lex(commandToRun,Strings,Numbers,functionToCall)
    console()

我希望调试数组中至少包含一些内容,但是由于某种原因,它和变量字典为空。没有错误消息或没有退出控制台。

0 个答案:

没有答案