What's the reverse of shlex.split?

后端 未结 5 1735
孤独总比滥情好
孤独总比滥情好 2020-12-08 02:16

How can I reverse the results of a shlex.split? That is, how can I obtain a quoted string that would \"resemble that of a Unix shell\", given a list of strings

5条回答
  •  醉酒成梦
    2020-12-08 02:46

    How about using pipes.quote?

    import pipes
    strings = ["ls", "/etc/services", "file with spaces"]
    " ".join(pipes.quote(s) for s in strings)
    # "ls /etc/services 'file with spaces'"
    

    .

提交回复
热议问题