473,394 Members | 2,052 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,394 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 2060
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.