Enhanced Error Message Decoder for Python
Project description
TEMD: Error Message Decoder for Python
TEMD is a Python library designed to help beginner Python programmers understand and resolve errors in their code. It provides detailed, user-friendly explanations for common Python errors, making it easier for learners to debug their programs and improve their coding skills. The project leverages machine learning models to interpret and explain error messages, supporting both automatic and wrapped error detection modes.
Requirements
- Python 3.x
joblibrequestsscikit-learn
Installation
You can install TEMD directly from PyPI:
pip install TEMD
How to Use
1. Initialize TEMD for Global Error Handling
To set up global error handling, import the TEMD class and call the init method. This will catch and explain errors automatically.
from TEMD.temd import TEMD
# Initialize TEMD for global error handling
temd = TEMD()
temd.init() # This sets up the global error handler
print("Global error handling active!")
2. Example of Automatic Error Handling
Once initialized, TEMD will automatically catch and explain errors that occur during the execution of the program.
# Example of automatic error handling
my_list = [1, 2, 3]
print(my_list[5]) # This will raise an IndexError and TEMD will handle it
3. Example of Wrapped Error Handling
You can also wrap specific blocks of code to focus error detection and explanation on those sections.
user_code = """
def forloop():
my_list = [1, 2, 3]
for i in range(5):
print(my_list[i]) # This will raise an IndexError when i >= 3
forloop()
"""
# Use wrap to execute the code inside a focused error handling scope
temd.wrap(user_code) # This will catch errors in the wrapped block and explain them
Logic and Functionality
Data Collection
A dataset of Python errors was collected from various sources, including common error messages encountered by beginners. The dataset includes both AST (Abstract Syntax Tree) errors and runtime errors.
Model Training
Machine learning models were trained using the collected dataset. The models include an AST error model and a runtime error model. These models were trained to recognize and interpret various Python error messages.
Library Development
A Python library was developed to encapsulate the trained models and provide an interface for error interpretation. The library includes functionality for both automatic error handling and error handling within wrapped code blocks.
Integration and Testing
The library was integrated into Python projects to test its effectiveness in real-world scenarios. Various test cases were designed to ensure the library provides accurate and helpful error explanations.
Documentation and Deployment
Comprehensive documentation was created to assist users in integrating and using the TEMD library. The library was packaged and deployed to PyPI (Python Package Index) for easy installation and use.
How to Train Models
-
Train the Runtime Error Model
Run the following script to train the runtime error model:
python train_runtime_error_model.py -
Train the AST Error Model
Run the following script to train the AST error model:
python train_ast_error_model.py
How to Run the Main Program
Run the main_program.py to trigger and handle errors, and view the error explanations provided by the models:
python main_program.py
Example Usage
from TEMD.temd import TEMD
# Initialize TEMD for global error handling
temd = TEMD()
temd.init() # This sets up the global error handler
print("Global error handling active!")
# Example of automatic error handling
my_list = [1, 2, 3]
print(my_list[5]) # This will raise an IndexError and TEMD will handle it
# Example function that will trigger an IndexError
def forloop():
my_list = [1, 2, 3]
for i in range(5):
print(my_list[i])
# Calling the function will automatically trigger TEMD's global error handler
forloop() # This should trigger an IndexError, and TEMD will explain it
# Focused Error Handling with wrap() (Only this block of code will be monitored)
user_code = """
def forloop():
my_list = [1, 2, 3]
for i in range(5):
print(my_list[i])
forloop()
"""
temd.wrap(user_code) # This will catch errors in the wrapped block and explain them
Authors
- Aditya Khair - Initial work - adityakhair45@gmail.com
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to the EMD Team and all contributors for their support and guidance.
- Special thanks to Asst. Prof. [Guide Name] and Prof. Manish Agrawal for their invaluable guidance throughout the project.
This README file provides a comprehensive overview of the TEMD project, including installation instructions, usage examples, and the underlying logic and functionality. You can use this as a template for your project's documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file temd-0.1.1.tar.gz.
File metadata
- Download URL: temd-0.1.1.tar.gz
- Upload date:
- Size: 94.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
297b5a2e2ba8475563385de06ac5350a5192217cdda365283dcc46c664907fa6
|
|
| MD5 |
ddfa5501704b956e5dc7e4e8ed2291e8
|
|
| BLAKE2b-256 |
25145ab8f26c34d9fe7cb1145152ac8a175c594ab047fbfd3072563ec4011de2
|
File details
Details for the file TEMD-0.1.1-py3-none-any.whl.
File metadata
- Download URL: TEMD-0.1.1-py3-none-any.whl
- Upload date:
- Size: 98.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca73810127d02645ed5cf3eac5b1b1b17e6677b2b4d4496f4fb7981bd0627f97
|
|
| MD5 |
8a6757fcbf9f5c7c8bf94c96697797dc
|
|
| BLAKE2b-256 |
7bf0689b8c3921e25ab388932170cb9f82804177329167ae4ff50784abcdc8ea
|