Skip to content

AlirezaRahi/Python-Decorator-and-Context-Manager-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Python Decorator + Context Manager Example

This is a small educational project demonstrating:

  • How to use a context manager for resource management (database connection).
  • How to use a decorator to log query execution time.

Features

  • Clean and reusable code
  • Simulates connecting to and disconnecting from a database
  • Logs query execution time

Requirements

No external dependencies. Works with Python 3.x.

Usage

python main.py

## Example Output
Connecting to database...
Executing query: fetch_users
Fetching users from DB Connection Object
Query executed in 2.0005 seconds
['User1', 'User2', 'User3']
Closing database connection...

About

A simple Python example demonstrating the use of decorators and context managers for clean and reusable code.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages