相关疑难解决方法(0)

每隔第n个字符拆分字符串?

是否有可能每隔第n个字符拆分一个python字符串?

例如,假设我有一个包含以下内容的字符串:

'1234567890'
Run Code Online (Sandbox Code Playgroud)

我怎么能让它看起来像这样:

['12','34','56','78','90']
Run Code Online (Sandbox Code Playgroud)

python string split

342
推荐指数
14
解决办法
30万
查看次数

为什么subprocess.Popen参数长度限制小于操作系统报告的限制?

我在Linux 3.16.0上运行Python 3.4.3.我想subprocess.Popen用一个长单个参数(一个复杂的Bash调用)运行一个命令,大约200KiB.

根据getconfxargs,这应该在我的范围内:

$ 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)

python linux subprocess command-line-arguments python-3.x

11
推荐指数
1
解决办法
7921
查看次数