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.
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.










share|improve this question




























    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.
    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.










    share|improve this question


























      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.
      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.










      share|improve this question















      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.
      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 2:34

























      asked Nov 11 at 2:23









      Person

      84112




      84112
























          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().






          share|improve this answer























          • 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






          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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().






          share|improve this answer























          • 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






          • 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















          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().






          share|improve this answer























          • 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






          • 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













          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().






          share|improve this answer














          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().







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 to raw = 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










          • By changing it to raw = 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."