Fading Coder

One Final Commit for the Last Sprint

Building Asynchronous Web APIs Using FastAPI

FastAPI leverages Starlette and Pydantic to deliver high-performance Web API development in Python. Its asynchronous support and automatic data validaiton make it suitable for modern microservices architectures. Environment Configuration Install the core framework using the package manager: pip inst...

Measuring Function Execution Time Using Python Decorators

Decorators provide a clean way to wrap additoinal behavior around fnuctions. The following implementation defines a measure_runtime decorator that records how long a function takes to execute, then prints the result. import time import os import requests from html import unescape def measure_runtime...

Essential Python Techniques: Aliases, Variable Swapping, and String Formatting

Configuring Python Aliases In various Linux or macOS environments, the default python command might refer to an older version. To ensure python and pip point to Python 3, aliases can be added to shell configuration files. For Bash users, append the following to ~/.bashrc: alias python='/usr/bin/pyth...

Python Syntax Basics: User Interaction and Operators

Python Syntax Basics: User Interaction and Operators
1. Program and User Interaction 1.1 What is User Interaction? User interaction refers to the process where a user inputs data into a computer, and the computer prints/outputs the results. 1.2 Why User Interaction? To enable computers to communicate with users like humans do. For example, withdrawing...

Configuring Chrome Browser Options with Selenium and Python

Background When using Selenium for browser rendering to scrape websites, the default is a clean Chrome browser. However, we often use browser extensions, proxies, or other customizations during normal browsing. Correspondingly, when scraping with Chrome, we may need to apply specific configurations...

Working with File and Directory Properties in Python

Getting File Size The os.path.getsize() function returns the size of a file in bytes: import os file_size = os.path.getsize("document.pdf") print(f"Size: {file_size} bytes") Getting Directory Size Python doesn't provide a direct method to calculate directory size. The standard ap...

Working with Excel Files in Python: A Comparative Guide to Popular Libraries

Python's ecosystem provides multiple libraries for reading, writing, and manipulating Excel files, each with distinct strengths and use cases. The most commonly used options include xlwings, openpyxl, pandas, xlsxwriter, win32com, xlutils, and DataNitro. Environment and Compatibliity Before selectin...

Loop Structures in Python

Loop Structures in Python
I. Classification of Loops while loop for-in traversal loop II. The while Loop 1. Syntax of while while condition: # loop body 2. Difference Between if and while if evaluates the condition once; if true, executes the block once. while evaluates the condition n+1 times; if true, executes the block n...

Baidu-style Pagination Implementation for Django

Create a reusable pagination helper module pagination.py: from django.utils.safestring import mark_safe class BaiduPagination: """ Baidu-style pagination generator for Django current: Current active page number total_items: Total number of records to paginate items_per_page: Number of...

Python Classes, Objects, and Special Methods

Object-Oriented Fundamentals Object-oriented programming revolves around creating blueprints called classes that define the structure and behavior of objects. A class serves as a template for instantiating individual objects, each with its own distinct state. Key components of a class definition: Co...