python interactive scripts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peruron
    New Member
    • Aug 2007
    • 11

    python interactive scripts?

    Hello!

    I wanna create a script that goes through a file, and changes whatever relevant fields. This part isn't problematic, but I've decided to add another feature to it - instead of just changing the field, I want to ask the user if he's interested in doing so before every change takes place.
    Is there an option in python to communicate with the user while running?

    Thanks very much!
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by peruron
    Hello!

    I wanna create a script that goes through a file, and changes whatever relevant fields. This part isn't problematic, but I've decided to add another feature to it - instead of just changing the field, I want to ask the user if he's interested in doing so before every change takes place.
    Is there an option in python to communicate with the user while running?

    Thanks very much!
    Yes, to get input from a user, use the raw_input() or input() functions.
    [code=python]
    response = raw_input("Do you want to change blah blah blah: ")

    if response in ' Yy':
    print "Changing"
    else:
    print "Skipping"
    [/code]

    Comment

    • peruron
      New Member
      • Aug 2007
      • 11

      #3
      Originally posted by ilikepython
      Yes, to get input from a user, use the raw_input() or input() functions.
      [code=python]
      response = raw_input("Do you want to change blah blah blah: ")

      if response in ' Yy':
      print "Changing"
      else:
      print "Skipping"
      [/code]

      That absolutely great! I saw the C-Shell equivalent... (:
      Will it be correct (syntax-wise) to insert the whole thing in a "while" loop, until I get "y" or "n" from the user?


      Thanks again!

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by peruron
        That absolutely great! I saw the C-Shell equivalent... (:
        Will it be correct (syntax-wise) to insert the whole thing in a "while" loop, until I get "y" or "n" from the user?


        Thanks again!
        Do you mean something like this?:
        [CODE=python]while 1:
        response = raw_input("Ente r input: ")

        if response in 'YynN': # keep going if not 'y' or 'n'
        break[/CODE]

        Comment

        • peruron
          New Member
          • Aug 2007
          • 11

          #5
          I think this is just what I mean, will put it to test very soon.
          Thanks a lot!

          Comment

          Working...