CoderzColumn : Python Tutorials (Page: 1)

Python Tutorials


Python is one of the most widely used programming languages today. This section is a large archive of tutorials, based on Python programming language. We cover the basic and advanced technical aspects through coding examples and snippets.

  • Parallel Computing
  • Concurrent Programming
  • Speed Up Python Code
  • Working with Emails
  • Profiling
  • Jupyter Notebook Helpers
  • Web Scraping
  • File & Directory Access
  • Work With Archives
  • Generic OS Services
  • Python Runtime Services
  • Text Processing Services
  • File Formats
  • Networking & Interprocess Communication
  • Image Processing

For an in-depth understanding of the above concepts, check out the sections below.

Recent Python Tutorials


Tags python, multiprocessing, multiprocessing-using-py…
Python multiprocessing Module - Simple Guide to Work with Processes in Python
Python

Python multiprocessing Module - Simple Guide to Work with Processes in Python

A complete guide on how to use Python module multiprocessing to create processes and assign tasks to them for parallel execution with simple and easy-to-understand examples. Tutorial covers topics like how to create processes, how to make processes wait for other processes, how to kill or terminate processes, how to create a pool of processes and submit tasks to it, etc.

Sunny Solanki  Sunny Solanki
Tags asyncio, async-await, concurrent_programming
asyncio - Concurrent Programming using Async / Await Syntax in Python
Python

asyncio - Concurrent Programming using Async / Await Syntax in Python

A detailed guide on how to use Python Module "asyncio" and keywords "async" & "await" for concurrent programming in Python. Tutorial covers how to create coroutines using "async/await" syntax and run them in parallel using "asyncio" module. Tutorial covers topics like creating coroutines, collecting results once coroutines are complete, waiting for coroutines, canceling coroutines, retrieving pending coroutines, etc in detail.

Sunny Solanki  Sunny Solanki
Tags email
email - How to Represent an Email Message in Python?
Python

email - How to Represent an Email Message in Python?

A complete guide on how to use Python library "email" to represent emails with simple examples. Tutorial covers topics like creating a simple email message, emails with CC / BCC, emails with diff types of attachments, setting HTTP headers in emails, combining different content types in emails, etc.

Sunny Solanki  Sunny Solanki
Tags smtp, send-mails
smtplib - Simple Guide to Sending EMails using Python
Python

smtplib - Simple Guide to Sending EMails using Python

A detailed guide on how to use Python library "smtplib" to send emails (Gmail, Yahoo, etc) with simple examples. Tutorial covers various operations with mailbox servers like login / logout, verifying email ids, sending emails with CC / BCC, sending mails with attachments, etc. It uses SMTP protocol behind the scene to send emails.

Sunny Solanki  Sunny Solanki
Tags system-signals
signal - Simple Guide to Send, Receive and Handle System Signals in Python
Python

signal - Simple Guide to Send, Receive and Handle System Signals in Python

A comprehensive guide on how to use Python module "signal" to send, receive and handle system (Unix/Windows) signals to signal some event. The library lets us catch signal and run a handler (callback) based on event represented by signal. The signal can be sent to different threads and processes to inform them about event and execute handler by them accordingly.

Sunny Solanki  Sunny Solanki
Tags difflib, sequence-comparison
difflib - Simple Way to Find Out Differences Between Sequences / File Contents using Python
Python

difflib - Simple Way to Find Out Differences Between Sequences / File Contents using Python

A simple guide on how to use Python module “difflib” to compare sequences and find out differences between them. Tutorial explains whole API of a module to explain different ways of comparing sequences and format results in different ways. It can be very useful to compare file contents to see differences.

Sunny Solanki  Sunny Solanki
Tags configuration-files-parser
configparser - Simple Guide to Create and Parse Configuration Files in Python
Python

configparser - Simple Guide to Create and Parse Configuration Files in Python

A simple guide on how to use Python library "configparser" to create, read, parse, and modify config files (Generally ending with .conf, .ini, etc) in Python. Apart from basics, tutorial covers how to add/remove sections, create configuration from Python dictionary or strings and specify section details as formatted Python strings. All topics are covered with simple and easy-to-understand examples.

