Python 我不知道';我不知道为什么var=int(input())是错误的

Python 我不知道';我不知道为什么var=int(input())是错误的,python,python-3.x,Python,Python 3.x,我不知道为什么int(input())会出错 只是我点击了执行按钮,但它显示了我的错误 我不能输入任何字符串或int 我的代码是: import sys input = sys.stdin.readline def process_queue(queue_list, f_idx, r_idx, command): cmd = command[0] if cmd == "push": queue_list[r_idx] = command[1]

我不知道为什么
int(input())
会出错

只是我点击了执行按钮,但它显示了我的错误

我不能输入任何字符串或int

我的代码是:

import sys
input = sys.stdin.readline

def process_queue(queue_list, f_idx, r_idx, command):
   cmd = command[0]
   if cmd == "push":
        queue_list[r_idx] = command[1]
        r_idx += 1
   elif cmd == "pop":
        if f_idx == r_idx:
            print(-1)
        else:
            print(queue_list[f_idx])
            f_idx += 1
   elif cmd == "size":
        print(r_idx-f_idx)
   elif cmd == "empty":
        print(int(r_idx == f_idx))
   elif cmd == "front":
        if f_idx == r_idx:
            print(-1)
        else:
            print(queue_list[f_idx])
   elif cmd == "back":
        if f_idx == r_idx:
            print(-1)
        else:
            print(queue_list[r_idx-1])

    return [f_idx, r_idx]

n = int(input())
queue_list = [0 for _ in range(n)]
f_idx = 0
r_idx = 0

for _ in range(n):
    command = input().split()
    f_idx, r_idx = process_queue(queue_list, f_idx, r_idx, command)

这就是问题的根源:

import sys
input = sys.stdin.readline
您基本上是在更改标签输入,以便它引用sys.stdin.readline。阅读

不过,查看错误消息会有所帮助。

Input()
输入接受用户的输入,但不读取转义字符。
它有一个提示,表示用户输入之前的默认值

sys.stdin.readline()
readline()还接收用户的输入,但也读取转义字符


实际上,您正在尝试使用input(),但您将input命名为sys.stdin.readline(),这就是问题所在。

在第二行,您将input设置为变量。所以你覆盖了“输入”的功能。这意味着当你用input()调用它时,它不存在。@Rashid'Lee'Ibrahim虽然不清楚为什么要使用它,但是
readline
的工作原理应该差不多。。。OP说他甚至不能输入输入。看到完整的错误会很有帮助……当我复制粘贴并运行代码时,我在
返回[f_idx,r_idx]
行上得到一个
缩进错误。我认为这个错误很明显,如果你真的把它贴出来会有帮助的…@Tomerikoo我不知道这是否是他的复制粘贴错误,但返回的空间比应该的多了一个。@Tomerikoo也在修复了那一个空间之后。如果注释掉
input=sys.stdin.readline
,脚本将正常工作。但是如果你把它放在那里,它不会接受输入。不,它不是。。。正如OP所说,错误甚至在提示输入之前就出现了。。。这似乎是一个缩进错误(假设代码被正确复制并且不是打字错误),非常感谢。我想你的评论和上面的评论很相似,对吧?祝你有一天愉快Tomerikoo,我用一些答案完成了这段代码。当我写这个问题的时候,我错了携带我的代码。也谢谢你!顺便说一句,我的英语水平很低。。。。如果您不知道我在说什么,请再次评论。您基本上是在更改标签输入,使其指向sys.stdin.readline-为什么会有问题?哦,谢谢!我知道问题出在哪里。祝您有个美好的一天!