shlex模块解决方案允许转义的引号,一个引号的转义和所有花哨的东西外壳程序支持。
>>> import shlex>>> my_splitter = shlex.shlex('''foo, bar, "one, two", three four''', posix=True)>>> my_splitter.whitespace += ','>>> my_splitter.whitespace_split = True>>> print list(my_splitter)['foo', 'bar', 'one, two', 'three', 'four']
转义引号示例:
>>> my_splitter = shlex.shlex('''"test, a",'foo,bar",baz',bar xc3xa4 baz''', posix=True) >>> my_splitter.whitespace = ',' ; my_splitter.whitespace_split = True >>> print list(my_splitter)['test, a', 'foo,bar",baz', 'bar xc3xa4 baz']
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)