def integer(arg):
"""Attempts to return the arg converted to `int`.
Returns nearest whole number if arg represents a `float`.
Mainly to be used as typehint in commands.
"""
try:
int(arg)
except ValueError:
pass
else:
return int(arg)
try:
float(arg)
except ValueError:
pass
else:
return int(round(float(arg)))
raise BadArgument('Converting to "int" failed.')
评论列表
文章目录