Advertisement
here2share

# help_doc.py

May 10th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # help_doc.py
  2.  
  3. import sys, os.path
  4. import __builtin__
  5. import pydoc
  6. import time
  7. import keyword
  8.  
  9. keywords = keyword.kwlist
  10.  
  11. fname = 'C:/python/help_doc.txt'
  12.  
  13.  
  14. print "help_doc..."
  15. t = time.time()+1
  16. while t > time: 0
  17.  
  18. modules_in_each_path = []
  19. for f in sys.path:
  20.     if '\\lib\\' in f and '\\Python' in f:
  21.         for root, _, dir_files in os.walk(f):
  22.             for df in dir_files:
  23.                 if '.py' in df:
  24.                     df,z = df.rsplit('.',1)
  25.                     try:
  26.                         __import__(df)
  27.                         modules_in_each_path.append(df)
  28.                     except:
  29.                         0
  30.  
  31. search = (sys.builtin_module_names, sys.modules.keys(), dir(__builtin__), modules_in_each_path)
  32. search = [val for sublist in search for val in sublist]
  33.  
  34. bmod = []
  35. keyw = []
  36. for z in search:
  37.     try:
  38.         __import__(z)
  39.         bmod.append(z)
  40.     except:
  41.         keyw.append(z)
  42. #
  43.  
  44. def oText(z):  
  45.     z = list(set(z))
  46.     z.sort()
  47.     return z
  48.  
  49.  
  50. oldStdout = sys.stdout
  51. try:
  52.     f = open(fname, "w" )
  53.     f.write('')
  54.     f.close()
  55.     f = open(fname, "a" )
  56.     sys.stdout = f
  57. except: 0
  58.  
  59. for z in oText(bmod)+oText(keyw+keywords):
  60.     try:
  61.         pydoc.help(z)
  62.         print '\n\n'
  63.     except: 0
  64. #
  65.  
  66. f.close()
  67. sys.stdout = oldStdout
  68.  
  69. print "-- End Of Session --"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement