python - 通过函数发送列表的值

标签 python interpreter

我正在为我制作的编程语言创建一个简单的解释器。我正在努力做到这一点,以便您可以将多个语句放在一行上。 (如 print "Hello"; print "World"。语句之间使用分号分隔 ;)

问题是,当我尝试在解释器中使用多个语句时出现错误。

我正在做的是获取用户输入,并用分号将其分割(这些部分进入列表)。我希望列表的值通过我拥有的 parse() 函数运行。

简而言之,我想通过函数运行列表的值。

这是我当前的代码:

if ';' in command:
        semiCount = command.count(';')
        command.split(';')
        for i in range(0, semiCount):
            command[i].replace(" ", "")
            parse(command[i])

最佳答案

据我了解,你想要这个:

temp_input=raw_input()  #taking the input
lst=temp_input.split(";") # splitting the input and saving in a list
for i in lst: # iterating through the list
    parse(i) # calling parse() with single list element

这是你想要的吗?

关于python - 通过函数发送列表的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32997780/

相关文章:

python - 灰度 PIL 图像到 OpenCV 格式

python - imshow() 和 matplotlib() 不能一起工作

perl - 如何在嵌入式 perl 解释器中动态加载 perl 扩展?

haskell - 是否可以从提示中的错误评估中恢复?

Python 子进程允许用户交互

Python itertools 获取列表列表的排列和组合

jvm - 有没有办法关闭 JIT 编译器,这样做是否会影响性能?

scala - 在运行时从 Scala 源代码创建可序列化对象

Ruby 解释器名称

python - 将数据从 LabView 发送到 Python 并返回