-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpy.py
executable file
·60 lines (51 loc) · 1.33 KB
/
helpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""Qickly get help on Python objects from command line"""
# =========
# MODULES
# =========
import os # OS interface: os.getcwd(), os.chdir('dir'), os.system('mkdir dir')
import sys # System-specific functions: sys.argv(), sys.exit(), sys.stderr.write()
import importlib # Simplifies module importing
import argparse # commandline argument parsers
# ==============
# PROGRAM DATA
# ==============
PROGNAME = os.path.basename(sys.argv[0])
# =================
# PARSING OPTIONS
# =================
def parseopt():
# CREATE PARSER
parser = argparse.ArgumentParser(prog=PROGNAME, description="Command-line option parser")
# MANDATORY ARGUMENTS
parser.add_argument(
"obj",
help="""\
Object to seek help about specified simply as obj
or more completely like module.class.method""",
)
# OPTION PARSING
opts = parser.parse_args()
# OPTION CHECKING
return opts
# ==============
# MAIN PROGRAM
# ==============
def main():
# PARSE OPTIONS
opts = parseopt()
help_this = opts.obj
try:
# POSSIBLY IMPORT MODULE
modulo = help_this.split(".")[0]
importlib.import_module(modulo)
except Exception:
pass
finally:
help(help_this)
sys.exit()
# ===========
# MAIN CALL
# ===========
if __name__ == "__main__":
main()