Python Forum

Full Version: Trying to write and execute first Python script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am new to Python and trying to learn it. I have Python 3.8 with IDLE environment and Anaconda 3 installed in my system (The system has Windows 7 Pro – 64 bit). I was trying to run my first Python script but was unable to do so. I wrote three simple print commands in a notepad file and named it ‘first_script.py’ and saved it in a folder on Desktop (file attached here). I then tried to run the script by right clicking on it and selecting ‘Open with --> Python’. A small command line window did come up but disappeared within a second.

Pls. tell me how to run a script in Python IDLE/ Anaconda environment? Presently I just want to start writing small scripts and see them getting executed.

Thanks and Regards,
Arvind Gupta
(May-21-2020, 02:04 PM)garvind25 Wrote: [ -> ]I then tried to run the script by right clicking on it and selecting ‘Open with --> Python’. A small command line window did come up but disappeared within a second.
Add this,use code as shown here when post code,look at BBCode.
This will prevent cmd to close,has to hit Enter.
print('one')
print('two')
print('three')
input('Press Enter to exit')
You should general to it from command line(cmd) or Anaconda Prompt.
Learning to use command line is important in programming.
This is like this,now could also drop last line.
(base) C:\Miniconda3>python first_script.py
one
two
three
Press Enter to exit

(base) C:\Miniconda3>
See that (base) is active,this most always be activated when use Anaconda3 or Miniconda.
Other to look into with Anaconda3 is conda and also pip.
So it's use to install stuff if needed,try conda if not Repo then pip.

Also if start Anaconda Navigator there are link to editor like Spyder or can start Jupyter Notebook.
if you have Anaconda installed, you can use Jupiter notebook. I believe its best if you want to practice.In Jupiter notebooks we have cells and each cell can be run individually and its really easy to use.To open Jupiter notebook, Goto the command prompt and run
 jupyter notebook 
It takes some time but after one minute or so your browser will open up.Next on extreme right you will see a dropdown (named new).Click on it and select Python 3.
After that its a piece of cake.Write the code and run the cell to see what code does.Its best for beginners
Thanks for your replies. I was able to create and run python scripts through IDLE.

Regards,
Arvind Gupta.