Python Forum
Trying to write and execute first Python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to write and execute first Python script
#1
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
Reply
#2
(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.
Reply
#3
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
Reply
#4
Thanks for your replies. I was able to create and run python scripts through IDLE.

Regards,
Arvind Gupta.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,003 Jun-29-2023, 11:57 AM
Last Post: gologica
  Is this possible to write a script for checking data from website? WanW 2 1,081 Jun-02-2022, 02:31 AM
Last Post: Larz60+
  How To Set Up And Execute A Python File knight2000 4 1,824 May-31-2022, 10:02 AM
Last Post: Larz60+
  Is it possible to write a python script to block twitter feeds? cubangt 0 837 Apr-07-2022, 04:14 PM
Last Post: cubangt
  execute python script guy7200 1 1,572 Oct-25-2021, 09:55 PM
Last Post: Axel_Erfurt
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,232 May-18-2021, 06:31 AM
Last Post: Skaperen
  Using python to execute app or cmd that requires admin credentials thewolf 0 2,078 Mar-05-2021, 08:15 PM
Last Post: thewolf
  Execute DBCC CHECKDB from python script susja 1 2,060 Aug-12-2020, 02:09 AM
Last Post: susja
  Execute full script samuelbachorik 0 1,511 Aug-06-2020, 08:09 PM
Last Post: samuelbachorik
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,786 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020