Skip to content

Instantly share code, notes, and snippets.

@Searge
Last active April 22, 2021 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Searge/8f755cac200594421d3053e92bda4a0e to your computer and use it in GitHub Desktop.
Save Searge/8f755cac200594421d3053e92bda4a0e to your computer and use it in GitHub Desktop.
Save the output of Python's built-in help() function/module to file.
#!/usr/bin/env python3
# Write The Fucking Manual function
# exports the output of Python's built-in `help()` function to file
# No Copyright
# ------------
# This work has been identified as being free of known restrictions
# under copyright law, including all related and neighboring rights.
# https://creativecommons.org/publicdomain/mark/1.0/
import importlib
import pydoc
def wtfm(func: str) -> str:
""" Renders `help()` output to file.
"""
with open(f"{func}.txt", "w") as f:
txt = pydoc.render_doc(func, renderer=pydoc.plaintext)
f.writelines(txt)
def builtin_check() -> None:
"""Buil-in checker
Checking if `import {module}` is needed
and writing a manual to the file then
"""
yes: set[str] = {'yes', 'y', 'ye', ''}
is_not: set[str] = {'no', 'n'}
choice = input(
'Is it built-in function?\nYes/No. Default [y]: '
).lower()
if choice in yes:
wtfm(input('Write you function: '))
elif choice in is_not:
module: str = input('Write you module: ')
importlib.import_module(module)
wtfm(module)
else:
print("Please respond with 'yes' or 'no'")
__date__ = '2021/04/21'
__deprecated__ = False
__license__ = 'Public Domain Mark 1.0'
if __name__ == '__main__':
builtin_check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment