HW. Parameter parsing

Here Insert Picture Description

while True:
    """
    使用标志位,注意上引号的出现,如果出现过一次上引号,那么当前参数结束的标志不是space而是下一个单引号
    """
    try:
        string =  input()
        result = []
        word = ''
        appear_left_quotation =False
        for char in string:
            if char == " ":
                if not appear_left_quotation:
                    result.append(word)
                    word = ""
                else:
                    word += char
            elif char == "\"" and not appear_left_quotation:
                word += char
                appear_left_quotation = True
            elif char  == "\"" and appear_left_quotation:
                word += char
                result.append(word)
                word =""
                appear_left_quotation =False
            else:
                word+=char
        result.append(word)
        print(len(result))
        for line in result:
            print(line)
    except:
        break

Guess you like

Origin blog.csdn.net/dpengwang/article/details/92946886