list_for_help = list()
list_for_help.append("PyQt5.QtCore")
list_for_help.append("PyQt5.QtCore.QTime")
list_for_help.append("PyQt5.QtGui")
list_for_help.append("PyQt5.QtGui.QColor")
list_for_help.append("PyQt5.QtWidget")
list_for_help.append("PyQt5.QtWidget.QLabel")
list_for_help.append("PyQt5.QtWidget.QWidget")
# 将标准输出内容送到文件中
out_tmp = sys.stdout
sys.stdout = open('help.rpt', 'w')
for s_item in list_for_help:
list_item = _s_item.split('.')
if len(list_item)==1:
a = list_item[-1]
print(f'help({a})')
# 由于import目标是变量, 所以需要在exec中运行, 直接import {a}会报错
exec(f'import {a}; help({a})')
else:
a = list_item[-1] ; # 最后一个元素
b = '.'.join(list_item[0:-1]); # 不包含最后一个元素
print(f'help({b})')
# 由于import目标是变量, 所以需要在exec中运行, 直接from {b} import {a}会报错
exec(f'from {b} import {a}; help({a})')
sys.stdout.close()
sys.stdout = out_tmp