L02-Python Scripts
L02-Python Scripts
Python Scripts
Write/Edit
OK?
NO
YES
YES
NO More
Inputs?
07/05/2025 Python Programming 3
Need for scripting
• The development of complicated programs using python terminal is very
difficult, complex, and time-consuming. Scripting is used for the development of
such complex and large programs.
• Windows Users:
• The steps for the methods are first, writing the python program in notepad second,
saving the program saved using a .py extension, and finally, executing the respective
program by typing the name of the program in the command prompt “python
filename.py”.
• Note: Set the path variable correctly before executing the script.
• Mac Users:
• Double-click the script in the Finder, to run a script application. The events and results
can’t be viewed if running a script app outside of Script Editor.
07/05/2025 Python Programming 4
Advantages of Scripting
• Scripting, developing a set of commands designed to work together,
to execute a needed task or set of tasks.
• The demand for scripting languages increases as there is a need for
easy solutions for developing complex programs in the market. As the
popularity and the traction for these scripting languages increase,
developers try to push the limits to get faster and better results. They
are easy to develop and can be executed in a short time.
• Note: Python is still considered to have an upper hand, and scripts
can mostly be used for integrations-related tasks. Developers should
know the boundaries and should respect them.
07/05/2025 Python Programming 5
Need for Documenting the Code
• Documenting the written python code is very important. It helps in easy usage of
the code for others and also for yourself. With proper documentation, the
structuring and usage of the respective code can be easily remembered for future
purposes. For documenting a source code, we make use of comments. Comments
are denoted by #. Python ignores the text written as comments.
• Note:
• Plain text files can be used to create and store Python commands
• Use python <scriptname> to run the respective file
• Extension .py is generally used for python scripts.
• Always opt for a syntax-highlighting text editor to edit your Python scripts.
• Make use of comments, as the comments improve the readability of your code and can be
used to understand the structuring and usage of the script for future purposes
07/05/2025 Python Programming 6
How to write Python Scripts?
• There is no semicolon at the end of the statement as with Python.
• No need to specify the end of the line.
• Also, we don’t need to include or import any files to run a simple python script.
• There is more than one way to run a python script but before going toward them, we first
must check whether a python interpreter is installed on the system or not.
• So, in Windows OS, open ‘cmd’ (Command Prompt) using Win key + R and type the
following command: python –V
• This command will give the version number of the Python interpreter installed or will
display an error if otherwise.
Filename,
preferred
extension is py
User Program
07/05/2025 Python Programming 13
Outputs
Python Shell is
Interactive
07/05/2025 Python Programming 14
Text Editors and IDEs
• When developing larger and more complex applications, it is recommended that you use an
Integrated Development Environment (IDE) or an advanced text editor.
• Most of these programs offer the possibility of running your scripts from inside the environment
itself. It is common for them to include a Run or Build command, which is usually available from
the tool bar or from the main menu.
• Python’s standard distribution includes IDLE as the default IDE, and you can use it to write, debug,
modify, and run your modules and scripts.
• Other IDEs such as Eclipse-PyDev, PyCharm, Eric, and NetBeans also allow you to run Python
scripts from inside the environment.
• Advanced text editors like Sublime Text and Visual Studio Code also allow you to run your scripts.
• To grasp the details of how to run Python scripts from your preferred IDE or editor, you can look
at its documentation.