Some of us might not know how to work with IDLE. so let me quickly through how to deal with IDLE saving of program and executing them. Hope you have by now IDLE installed in your system. If not please do it.
After having installed it will look like this,
In Windows we are working on IDLE, so they need not do anything special.
In IDLE, goto File → New Window. This is where we will be writing the code,execute and saving them, its just like a notepad. Lets write a small code to begin with
print “Hello world”
Go to Run → Run Module or you can press F5, then we have the output to the IDLE interface as shown in the figure:
Lets make it more interesting by writing the code:
x=raw_input(“Enter your name:”) print “Welcome,”+x
run the module(F5), we have
That’s it about saving the program guys, but this is not the end we have a python file saved in a specific destination, Let’s check that out. When you open that file we have a problem, Whats that??? After typing in the name we can’t see what has happened.
Note to Linux user,
You need to put this following line in your python script:
which means the script will execute with the help of env python in usr/bin directory. and another important thing you cannot directly execute the file which is located in a location specified, because the file is not executable. So,type in the terminal
v$chmod 700 p1.py
which makes the file executable. When we run in terminal, the problem is same we can’t see the output. Change the code in the python file, p1.py as
x=raw_input(“Enter your name:”) print “Welcome,”+x raw_input(“Press<Enter>”)
Just the save the file here and run it.
thor@war:~$ ls Desktop Documents Downloads examples.desktop pl.py thor@war:~$ chmod 700 pl.py thor@war:~$ python pl.py hello Enter your name:chandan Welcome, chandan thor@war:~$ ls Desktop Documents Downloads examples.desktop pl.py thor@war:~$