I have a general format of docstrings that I try to follow when I make functions. I give a summary of what the function does followed by a brief explanation of what class it takes for input and what class it outputs.
def cuberoot4u(number):
"""Returns the cube root of number.
cuberoot4u(float) -> float
"""
return pow(number, 1/3)
So in this case, cuberoot4u takes a float for an input and returns a float for output.
How could I best convey to the user with docstrings what class of input a function requires if it takes a .txt file as an input and outputs the content in a string?
def getText(filename):
"""Reads the file filename and returns the content.
getText(?????) -> str
"""
fd = open(filename)
text = fd.read()
fd.close()
return text
Would it be best to say getText(filename.txt) -> str or is there a specific class name for that much like string is 'str' and an integer is 'int'?
Also, what about for functions whose outputs are not clearly defined like this example:
def commandmenu():
"""Begin some random menu which does stuff.
commandmenu() -> ??????
"""
while 1:
someuserinput = input("Enter a command: ")
if someuserinput == 'this':
pass
elif someuserinput == 'that':
pass
else:
print('u suck')
return None
So in this case, there is no initial output from entering the function as it leads to an input from the user before it does something. What would best fit in ????? if such a function becomes more and more meticulous like this and may lead to multiple different outputs depending on prompts to the user etc.?