开发者

different results in IDLE and Windows console

开发者 https://www.devze.com 2023-02-24 04:32 出处:网络
I write this simple bit of code (Python 3.2 on Win32): def main(): decision = input(\'¿Send mail? (y/n): \')

I write this simple bit of code (Python 3.2 on Win32):

def main():
    decision = input('¿Send mail? (y/n): ')
    if decision == "y":
        sender()
        print("Mail sent.")
    else:
        print("Cancelled.开发者_开发知识库")
    input()

def sender():
    print("In sender ... ")
    pass

main()

and it works as expected in IDLE, but in the Windows console it surprisingly says 'cancelled' when you choose 'y'.

Now this makes no sense to me, Can you please help me see what's wrong?


I suggest you read the definition of input(). It is not recommended for general user input as it expects syntactically valid Python code and eval()s it.

0

精彩评论

暂无评论...
验证码 换一张
取 消