This project demonstrates the use of decorators in Python, as well as basic object-oriented programming concepts. Below is a summary of the key concepts and components you have learned and implemented in this project.
The project consists of the following files:
main.py
: The main entry point of the application.student.py
: Defines theStudent
class.teacher.py
: Defines theTeacher
class.person.py
: Defines thePerson
class, which is the base class forStudent
andTeacher
.logging_decorator.py
: Contains thelogging_decorator
function.double_decorator.py
: Contains thedouble_decorator
function.string_check_decorator.py
: Contains thestring_check_decorator
function..gitignore
: Specifies files and directories to be ignored by Git.
Decorators are a powerful feature in Python that allow you to modify the behavior of a function or method. In this project, you have implemented and used the following decorators:
-
Logging Decorator (
logging_decorator
):- Logs the function name and its arguments when the function is called.
- Defined in
logging_decorator.py
.
-
Double Decorator (
double_decorator
):- Calls the decorated function twice.
- Defined in
double_decorator.py
.
-
String Check Decorator (
string_check_decorator
):- Checks if all arguments passed to the function are strings and prints a message if they are not.
- Defined in
string_check_decorator.py
.
You have also implemented basic object-oriented programming concepts by defining classes and inheritance:
-
Person Class (
Person
):- Base class with attributes
first_name
,last_name
, andage
. - Defined in
person.py
.
- Base class with attributes
-
Student Class (
Student
):- Inherits from
Person
and addsstudent_id
andgrade
attributes. - Defined in
student.py
.
- Inherits from
-
Teacher Class (
Teacher
):- Inherits from
Person
and addsteacher_id
attribute. - Includes a method to grade a student.
- Defined in
teacher.py
.
- Inherits from
The main function in main.py
demonstrates the usage of the classes and decorators:
- Creates instances of
Student
andTeacher
. - Grades the student using the
Teacher
class. - Prints the student's details.
- Calls the
print_hello_world
function, which is decorated to print "Hello World!" twice and log the call. - Calls the
add
function, which is decorated to check if arguments are strings and log the call.
To run the project, execute the main.py
file:
python main.py
This will demonstrate the functionality of the decorators and the object-oriented classes you have implemented.