Tired of doing daily repetitious chores? Well, it may dull even the toughest among us from within our heads.
Lucky for us, the digital era we live in provides a wealth of tools to free ourselves of such kind of labor. One of them is Python, the ideal programming language to start your path with task automation.
We will discuss in this post six suggestions with real-life examples and the reasons to automate Python activities. Arzu Huseynov, a Python Developer employed at Monterail, worked on the two final examples; I wrote the first four.
Here's the introduction blog article for you should you like to learn more about Python foundations before we start:
How would one begin with task automation?
First of all, despite your full rookie status in the sector, automation is absolutely for you.
Although first it may appear difficult, creating your first script will be rather fulfilling and your new abilities will save a lot of time down road.
Python Automation List
Python automation is briefly step-by-step guided here:
Consider first the repetitious chores your daily employment requires.
Name any you believe could be automated.
Sort your job into smaller jobs.
Consider how you may at least partially automate at least some of these.
Once you choose a suitable chore, you have to decide on the appropriate tool.
Speaking from the standpoint of a Python developer, it is not surprising that the "tool" I would investigate is Python. Among the great range of languages accessible, Python is quite simple to pick up and has shown value in many different disciplines.
Why Automate Tasks Using Python?
Python has easy accessible syntax and high readability. The later is a great starting point for your adventure as it sounds like simple English.
Among other languages, Python is obviously among the easiest ones in use.
View this sample of C++ and Python code.
Python's above mentioned benefits help to speed and ease the learning process. Given little time and effort, you will learn enough to create basic scripts. Even experienced developers can benefit from this flat learning curve greatly accelerating development.
Furthermore persuading you to utilize Python is its excellent support for data structures.
Python provides numerous varieties of data structures by default, including lists, dictionaries, tuples, and sets; data structures help you to store and access data. These systems provide simple, effective data management as well as, when selected wisely, improve program performance. Besides, the data is kept consistently and securely.
Better further, Python allows you to design your own data structures, which lends great flexibility to the language. Although a novice may not find data structures very relevant, believe me on this: your choice of data structure usually becomes more crucial the deeper you go.
Python lets you almost automate almost everything. From emailing and completing PDFs and CSVs—if you are not familiar with this file format I encourage you to examine it—used by Excel—to communicate with outside APIs and send HTTP requests. Whatever your concept is, Python together with its modules and tools will most likely help you realize it.
From machine learning and web scraping to computer system management, plenty of Python-built modules make the language really potent, enabling developers to address everything.
Python Use Cases: Starting Point
From this introduction, you should be able to understand Python as a flexible programming language applied in many spheres and sectors. Among the illustrations are:
Testing Web Development
Web Scrapping
Data Interpretive
Computer Graphics: Machine Learning
Internet of Things and Big Data
With Python, what should one do? Ideas for Automated Scripts
Here's my reply: essentially, Python allows any repetitious chore to be automated with some effort.
You simply need Python on your computer (all of the examples below were written in Python 3) and the libraries for a specific problem to accomplish it. I will show you that automation is simple with Python; I will not be teaching you the language. I used iPython, a program designed to enable interactive, step-by-step code writing, in the samples below.
Python's built-in libraries ought should be sufficient for straightforward automated chores. In other situations, I will let you know what ought to be installed.
Reading (including writing) files
Python can help you to effectively automate reading and writing files. You simply need to know the location of the files in your filesystem, their names, and the mode you should open them in initially.
In the case below, I opened a file using the with statement—a method I strongly advise. The file closes automatically and our cleaning is handled after the with block code is completed. The official records provide further information about it.
Let's open the file and load it. The first argument Open() uses is a file path; the opening mode is the second. Default loading of the file is in read-only mode ("r"). Use the read() function to access a file's whole contents.
In [1]: with open(“text_file.txt”) as f:
...: print(f.read())
...:
A simple text file.
With few lines.
And few words.
Try the readlines() approach to line-by-line reading the material; it stores the contents into a list.
In [2]: with open(“text_file.txt”) as f:
...: print(f.readlines())
...:
[“A simple text file.”, “With few lines.”, “And few words.”]
A file's contents are also yours to change. Loading it in write, or "w," mode is one of the choices for doing so. The second argument of the open() function guides the mode choice. But be cautious with it as it replaces the original material!
In [3]: with open(“text_file.txt”, “w”) as f:
...: f.write(“Some content”)
...:
In [4]: with open(“text_file.txt”) as f:
...: print(f.read())
...:
Some content
2. Sending emails
Emailing others is another chore that Python can automate. The excellent smtplib module included with Python allows you to send emails over the Simple Mail Transfer Protocol (SMTP). Discover how easy it is to send an email using the SMTP server of Gmail and the library here. Naturally, you will need an email account on Gmail; however, I highly advise you to open a new account just for this script. The reason is Setting the Allow less secure applications option to ON will help others to access your private data simpler as you will need to do so. Now set up the account and, after you're done, let's start coding.
We will first need to create an SMTP connection.
In [1]: import getpass
In [2]: import smtplib
In [3]: HOST = “smtp.gmail.com”
In [4]: PORT = 465
In [5]: username = “username@gmail.com”
In [6]: password = getpass.getpass(“Provide Gmail password: “)
Provide Gmail password:
In [7]: server = smtplib.SMTP_SSL(HOST, PORT)
Tired of doing daily repetitious chores? Well, it may dull even the toughest among us from within our heads.
Lucky for us, the digital era we live in provides a wealth of tools to free ourselves of such kind of labor. One of them is Python, the ideal programming language to start your path with task automation.
We will discuss in this post six suggestions with real-life examples and the reasons to automate Python activities. Arzu Huseynov, a Python Developer employed at Monterail, worked on the two final examples; I wrote the first four.
Here's the introduction blog article for you should you like to learn more about Python foundations before we start:
How would one begin with task automation?
First of all, despite your full rookie status in the sector, automation is absolutely for you.
Although first it may appear difficult, creating your first script will be rather fulfilling and your new abilities will save a lot of time down road.
Python Automation List
Python automation is briefly step-by-step guided here:
Consider first the repetitious chores your daily employment requires.
Name any you believe could be automated.
Sort your job into smaller jobs.
Consider how you may at least partially automate at least some of these.
Once you choose a suitable chore, you have to decide on the appropriate tool.
Speaking from the standpoint of a Python developer, it is not surprising that the "tool" I would investigate is Python. Among the great range of languages accessible, Python is quite simple to pick up and has shown value in many different disciplines.
Why Automate Tasks Using Python?
Python has easy accessible syntax and high readability. The later is a great starting point for your adventure as it sounds like simple English.
Among other languages, Python is obviously among the easiest ones in use.
View this sample of C++ and Python code.
Python's above mentioned benefits help to speed and ease the learning process. Given little time and effort, you will learn enough to create basic scripts. Even experienced developers can benefit from this flat learning curve greatly accelerating development.
Furthermore persuading you to utilize Python is its excellent support for data structures.
Python provides numerous varieties of data structures by default, including lists, dictionaries, tuples, and sets; data structures help you to store and access data. These systems provide simple, effective data management as well as, when selected wisely, improve program performance. Besides, the data is kept consistently and securely.
Better further, Python allows you to design your own data structures, which lends great flexibility to the language. Although a novice may not find data structures very relevant, believe me on this: your choice of data structure usually becomes more crucial the deeper you go.
Python lets you almost automate almost everything. From emailing and completing PDFs and CSVs—if you are not familiar with this file format I encourage you to examine it—used by Excel—to communicate with outside APIs and send HTTP requests. Whatever your concept is, Python together with its modules and tools will most likely help you realize it.
From machine learning and web scraping to computer system management, plenty of Python-built modules make the language really potent, enabling developers to address everything.
Python Use Cases: Starting Point
From this introduction, you should be able to understand Python as a flexible programming language applied in many spheres and sectors. Among the illustrations are:
Testing Web Development
Web Scrapping
Data Interpretive
Computer Graphics: Machine Learning
Internet of Things and Big Data
With Python, what should one do? Ideas for Automated Scripts
Here's my reply: essentially, Python allows any repetitious chore to be automated with some effort.
You simply need Python on your computer (all of the examples below were written in Python 3) and the libraries for a specific problem to accomplish it. I will show you that automation is simple with Python; I will not be teaching you the language. I used iPython, a program designed to enable interactive, step-by-step code writing, in the samples below.
Python's built-in libraries ought should be sufficient for straightforward automated chores. In other situations, I will let you know what ought to be installed.
Reading (including writing) files
Python can help you to effectively automate reading and writing files. You simply need to know the location of the files in your filesystem, their names, and the mode you should open them in initially.
In the case below, I opened a file using the with statement—a method I strongly advise. The file closes automatically and our cleaning is handled after the with block code is completed. The official records provide further information about it.
Let's open the file and load it. The first argument Open() uses is a file path; the opening mode is the second. Default loading of the file is in read-only mode ("r"). Use the read() function to access a file's whole contents.
Try the readlines() approach to line-by-line reading the material; it stores the contents into a list.
A file's contents are also yours to change. Loading it in write, or "w," mode is one of the choices for doing so. The second argument of the open() function guides the mode choice. But be cautious with it as it replaces the original material!
2. Sending emails
Emailing others is another chore that Python can automate. The excellent smtplib module included with Python allows you to send emails over the Simple Mail Transfer Protocol (SMTP). Discover how easy it is to send an email using the SMTP server of Gmail and the library here. Naturally, you will need an email account on Gmail; however, I highly advise you to open a new account just for this script. The reason is Setting the Allow less secure applications option to ON will help others to access your private data simpler as you will need to do so. Now set up the account and, after you're done, let's start coding.
We will first need to create an SMTP connection.