displaying python's autodoc to the user (python 3.3)
Posted
by
Plotinus
on Programmers
See other posts from Programmers
or by Plotinus
Published on 2013-07-03T16:26:11Z
Indexed on
2013/07/03
17:17 UTC
Read the original article
Hit count: 1178
I'm writing a simple command line math game, and I'm using python's autodoc for my math algorithms to help me remember, for example, what a proth number is while i'm writing the algorithm, but later on I'll want to tell that information to the user as well, so they'll know what the answer was. So, for example I have:
def is_proth():
"""Proth numbers and numbers that fit the formula k×2^n + 1, where k are odd positive
integers, and 2^n > k."""
[snip]
return proths
and then I tried to make a dictionary, like so:
definitions = {"proths" : help(is_proth)}
But it doesn't work. It prints this when I start the program, one for each item in the dictionary, and then it errors out on one of them that returns a set. And anyway, I don't want it displayed to the user until after they've played the game.
Help on function is_proth in module __main__:
is_proth()
Proth numbers and numbers that fit the formula k×2^n + 1, where k are odd positive
integers, and 2^n > k.
(END)
I understand the purpose of autodoc is more for helping programmers who are calling a function than for generating userdoc, but it seems inefficient to have to type out the definition of what a proth number is twice, once in a comment to help me remember what an algorithm does and then once to tell the user the answer to the game they were playing after they've won or lost.
© Programmers or respective owner