CoderzColumn : Python Tutorials (Page: 3)

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, threadpool, processpool
concurrent.futures: High-Level Multithreading and Multiprocessing API in Python
Python

concurrent.futures: High-Level Multithreading and Multiprocessing API in Python

A comprehensive guide on how to use Python module "concurrent.futures" for multitasking (Multithreading & Multiprocessing). The "concurrent.futures" module provides a very high-level API that let us create a pool of workers (threads/processes) to which we can submit tasks for completion. It'll take care of handling resources and we don't need to do much low-level coding that we have to do if we use "threading" or "multiprocessing" modules.

Sunny Solanki  Sunny Solanki
Tags ipywidgets, notebook
ipywidgets  - An In-depth Guide to Interactive Widgets in Jupyter Notebook [Python]
Python

ipywidgets - An In-depth Guide to Interactive Widgets in Jupyter Notebook [Python]

A detailed guide on how to use Python library ipywidgets that let us create widgets (dropdown, radio buttons, checkboxes, buttons, etc) in Jupyter notebooks. These widgets let us add interactivity to our notebooks. It can be linked to various data viz libraries to make charts interactive like dashboards and web apps.

Sunny Solanki  Sunny Solanki
Tags beautifulsoup, scraping, htmlparsing, xmlparsing
beautifulsoup - Scrape,Parse & Analyze Web Pages in Python
Python

beautifulsoup - Scrape,Parse & Analyze Web Pages in Python

The tutorial covers in detail how we can parse HTML pages using BeautifulSoup and retrieve information from the parsed pages. We explain things like accessing individual tags, accessing attribute details, accessing text of tags, searching for tags, accessing children/parent of tags, etc.

Sunny Solanki  Sunny Solanki
Tags beautifulsoup, modify-html-doc
Beautifulsoup: Guide To Modify HTML
Python

Beautifulsoup: Guide To Modify HTML

This tutorial primarily concentrates on how we can modify the contents of the parsed HTML document by BeautifulSoup. We have explained various modifications like rename tag, Add new tag, modify/add attributes, wrap tag inside of another tag, etc.

Sunny Solanki  Sunny Solanki
Tags numba, stencil-kernel
Numba @stencil Decorator: Guide to Improve Performance of Code involving Stencil Kernels
Python

Numba @stencil Decorator: Guide to Improve Performance of Code involving Stencil Kernels

The tutorial covers how to design stencil kernel functions using Numba @stencil decorator. Stencil kernels are functions where each element of the input array is updated according to a specified pattern.

Sunny Solanki  Sunny Solanki
Tags numba, guvectorize-decorator
Numba @guvectorize Decorator: Generalized Universal Functions
Python

Numba @guvectorize Decorator: Generalized Universal Functions

Numba @guvectorize decorator let us create ufuncs (Universal Functions) which works on arrays of different shapes and returns result which can be of different shape than input. It's designed to speed up operations on arrays of differing shapes.

Sunny Solanki  Sunny Solanki
Tags pandas-dataframe, multiindex, hierarchical-index
Simple Guide to Understand Pandas Multi-Level / Hierarchical Index
Python

Simple Guide to Understand Pandas Multi-Level / Hierarchical Index

Tutorial covers detailed guide on how to create and work with Multi-level as well as hierachical index for Pandas Dataframe. It also covers various ways to index dataframe which has multi-level indexing for rows ad columns.

Sunny Solanki  Sunny Solanki
Tags python, optimisation
numba - Make Your Python Functions Run Faster Like C/C++
Python

numba - Make Your Python Functions Run Faster Like C/C++

Tutorial provides detailed guide to use Numba @jit decorator. It explains various ways to use @jit decorator and all the possible parameters of it to speed up Python code.

Sunny Solanki  Sunny Solanki
Tags xarray-dataset
xarray.Dataset: Multi-Dimensional Labelled Arrays
Python

xarray.Dataset: Multi-Dimensional Labelled Arrays

xarray (Dataset) : Multi-Dimensional Labelled Arrays

Sunny Solanki  Sunny Solanki
Tags pandas-dataframe, python-expressions, query-funct…
Pandas query(): Query Pandas DataFrame using Python Expressions
Python

Pandas query(): Query Pandas DataFrame using Python Expressions

Pandas query(): Query Pandas DataFrame using Python Expressions

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.