首页 > 解决方案 > 如何纠正 TypeError 与选择()缺少 1 个必需的位置参数:“人口”

问题描述

我希望在调用随机页面函数时显示条目列表,但我不断收到此错误选择()缺少 1 个必需的位置参数:“人口”。

标签: randomimport

解决方案


我最近因为一个错字而遇到了这个问题。

显然,您使用的是推荐的“秘密”PNG,而不是“随机”伪PNG。我有以下代码:

#!/usr/bin/python3
"""
Will get 10 random letters...
from the lowercase abcdefghijklmnopqrstuvwxyz
"""
import string
import secrets
response = secrets.SystemRandom.choices(string.ascii_lowercase, k=10)
print(response)

但是 secrets.SystemRandom 是一个类,所以我只是将其更改为 secrets.SystemRandom() 并且问题已解决。

固定代码:

#!/usr/bin/python3
"""
Will get 10 random letters...
from the lowercase abcdefghijklmnopqrstuvwxyz
"""
import string
import secrets
response = secrets.SystemRandom().choices(string.ascii_lowercase, k=10)
print(response)

推荐阅读