How to redirect the raw_input to stderr and not stdout?

前端 未结 3 1901
余生分开走
余生分开走 2021-01-12 04:53

I want to redirect the stdout to a file. But This will affect the raw_input. I need to redirect the output of raw_input to stde

3条回答
  •  耶瑟儿~
    2021-01-12 05:39

    Use getpass

    import getpass
    
    value=getpass.getpass("Enter Name: ")
    print(value)
    

    This will print the content value to stdout and Enter Name: to stderr.

    Tested and works with python 2.7 and 3.6.

提交回复
热议问题