Python interpreter bugging out with error “AttributeError: 'list' object has no attribute 'split' ”
up vote
0
down vote
favorite
I was making a programming language in Python 3.6 when I stumbled across something odd. With the following code, I get an error, with some interesting output.
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.")
After running this, I get this error.

Are you seeing what I'm seeing? <class 'str'> is the class of raw[1]. Nothing there. But when I refer to it after, it says that it's a list!
Can someone tell me what's going on here?
EDIT
I forgot to add the viper file.
setvar("hmm", "No")
EDIT 2
I'm going to explain my issue. It's treating a string as a list.
python python-3.6 interpreter
add a comment |
up vote
0
down vote
favorite
I was making a programming language in Python 3.6 when I stumbled across something odd. With the following code, I get an error, with some interesting output.
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.")
After running this, I get this error.

Are you seeing what I'm seeing? <class 'str'> is the class of raw[1]. Nothing there. But when I refer to it after, it says that it's a list!
Can someone tell me what's going on here?
EDIT
I forgot to add the viper file.
setvar("hmm", "No")
EDIT 2
I'm going to explain my issue. It's treating a string as a list.
python python-3.6 interpreter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I was making a programming language in Python 3.6 when I stumbled across something odd. With the following code, I get an error, with some interesting output.
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.")
After running this, I get this error.

Are you seeing what I'm seeing? <class 'str'> is the class of raw[1]. Nothing there. But when I refer to it after, it says that it's a list!
Can someone tell me what's going on here?
EDIT
I forgot to add the viper file.
setvar("hmm", "No")
EDIT 2
I'm going to explain my issue. It's treating a string as a list.
python python-3.6 interpreter
I was making a programming language in Python 3.6 when I stumbled across something odd. With the following code, I get an error, with some interesting output.
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.")
After running this, I get this error.

Are you seeing what I'm seeing? <class 'str'> is the class of raw[1]. Nothing there. But when I refer to it after, it says that it's a list!
Can someone tell me what's going on here?
EDIT
I forgot to add the viper file.
setvar("hmm", "No")
EDIT 2
I'm going to explain my issue. It's treating a string as a list.
python python-3.6 interpreter
python python-3.6 interpreter
edited Nov 11 at 2:34
asked Nov 11 at 2:23
Person
84112
84112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The line after you print the type:
raw[1] = raw[1].split()
This turns it into a list. When you call raw[1] later with "params" : raw[1].split(), it is not a string anymore, but a list. So this means raw[1] is being split twice. If you are intending to return the parameters in raw[1] as a list, you could just remove the line raw[1] = raw[1].split().
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it toraw = raw[1].split(), it removes the "keyword" which I do not want.
– Person
Nov 11 at 2:32
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The line after you print the type:
raw[1] = raw[1].split()
This turns it into a list. When you call raw[1] later with "params" : raw[1].split(), it is not a string anymore, but a list. So this means raw[1] is being split twice. If you are intending to return the parameters in raw[1] as a list, you could just remove the line raw[1] = raw[1].split().
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it toraw = raw[1].split(), it removes the "keyword" which I do not want.
– Person
Nov 11 at 2:32
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
|
show 1 more comment
up vote
1
down vote
The line after you print the type:
raw[1] = raw[1].split()
This turns it into a list. When you call raw[1] later with "params" : raw[1].split(), it is not a string anymore, but a list. So this means raw[1] is being split twice. If you are intending to return the parameters in raw[1] as a list, you could just remove the line raw[1] = raw[1].split().
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it toraw = raw[1].split(), it removes the "keyword" which I do not want.
– Person
Nov 11 at 2:32
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
The line after you print the type:
raw[1] = raw[1].split()
This turns it into a list. When you call raw[1] later with "params" : raw[1].split(), it is not a string anymore, but a list. So this means raw[1] is being split twice. If you are intending to return the parameters in raw[1] as a list, you could just remove the line raw[1] = raw[1].split().
The line after you print the type:
raw[1] = raw[1].split()
This turns it into a list. When you call raw[1] later with "params" : raw[1].split(), it is not a string anymore, but a list. So this means raw[1] is being split twice. If you are intending to return the parameters in raw[1] as a list, you could just remove the line raw[1] = raw[1].split().
edited Nov 11 at 2:45
answered Nov 11 at 2:29
A Kruger
83117
83117
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it toraw = raw[1].split(), it removes the "keyword" which I do not want.
– Person
Nov 11 at 2:32
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
|
show 1 more comment
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it toraw = raw[1].split(), it removes the "keyword" which I do not want.
– Person
Nov 11 at 2:32
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
It would be helpful if you could give me an example of how to fix it.
– Person
Nov 11 at 2:30
By changing it to
raw = raw[1].split(), it removes the "keyword" which I do not want.– Person
Nov 11 at 2:32
By changing it to
raw = raw[1].split(), it removes the "keyword" which I do not want.– Person
Nov 11 at 2:32
1
1
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
Do you have an example line of what you're splitting and what you're trying to get?
– A Kruger
Nov 11 at 2:34
I added the viper file with the post.
– Person
Nov 11 at 2:35
I added the viper file with the post.
– Person
Nov 11 at 2:35
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
I'm not sure the intention of the rest of the code, but this should have address the error. Are you still getting the error?
– A Kruger
Nov 11 at 3:04
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245308%2fpython-interpreter-bugging-out-with-error-attributeerror-list-object-has-no%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown