在 self.__init__() 方法中使用 getpass() 失败,但在功能上使用时工作正常。为什么是这样?

Using getpass() fails in the self.__init__() method but works fine when used functionally. Why is this?

我不知道我做错了什么。如果这个 class 被实例化并且没有用户已经被腌制,我想设置一个新用户。我的 __init__ 方法目前看起来像这样:

class User:
    def __init__(self, *args, **kwargs):
        if os.path.isfile(f"{get_cwd()}/user.pickle"):
            self.load_user()
        else:
            self.email_address = input("What's your email address?: ")
            self.email_password = base64.b64encode(getpass("What's your email password?: ").encode("utf-8"))
            self.save_user()

但是,当我实例化 class 时,它并没有通过请求 self.email_address。如果我将 self.email_password 更改为一个简单的输入函数,它就可以工作。我在这里使用 getpass() 做错了什么?

我尝试创建一个单独的函数来接收/编码密码变量并从 __init__ 方法中调用它,但它做同样的事情。

如果我让整个脚本正常运行(但它有点长!)

为什么我在使用 getpass 和基于 class 的方法时遇到问题?

编辑:试图通过PyCharm终端运行,以上内容或多或少是不相关的。

感谢@Alex Hall 提醒我 getpass 无法通过 PyCharm 终端运行。在普通终端中工作得很好。