473,225 Members | 787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 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 2053
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

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

Similar topics

50
by: Edward K. Ream | last post by:
I would like to say a few (actually more than a few) words here about some recent discoveries I have made concerning the interaction of Leo and Python. If you don't want to hear an inventor enthuse...
16
by: sb | last post by:
Hello I have a bunch of questions about using python scripting in vim and about editing python with vim. I can install vim with python scripting support, but I can not find docs, examples...
9
by: Nuff Said | last post by:
When I type the following code in the interactive python shell, I get 'UTF-8'; but if I put the code into a Python script and run the script - in the same terminal on my Linux box in which I...
0
by: Fuzzyman | last post by:
Movable Python has just been released on sourceforge. Movable Python is a frozen distribution of Python. It will run python scripts without needing to be installed. ...
30
by: bblais | last post by:
Hello, Let me start by saying that I am coming from a background using Matlab (or Octave), and C++. I am going to outline the basic nuts-and-bolts of how I work in these languages, and ask for...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
4
by: fuffens | last post by:
Hi! Does anyone here have experience with Python in Eclipse environment? I have downloaded the Pydev plug-in for Eclipse. I like the editor and I find it very useful to be able to add files in a...
34
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
7
by: Anthony | last post by:
Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual...
9
by: Catherine Moroney | last post by:
I have one script (Match1) that calls a Fortran executable as a sub-process, and I want to write another script (Match4) that spawns off several instances of Match1 in parallel and then waits...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.