When I run the following script in IDLE
I get the output as
but when I run from cmd prompt, I get
How do I get the same result which I got using IDLE?
This can be because of IDLE of python changing its CWD (current working directory) to the location where the python script is running. So, using CWD while running the script does not do anything and leaves the CWD as same.
You can the following python code to change the CWD to the location where the script is running:
If you want to be a pro in Python then I recommend this Python Certification program by Intellipaat.