Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we save it.
So when we use Python IDLE(GUI) we can navigate to "File" and then click on "New Window" or we can use shortcut i.e."Ctrl+N" which will open a new text editor where we can write our program and save it into any location on the operating system. From the new window we can execute our program too.
Below are the screen shots taken after opening IDEL and then opening a New window.
Now let us write a simple program and save it on any location, but when we save the file the extension of the file name will always be ".py" :
x = raw_input("Enter your name : ")
print "Hello " + x
Once it is saved on your system then navigate to "Run" and click on "Run Module" or "F5" which will run on the Python Shell as like below:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Enter your name : Sloba
Hello Sloba
>>>
I have named this program as "test.py". Below is the image of the file that I have saved it on my desktop.
Now we can also run this program by simply double click on it. But we will be unable to see the result after we enter the name as I have shown earlier, because it is processed so fast that we cannot see if the printed the input successfully or not.
So for avoiding this let us modify the program a bit and execute it from my desktop.
Modified code:
x = raw_input("Enter your name : ")
print "Hello " + x
raw_input(" Hit <enter> to Exit ")
So once we hit enter the command prompt will be closed. Now we come to know like how to save our Python program and if we want to hold before exit then we can make use of a function called "RAW_INPUT".
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
Comments (3)
Commented:
"Here I am using Python IDEL(GUI) to write a simple program and save it, so that we can just execute it in future."
Isn't it called Python IDLE?
-P0j0
Author
Commented:Regards,
Sloba
Commented: