Tagged articles
28 articles
Page 1 of 1
Data STUDIO
Data STUDIO
Jan 21, 2026 · Fundamentals

Unlock Python’s Hidden Magic: Dunder Methods That Make Your Code Feel Native

This article introduces essential Python dunder methods such as __missing__, __fspath__, __call__, __slots__, __enter__/__exit__, __aiter__/__anext__, __getattr__/__getattribute__, explaining their problem contexts, concrete implementations, performance benefits, and best‑practice trade‑offs with clear code examples.

__call____missing____slots__
0 likes · 17 min read
Unlock Python’s Hidden Magic: Dunder Methods That Make Your Code Feel Native
Data Party THU
Data Party THU
Jan 8, 2026 · Fundamentals

Master Python Context Managers: Write Safer, Cleaner Code

Learn how Python’s context manager protocol works, explore both class‑based and generator‑based implementations, and see practical examples—from file handling and database transactions to async operations—so you can prevent resource leaks, ensure exception safety, and write more maintainable code.

AsyncException HandlingResource Management
0 likes · 11 min read
Master Python Context Managers: Write Safer, Cleaner Code
Data STUDIO
Data STUDIO
Dec 29, 2025 · Fundamentals

Why Python’s Context Manager Prevents Resource Leaks

The article explains how Python’s context manager (the with statement) provides an elegant, exception‑safe way to acquire and release resources such as files, database connections, locks, and even asynchronous handles, showing concrete code examples, custom implementations, and best‑practice guidelines.

AsyncPythonResource Management
0 likes · 12 min read
Why Python’s Context Manager Prevents Resource Leaks
Python Crawling & Data Mining
Python Crawling & Data Mining
Sep 18, 2025 · Fundamentals

Master Python’s With Statement: Build Elegant Context Managers for Safer Code

This tutorial explains why traditional try‑finally resource handling is cumbersome, introduces Python’s with statement and the underlying __enter__/__exit__ magic methods, provides practical examples such as timers, database connections, temporary directories, and shows how to simplify custom managers with contextlib while covering best practices and performance considerations.

Exception HandlingPythonResource Management
0 likes · 10 min read
Master Python’s With Statement: Build Elegant Context Managers for Safer Code
AI Large Model Application Practice
AI Large Model Application Practice
Aug 4, 2025 · Backend Development

Mastering Lifespan in FastAPI and MCP Server: Context Managers for Robust Resource Management

This article explains how to use Python's context manager protocol and FastAPI's lifespan feature to automatically initialize and clean up resources in both standard FastAPI applications and MCP Server, covering implementation methods, code examples, and differences across transport modes.

FastAPIasynccontextmanagercontext manager
0 likes · 14 min read
Mastering Lifespan in FastAPI and MCP Server: Context Managers for Robust Resource Management
Code Mala Tang
Code Mala Tang
Apr 10, 2025 · Fundamentals

Unlock Python’s Hidden Power: Mastering Context Managers for Cleaner Code

This article explains what Python context managers are, how they work under the hood, and why they are far more useful than simple file handling, providing practical examples ranging from resource management and testing to advanced asynchronous usage and common pitfalls.

PythonResource Managementbest practices
0 likes · 21 min read
Unlock Python’s Hidden Power: Mastering Context Managers for Cleaner Code
Test Development Learning Exchange
Test Development Learning Exchange
Jan 5, 2025 · Fundamentals

Understanding Python's with Statement and Context Managers with Practical Examples

This article explains Python's with statement as a context management tool, describes the required __enter__ and __exit__ methods, and provides multiple practical examples—including file handling, custom managers, multiple managers, third‑party resources, and automation scenarios—to illustrate reliable resource acquisition and cleanup.

Resource Managementcontext managerwith statement
0 likes · 8 min read
Understanding Python's with Statement and Context Managers with Practical Examples
Python Programming Learning Circle
Python Programming Learning Circle
Nov 23, 2024 · Fundamentals

Useful Python Tricks and Advanced Techniques

This article presents a collection of lesser‑known Python tricks—including string cleaning with translate, iterator slicing via itertools.islice, skipping header lines, keyword‑only functions, custom context managers, memory‑saving __slots__, resource limits, import control, and total_ordering—to help developers write cleaner, more efficient code.

Memory OptimizationPythoncontext manager
0 likes · 10 min read
Useful Python Tricks and Advanced Techniques
Test Development Learning Exchange
Test Development Learning Exchange
Oct 30, 2024 · Fundamentals

Understanding Python Magic (Dunder) Methods: Definitions, Examples, and Best Practices

This article explains Python magic (dunder) methods, their purposes, common examples such as __init__, __str__, __repr__, __len__, __getitem__, __setitem__, __delitem__, __iter__, __call__, __add__, __eq__, __hash__, and shows how to implement operator overloading, iterator and context‑manager protocols while discussing naming rules, performance, inheritance, type checking, and limitations.

Iterator ProtocolPythonSpecial Methods
0 likes · 19 min read
Understanding Python Magic (Dunder) Methods: Definitions, Examples, and Best Practices
Test Development Learning Exchange
Test Development Learning Exchange
Jun 11, 2024 · Fundamentals

Comprehensive Guide to Python Exception Handling

This article explains Python exception handling fundamentals, covering basic try‑except, multiple exception catches, else/finally blocks, custom exceptions, exception propagation, raise‑from chaining, context manager handling, assert statements, generic suppression, and selective suppression with contextlib.

AssertException Handlingcontext manager
0 likes · 4 min read
Comprehensive Guide to Python Exception Handling
Go Programming World
Go Programming World
Feb 19, 2024 · Backend Development

Implementing Context Managers in Go: Emulating Python's with Using defer and Anonymous Functions

This article explores how to replicate Python's context manager behavior in Go by examining defer's delayed execution, demonstrating its limitations in loops, and presenting three solutions—anonymous functions, a WithClose helper, and a withLock-inspired pattern—to ensure timely resource release.

GoResource ManagementWithClose
0 likes · 10 min read
Implementing Context Managers in Go: Emulating Python's with Using defer and Anonymous Functions
Test Development Learning Exchange
Test Development Learning Exchange
Jul 29, 2023 · Fundamentals

Understanding Python Context Managers: __enter__ and __exit__ Methods with Practical Examples

This article explains Python's context manager protocol, detailing the roles of __enter__() and __exit__() methods, their typical use cases, and provides ten concrete code examples ranging from file handling and database connections to custom managers for networking, temporary files, and exception handling.

Resource Managementcode-examplescontext manager
0 likes · 5 min read
Understanding Python Context Managers: __enter__ and __exit__ Methods with Practical Examples
Python Programming Learning Circle
Python Programming Learning Circle
Jun 27, 2023 · Fundamentals

Useful Python Tricks: String Cleaning, Iterator Slicing, Keyword‑Only Arguments, Context Managers, __slots__, Resource Limits, __all__, and Total Ordering

This article presents a collection of lesser‑known Python tricks—including string normalization, iterator slicing, keyword‑only functions, custom context managers, memory‑saving __slots__, CPU/memory limits, import control with __all__, and simplified ordering with total_ordering—to help developers write cleaner and more efficient code.

IteratorMemory OptimizationPython
0 likes · 10 min read
Useful Python Tricks: String Cleaning, Iterator Slicing, Keyword‑Only Arguments, Context Managers, __slots__, Resource Limits, __all__, and Total Ordering
Python Programming Learning Circle
Python Programming Learning Circle
Apr 7, 2023 · Fundamentals

Lesser‑Known Python Tricks and Techniques

This article introduces a collection of lesser‑known Python tricks—including string cleaning with translate, iterator slicing via itertools, skipping header lines, keyword‑only functions, custom context managers, memory‑saving __slots__, resource limits, import control with __all__, and total_ordering—to help developers write cleaner, more efficient code.

Memory Optimizationcode snippetscontext manager
0 likes · 10 min read
Lesser‑Known Python Tricks and Techniques
MaGe Linux Operations
MaGe Linux Operations
May 5, 2022 · Fundamentals

Master Python’s with Statement: Simplify Resource Management

This article explains the purpose and mechanics of Python's with statement, showing how it leverages context managers to replace verbose try‑finally blocks, and demonstrates both class‑based and decorator‑based implementations with clear code examples.

Code ExampleDecoratorPython
0 likes · 6 min read
Master Python’s with Statement: Simplify Resource Management
Python Programming Learning Circle
Python Programming Learning Circle
Oct 13, 2021 · Fundamentals

New Features in Python 3.10: Union Types, zip strict mode, parenthesized context managers, explicit type aliases, match‑case, improved error messages and other updates

Python 3.10, released on October 4 2021, introduces concise Union type syntax, a strict mode for zip, parenthesized with‑statements, explicit TypeAlias declarations, structural pattern matching via match‑case, clearer syntax error messages, and several deprecations such as distutils, all illustrated with code examples.

3.10PythonUnion Types
0 likes · 8 min read
New Features in Python 3.10: Union Types, zip strict mode, parenthesized context managers, explicit type aliases, match‑case, improved error messages and other updates
Python Programming Learning Circle
Python Programming Learning Circle
Jun 9, 2021 · Fundamentals

Python Tips: String Manipulation, Iterator Slicing, Context Managers, Slots, Resource Limits, and More

This article presents a collection of practical Python techniques—including string cleaning with translation tables, iterator slicing with itertools, skipping file headers, keyword‑only arguments, custom context‑manager objects, memory‑saving __slots__, CPU and memory resource limits, export control via __all__, and simplified total ordering—illustrated with concise code examples.

IteratorPythonString Manipulation
0 likes · 9 min read
Python Tips: String Manipulation, Iterator Slicing, Context Managers, Slots, Resource Limits, and More
Python Programming Learning Circle
Python Programming Learning Circle
Mar 29, 2021 · Fundamentals

Understanding Python Context Managers: Basics, Custom Implementations, and Advanced Applications

This article explains Python's context manager mechanism, covering the basic with statement, custom __enter__/__exit__ classes, the contextlib.contextmanager decorator, nesting, combining multiple managers with ExitStack, and practical applications such as SQLAlchemy session handling, exception management, and persistent HTTP requests.

DecoratorPythonResource Management
0 likes · 6 min read
Understanding Python Context Managers: Basics, Custom Implementations, and Advanced Applications
MaGe Linux Operations
MaGe Linux Operations
Aug 30, 2020 · Fundamentals

Unlock Hidden Python Tricks: From String Cleanup to Memory Limits

Explore a collection of lesser‑known Python tricks—including string sanitization, iterator slicing, context‑manager shortcuts, memory‑saving slots, resource limits, controlled imports, and simplified ordering—each illustrated with concise code examples to help you write cleaner, more efficient programs.

IteratorMemory OptimizationString Manipulation
0 likes · 10 min read
Unlock Hidden Python Tricks: From String Cleanup to Memory Limits
Python Programming Learning Circle
Python Programming Learning Circle
Mar 21, 2020 · Fundamentals

Python Fundamentals: Standard Libraries, Data Types, Context Managers, and Common Practices

This article presents a comprehensive Python fundamentals guide covering common standard libraries, built‑in data types, the with statement, mutable vs immutable types, date handling, word counting, file deletion, custom exceptions, error handling, bug‑fix strategies, and key language feature differences between Python 2 and 3.

Data TypesException HandlingPython2 vs Python3
0 likes · 15 min read
Python Fundamentals: Standard Libraries, Data Types, Context Managers, and Common Practices
Qunar Tech Salon
Qunar Tech Salon
Jun 11, 2019 · Fundamentals

Understanding Python __init__ and __del__ Methods: Constructors, Destructors, and Resource Management

This article explains how Python uses the special __init__ and __del__ methods to emulate constructors and destructors, discusses the language's reference‑counting garbage collector, demonstrates common pitfalls with __del__, and presents safer alternatives such as context managers and weak references for resource cleanup.

PythonResource Managementcontext manager
0 likes · 7 min read
Understanding Python __init__ and __del__ Methods: Constructors, Destructors, and Resource Management
MaGe Linux Operations
MaGe Linux Operations
Jan 7, 2018 · Backend Development

Why Your Python with‑Statement Fails: Debugging Global Process Locks

The article examines a flawed implementation of a global process lock using Python's with statement, explains why exceptions raised in __enter__ are not caught by __exit__, demonstrates failing unit tests, and presents three alternative solutions—including a custom ABContext, use of the deprecated contextlib.nested, and a simple if‑statement workaround—to correctly manage exceptions in context managers.

Exception HandlingPythoncontext manager
0 likes · 6 min read
Why Your Python with‑Statement Fails: Debugging Global Process Locks