472,126 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

python interactive scripts?

11
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!
Aug 16 '07 #1
4 2005
ilikepython
844 Expert 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. response = raw_input("Do you want to change blah blah blah: ")
  2.  
  3. if response in ' Yy':
  4.     print "Changing"
  5. else:
  6.     print "Skipping"
  7.  
Aug 16 '07 #2
peruron
11
Yes, to get input from a user, use the raw_input() or input() functions.
Expand|Select|Wrap|Line Numbers
  1. response = raw_input("Do you want to change blah blah blah: ")
  2.  
  3. if response in ' Yy':
  4.     print "Changing"
  5. else:
  6.     print "Skipping"
  7.  

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!
Aug 16 '07 #3
ilikepython
844 Expert 512MB
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?:
Expand|Select|Wrap|Line Numbers
  1. while 1:
  2.     response = raw_input("Enter input: ")
  3.  
  4.     if response in 'YynN':   # keep going if not 'y' or 'n'
  5.         break
Aug 16 '07 #4
peruron
11
I think this is just what I mean, will put it to test very soon.
Thanks a lot!
Aug 16 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

50 posts views Thread by Edward K. Ream | last post: by
16 posts views Thread by sb | last post: by
reply views Thread by Fuzzyman | last post: by
30 posts views Thread by bblais | last post: by
118 posts views Thread by 63q2o4i02 | last post: by
4 posts views Thread by fuffens | last post: by
9 posts views Thread by Catherine Moroney | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.