What's the reverse of shlex.split?

后端 未结 5 1727
孤独总比滥情好
孤独总比滥情好 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:39

    There is a feature request for adding shlex.join(), which would do exactly what you ask. As of now, there does not seem any progress on it, though, mostly as it would mostly just forward to shlex.quote(). In the bug report, a suggested implementation is mentioned:

    ' '.join(shlex.quote(x) for x in split_command)
    

    See https://bugs.python.org/issue22454

提交回复
热议问题