How to run the automation scripts in python?
What are automation Scripts?
A code
that can be reusable to execute a function in multiple times. It automatically
executed without any user intervention.
In python, it is stored with ‘.py’ extension.
Steps to execute the automation scripts:
1.Python Installation
- · First, make sure that system has python.
- · Just check the version in command prompt.
- · Open the command prompt by giving ‘cmd’ command in search panel.
- · It opens the command prompt.
- · Use the below syntax to check the version.
C:\Users\rajeswari jeevananth>python --version
Python 3.10.0
2. Set up your Environment for windows
·
Create a project folder.
3. Create the automation script
Let us
create a python code to rename a file in a directory. Actual file is created
with the name of “automation.py”.
This program checks the directory. Finds the file and
renames it.
Python code:
import os
folder =
"C:/Users/rajeswari jeevananth/Documents"
for count,
filename in enumerate(os.listdir(folder)):
new_name = f"file_{count}.txt"
os.rename(os.path.join(folder,
filename),
os.path.join(folder, new_name))
print("Files
renamed successfully!")
Output:
yes. The code is executed successfully.
Why automation scripts are needed?
Main purpose
is to save the time.
Other uses:
o Organizing
the file activities.
o web
scraping
o Email
automation.
o scheduled backups execution in periodical manner.
o Automative
software testing.
o Frequent
Controlling of browsers or applications.
o Other
maintenance activities.
These are the basics of executing an automation script in
python. Hope, you understood the
concept. Keep coding!!!!
Comments
Post a Comment