是否有可能每隔第n个字符拆分一个python字符串?
例如,假设我有一个包含以下内容的字符串:
'1234567890'
Run Code Online (Sandbox Code Playgroud)
我怎么能让它看起来像这样:
['12','34','56','78','90']
Run Code Online (Sandbox Code Playgroud) 我在Linux 3.16.0上运行Python 3.4.3.我想subprocess.Popen用一个长单个参数(一个复杂的Bash调用)运行一个命令,大约200KiB.
根据getconf和xargs,这应该在我的范围内:
$ getconf ARG_MAX
2097152
$ xargs --show-limits < /dev/null
Your environment variables take up 3364 bytes
POSIX upper limit on argument length (this system): 2091740
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2088376
Size of command buffer we are actually using: 131072
Run Code Online (Sandbox Code Playgroud)
但是,Python以极小的限制失败:
>>> subprocess.Popen('echo %s > /dev/null' % ('a' * (131072-4096)), shell=True, executable='/bin/bash')
<subprocess.Popen object at 0x7f4613b58410> …Run Code Online (Sandbox Code Playgroud)