user input and lists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bellum
    New Member
    • Sep 2006
    • 23

    user input and lists

    Hi, Python is the first language for me to get into. I'm still really new and have a lot to learn, though...

    Does anyone know how to allow users to append lists?

    I tried

    user.append = raw_input("Type in desired username ")

    But apparently .append is read only. D:
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    you can't do that.

    users = []
    user = raw_input( "Enter user:")
    users.append(us er)

    Comment

    • Bellum
      New Member
      • Sep 2006
      • 23

      #3
      Oh....Duh, nvm.

      I've run into another problem, but from what I've seen, the proper sintax is

      user.append(raw _input("Type in desired username "))

      right?

      I can't properly test it, because (after changing user to a list) my original code directly afterward doesn't work.

      if len(user) > 4:

      Doesn't work because it's asking how many objects are in the list. D:

      I tried

      if len(user[0]), too, but to no avail. I think I've discovered a better way to do what I want, so I'm going to revert to user being a simple string, but I'd still like to know.


      EDIT: Oh, ok.

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        it should be users.append(ra w_input("Type in desired username "))
        if you declared "users" as a list

        len(users) will show how many items are inside the list

        Comment

        • Bellum
          New Member
          • Sep 2006
          • 23

          #5
          I know, but the intention was to find the number of characters in a particular object in the list. A 'no less than five characters' thing.

          I don't really need it anymore because I'm changing the way I'm going about this particular problem, but is it possible to do that using the len function on lists?




          Thanks for the help, mate.

          Comment

          Working...