I have a requirement where, I have to iterate over a directory, and for every python file in that directory, I have to print its documentation..
Now, one problem I am facing in this is: - "To get the module object from the module name, so that I can USE __doc__ attribute printed"
The code I have written so far is: -
This is my main chunk of code..
Every time I print the "doc", the documentation of string module gets printed..
What I can I change in this??
As in the above code: - I have tried to use (sys.modules[modulename] ) also..
But, it is working for some module, and not for other...
E.g:- sys.modules['abc'] is working fine., but sys.modules['aifc'] is not working..
I'm trying to print doc for all the python files under Python Standard Lib directory.
As you know, I'm new to Python, but maybe the reason you keep getting the doc-string for the string class is because you are calling __doc__ on a string (the name)?
Not sure if I understand what you're doing, but you can use __import__ and getattr to get a handle on a module or class so you can call __doc__ on the module/class e.g. to get the doc-string for the os module and the os.path class (on Python 3):