python - “UnboundLocalError:分配前引用的局部变量'输入'”几乎适用于我的代码中的每个输入
问题描述
x = int(0)
ans1 = int(0)
ans = int(0)
with open('risk_q.txt') as r:
for x in range(12):
mylist = [line.rstrip('\n') for line in r]
ans1 = int(input()) #Error occurs in this line
此错误发生在代码前面的不同输入中,因此我在函数之前获取输入,然后通过函数的参数将其传递。
解决方案
检查您的代码。看起来好像您已用作input
变量名,因此覆盖了内置函数。
推荐阅读
- c - 在 C 中的 pthread 之间共享数据
- python - 如何将 pandas 数据框插入现有的 postgres sql 数据库?
- swift - 将变量添加到已保存的用户默认变量
- python - 如何将列与熊猫连接?
- javascript - 我怎么能以这种方式格式化这些数据?
- python - 如何在一个 PDF 中保存多个熊猫图
- asp.net-core - ASP.NET Core 3.1 的自定义身份验证处理程序授权失败?
- python - Twint Python 库导致搜索查询异常
- python - 多个文件到单个文件的符号链接
- c++ - 当 bWaitAll = true 时 WaitForMultipleObjects 和 2 个事件