Python click 模块,INT 实例源码
我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用click.INT。
def tokens2counts(sep, limit, tokens):
'''Count unique tokens in a list of tokens.
Tokens are sorted by top counts.'''
content = read_tokens(tokens)
counts = sort_counts(get_counts(content))
# we want the argument type to be an INT - but python only
# has support for a float infinity. So if it the limit is negative,
# it becomes infinite
if limit < 0:
limit = float('inf')
# using csv writer to ensure proper encoding of the seperator.
rows = [list(map(str, vals)) for ind, vals in enumerate(counts) if ind < limit]
write_csv(rows, str(sep))
def job_option(f):
return click.option(
'--jobid', '-j', default=None,
type=click.INT, help='The job ID'
)(f)
def user_credentials(f):
out = click.argument("uid", type=click.INT
)(f)
return out
def test_int_type(self):
class Option(IntegerOption):
Metadata = 'name'
cli = ['--name']
click_option = ClickObjectOption(Option)
self.assertEqual(click_option.type, click.INT)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。