似乎有两种不同的方法将字符串转换为字节,如TypeError的答案所示:'str'不支持缓冲区接口
哪种方法更好或更好Pythonic?或者只是个人喜好?
b = bytes(mystring, 'utf-8')
b = mystring.encode('utf-8')
Run Code Online (Sandbox Code Playgroud) 当我运行此代码时:
import getpass
p = getpass.getpass(prompt='digite a senha\n')
if p == '12345':
print('YO Paul')
else:
print('BRHHH')
print('O seu input foi:', p) # p = seu input
Run Code Online (Sandbox Code Playgroud)
我收到了这个警告:
Warning (from warnings module):
File "/usr/lib/python3.4/getpass.py", line 63
passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed.
Run Code Online (Sandbox Code Playgroud)