omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Fixed // Help! Error when removing from list.

    Pythonista
    2
    3
    1433
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dann239
      Dann239 last edited by

      Works!

      Very new to Python... However, I wrote this little list making script.
      If I run this, and go to my def Edit(), the script errors out when its asked to remove the item from the list using the user input. If the item in the list is just a single character, it succeeds without error. Any ideas?

      <code>
      import console
      list = []

      def view():
      print("Viewing Data")
      sortlist = sorted(list)
      print "\n".join(sortlist)
      x = raw_input().title()
      if x == "Q":
      return

      def add():
      print("In Adding Mode")
      sortlist = sorted(list)
      print "\n" .join(sortlist)
      x = raw_input().title()
      if x == "Q":
      return
      else: list.append(x.title())
      console.clear()
      add()

      def edit():
      print("Edit List, Remove?")
      sortlist = sorted(list)
      print "\n" .join(sortlist)
      x = raw_input().title()
      if x == "Q":
      return
      else: list.remove(x)
      console.clear()
      edit()

      while True:
      console.clear()
      choice = ["[A]dd to list" , "[V]iew List" , "[E]dit List"]
      print("List App")
      print('\n'.join(choice))
      print("Use 'q' to Exit")
      x = raw_input().title()
      if x == "A":
      console.clear()
      add()
      elif x == "V":
      console.clear()
      view()
      elif x == "E":
      console.clear()
      edit()
      </code>

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        'THIS' not in ('This', 'Is', 'Text')
        

        Add() calls x.title() but Edit() calls x.upper().

        Change all calls to upper() into calls to title() and your script should work.

        Also 'while True' is probably easier to understand (and type) than 'while 0 == 0'.

        1 Reply Last reply Reply Quote 0
        • Dann239
          Dann239 last edited by

          I appreciate the help! Thank you.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors