I'm writing a click command that accepts an argument of both int
and str
types, and I need to figure out the passed argument type within the function as in this example:
import click
@click.command()
@click.argument('num')
def command(num):
if type(num) is int:
click.echo("integer")
elif type(num) is str:
click.echo("string")
if __name__ == '__main__':
command()
This example doesn't work, because the argument type is always unicode.
$ python script.py text
<type 'unicode'>
$ python script.py 123
<type 'unicode'>
I'm looking for a way to make executing this command return this:
$ python script.py text
<type 'str'>
$ python script.py 123
<type 'int'>