Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

L02-Python Scripts

The document discusses the importance of scripting in Python programming, highlighting its advantages for developing complex programs efficiently. It outlines the steps for writing and executing Python scripts on both Windows and Mac, as well as the need for proper documentation and the various methods to run scripts, including interactive mode and using IDEs. Additionally, it emphasizes the significance of using comments for code readability and the use of appropriate text editors or IDEs for larger applications.

Uploaded by

madhurb2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

L02-Python Scripts

The document discusses the importance of scripting in Python programming, highlighting its advantages for developing complex programs efficiently. It outlines the steps for writing and executing Python scripts on both Windows and Mac, as well as the need for proper documentation and the various methods to run scripts, including interactive mode and using IDEs. Additionally, it emphasizes the significance of using comments for code readability and the use of appropriate text editors or IDEs for larger applications.

Uploaded by

madhurb2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Lecture – 2

Python Scripts

07/05/2025 Python Programming 1


A Typical Programming Cycle

07/05/2025 Python Programming 2


Run
with some input

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.

07/05/2025 Python Programming 7


05/07/2025 Python Programming 8
Different ways to run Python Script
• Here are the ways with which we can run a Python script.
• Interactive Mode
• Command Line
• Text Editor (VS Code)
• IDE (Spyder / Jupyter Notebook)

07/05/2025 Python Programming 9


Interactive Mode
• In this mode, you can run your script line by line in a sequence.
• To enter in an interactive mode, you will have to open Command Prompt on your
Windows machine and type ‘python’ and press Enter key.

07/05/2025 Python Programming 10


Interactive Mode – Example 1
• Run the following line in the interactive mode:
• print(‘Hello World !’)

07/05/2025 Python Programming 11


Interactive Mode – Example 2
• Run the following line in the interactive mode:
• name = ”Aditya"
• print("My name is " + name)

07/05/2025 Python Programming 12


Text Editors and IDEs
• To run a Python script store in a ‘.py’ file in command line, we have to
write ‘python’ keyword before the file name in the command prompt.

Filename,
preferred
extension is py

User Program
07/05/2025 Python Programming 13
Outputs

Python Shell Prompt

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.

07/05/2025 Python Programming 15


THANK YOU

07/05/2025 Python Programming 16

You might also like