Sunny Solanki  Sunny Solanki
Tags events, scheduler, sched
sched - How to Schedule Events in Python?
Python

sched - How to Schedule Events in Python?

A simple guide on how to use Python module "sched" to schedule events. It let us run a function/callable in future. We can run a task at a specified time in future or after a specified time interval has passed. Apart from scheduling tasks, we have covered how to cancel tasks, assign priorities, create a scheduler with different time units, etc.

Sunny Solanki  Sunny Solanki
Tags python, parallel-processing
joblib - Parallel Processing in Python
Python

joblib - Parallel Processing in Python

A detailed guide on how to use Python library joblib for parallel computing in Python. Tutorial explains how to submit tasks to joblib pool and then retrieve results. It even explains how to use various parallel computing backend like loky, threading, multiprocessing, dask, etc.

Sunny Solanki  Sunny Solanki
Tags logging-configuration
logging.config - Simple Guide to Configure Loggers from Dictionary and Config Files in Python
Python

logging.config - Simple Guide to Configure Loggers from Dictionary and Config Files in Python

An in-depth guide to configure loggers from dictionary and config files. Python module "logging.config" provides us with various methods to create loggers from configuration details available through dictionary and config files. The tutorial explains methods (dictConfig() & fileConfig()) of module with simple examples.

Sunny Solanki  Sunny Solanki
Parallel Computing using Python

Parallel Computing using Python


Parallel Computing is a type of computation where tasks are assigned to individual processes for completion. These processes can be running on a single computer or cluster of computers. Parallel Computing makes multi-tasking super fast.

Python provides different libraries (joblib, dask, ipyparallel, etc) for performing parallel computing.

Concurrent Programming in Python

Concurrent Programming in Python


Concurrent computing is a type of computing where multiple tasks are executed concurrently. Concurrent programming is a type of programming where we divide a big task into small tasks and execute these tasks in parallel. These tasks can be executed in parallel using threads or processes.

Python provides various libraries (threading, multiprocessing, concurrent.futures, asyncio, etc) to create concurrent code.

Speed Up Python Code

Speed Up Python Code


Python is an interpreter-based language and hence is slow compared to compiler-based languages (C / C++ / Java, etc). But we can make it super fast (Almost as fast as C++).

Python has a library named 'Numba' that can help us with it. Numba is a JIT Compiler (Just-In-Time) of Python. It converts Python code to faster machine-level code using 'LLVM' compiler.

To convert python code to low-level machine code, it provides us with various decorators (@jit, @njit, @vectorize, @guvectorize, @stencil, etc.). We can decorate our Python functions using these decorators to speed up our Python functions.

Numba even let us parallelize compiled code on multiple CPUs / GPUs for even faster completion.

Working with Emails in Python

Working with Emails in Python


Python provides various libraries to work with emails. Libraries to send emails, manage mailboxes and represent emails are different based on HTTP protocol.

To send emails, Python provides a library named 'smtplib' (based on SMTP protocol).

To manage mailboxes (read emails, flag emails, move emails, create folder / directory, delete email / directory, etc), Python offers a library named 'imaplib' (based on IMAP protocol).

To represent emails, Python has a library named 'email'. To determine MIME Type of attachment file, Python offers a library named 'mimetypes'.

Profile Python Code / Script / Program

Profile Python Code / Script / Program


Profiling is the process of recording time taken by Python program / code / script / process. It measures the time complexity of a program.

Apart from time, we can also record memory usage (space complexity) by our code / program. The process of recording memory usage is referred to as 'memory profiling'. Profiling can help us make better decisions regarding resource allocation as well it presents many opportunities to optimize existing code for maximum resource utilization.

Python has many libraries (cProfile, profile, line_profiler, memory_profiler, tracemalloc, pprofile, scalene, yappi, guppy, py-spy, pyinstrument, etc.) to profile time and memory usage by our Python code.