How to put text in input line: how to ask for user input on the command line while providing a 'default' answer that the user can edit or delete?

后端 未结 4 1549
忘了有多久
忘了有多久 2020-12-18 21:07

I am creating a Python script that asks for input from the command line. The user will have the ability to edit a part of a file. I can ask for the new information and overw

4条回答
  •  无人及你
    2020-12-18 21:23

    You should just have 2 variables: one for standard string, one for string that will user change by itself. Like:

    str1 = 'String that is standard'
    str2 = str1 #it usually will be standard string
    usr = input('your text goes here')
    if len(usr) != 0:
        str2 = usr
    #and here goes code for writing string into file
    

提交回复
热议问题