Display details of importer

0 votes
In Django I have a package that issues a deprecation warning. sHow to make sure that the warning described where the import was being made from, so the coder can go in and change the file without having to step through code to find it?

So the general case is

#file1.py
import file2.py

#file2.py
import warnings
warnings.warn(
'Package deprecated: imported from %s' % __importer__,
DeprecationWarning
)
 

Where __importer__ is an imaginary attribute containing "file1.py", or some such reference.

Can anyone help me with this?
Mar 15, 2019 in Python by ana1504.k
• 7,890 points
34 views

1 answer to this question.

0 votes
Yes, you can perform the same by using the stacklevel argument to warnings.warn

I hope this helps!
answered Mar 15, 2019 by SDeb
• 13,230 points

Related Questions In Python

+1 vote
2 answers
0 votes
1 answer
0 votes
0 answers

Excel .json Import Error: The Type of Current Preview Value is Too Complex to Display

Main Problem: I'm trying to import .json to excel ...READ MORE

Mar 14 in Python by Tarık
• 120 points
269 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
2,053 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 756 views
0 votes
0 answers
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 13,230 points
565 views
0 votes
1 answer

Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

answered Sep 21, 2018 in Python by SDeb
• 13,230 points
105 views