I have a class 'Model' in a.py, Now the class has moved to b.py. So whenever end user use from a import Model, I wanted to through an deprecation or some warning message. Any idea how to do that?
Asked
Active
Viewed 75 times
2 Answers
1
you should use warning (https://docs.python.org/3/library/warnings.html) and more specially DeprecationWarning (https://docs.python.org/3/library/exceptions.html#DeprecationWarning)
a good answer already exist here : How to warn about class (name) deprecation

DonKnacki
- 427
- 4
- 11
-
Thanks for your answer. What if I have set of classes moved? Do I need to create all methods? – Kavya Gunthoju Jun 04 '21 at 13:07
0
I came up with this simple solution :
class Model:
def __init__(self):
# prints a warning message in the console
print('The "Model" class has been moved to b.py, please consider modifying your code !')
m = Model() # instantiate the model class to throw the message
This should work like you expected it Edit: this is the code for a.py

S-c-r-a-t-c-h-y
- 321
- 2
- 5