Is there a way to get the doc string of a python file if I only have the file name? For example, I have a python file called a.py. I know that it has a document line (which was previously set), but does not know its internal structure if it has any classes or main, etc.? I hope I do not forget something pretty obvious. If I know that I have a main function, I can do this using import
filename = 'a.py' foo = __import__(filename) filedescription = inspect.getdoc(foo.main())
I canβt just like that:
filename.__doc__ #it does not work
source share