Python解释器出现错误;属性错误:';列表';对象没有属性';拆分'&引用;
我正在用Python3.6编写一种编程语言,突然发现了一些奇怪的东西。通过下面的代码,我得到了一个错误,并有一些有趣的输出Python解释器出现错误;属性错误:';列表';对象没有属性';拆分'&引用;,python,python-3.6,interpreter,Python,Python 3.6,Interpreter,我正在用Python3.6编写一种编程语言,突然发现了一些奇怪的东西。通过下面的代码,我得到了一个错误,并有一些有趣的输出 import sys import tkinter as tk import datetime class _Viper: def __init__(self): pass def error(self, err, title="ERROR"): root = tk.Tk() root.title(title
import sys
import tkinter as tk
import datetime
class _Viper:
def __init__(self):
pass
def error(self, err, title="ERROR"):
root = tk.Tk()
root.title(title)
root["bg"] = "#d56916"
label = tk.Label(root, text=err)
labelt = tk.Label(root, text=str(datetime.datetime.now()))
label.config(bg="#e67a27")
labelt.config(bg="#d56916")
label.grid()
labelt.grid()
root.mainloop()
def grabdata(self, line):
raw = line.split("(")
raw[1] = raw[1][:-1]
print(type(raw[1]))
raw[1] = raw[1].split()
#raw[1] = raw[1].split('"')
return {
"keyword" : raw[0],
"params" : raw[1].split()
}
Viper = _Viper() #For PyLint
"""
try:
sys.argv[1]
execute = True
except:
execute = False
Viper.error("Error `Viper.FileNotProvidedError` @ interpreter.py. Do not directly run this file. Run it with `Viper0.0.0a C:\\path\\to\\file`, or associate viper to Viper0.0.0a.bat.")
"""
sys.argv.append("C:\\viper\\interpreter\\testie.vi")
execute = True
if execute:
extension = str(sys.argv[1][-2]+sys.argv[1][-1])
if extension.upper() == "VI":
with open("C:\\viper\\interpreter\\testie.vi", "r") as src:
lines = src.readlines()
for line in lines:
Viper.grabdata(line)
else:
Viper.error("Error `Viper.ExtensionNotViperError` @ interpreter.py. Please run this with a file with the \"vi\" extension.")
运行此命令后,我得到此错误。
你看到我看到的了吗
是原始[1]
的类。那里什么也没有。但当我在后面提到它时,它说这是一个列表
有人能告诉我这是怎么回事吗
编辑
我忘了添加毒蛇文件
编辑2
我要解释我的问题。它将字符串视为打印类型后的列表行:
raw[1] = raw[1].split()
这将把它变成一个列表。当您稍后使用
参数调用raw[1]
时:raw[1].split()
,它不再是一个字符串,而是一个列表。这意味着raw[1]
将被拆分两次。如果您打算将raw[1]
中的参数作为列表返回,您可以删除行raw[1]=raw[1]。split()
如果您能给我一个如何修复它的示例,那将很有帮助。通过将其更改为raw=raw[1]。split()
,它将删除“关键字”这是我不想要的。你有没有一个示例行,说明你正在拆分什么以及你想要得到什么?我在帖子中添加了viper文件。我不确定代码其余部分的意图,但这应该可以解决错误。你还在犯错误吗?
raw[1] = raw[1].split()