如何将字符串拆分成命令行参数(如python中的shell)? [英] How to split a string into command line arguments like the shell in python?

查看:231
本文介绍了如何将字符串拆分成命令行参数(如python中的shell)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在字符串中包含命令行参数,我需要将其拆分以提供给argparse.ArgumentParser.parse_args.

I have command line arguments in a string and I need to split it to feed to argparse.ArgumentParser.parse_args.

我看到文档大量使用string.split().但是,在复杂的情况下,这是行不通的,例如

I see that the documentation uses string.split() plentifully. However in complex cases, this does not work, such as

--foo "spaces in brakets"  --bar escaped\ spaces

是否有在python中执行此操作的功能?

Is there a functionality to do that in python?

(此处 ).

推荐答案

这是 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