I have a problem…which I solved…but do not understand why the solution is that way. And I seek illumination…
I have multiple .py files. One file imports the classes of the other. The main file (which imports the classes in the other .py file) also has this…
from textwrap import dedent
And I used dedent in the main .py file and it worked. But then I found that I needed to use it in one of the functions of the classes the main file imports. Whenever I ran the program and the code got to that function in the imported class that had dedent in it I got this error:
NameError: name 'dedent' is not defined
I solved the problem by adding another “from textwrap import dedent” statement into the .py file that had the classes that get imported by the main file.
And that’s what bugs me. I would have thought that the original dedent import line in the main file would have also covered any imported classes that used dedent. But it appears not to. Can someone explain. Does this mean I need to start copying any other import commands into the other .py file(s) just to cover my bases?