Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中指定子流程中的数据类型?_Python_Python 2.7 - Fatal编程技术网

如何在python中指定子流程中的数据类型?

如何在python中指定子流程中的数据类型?,python,python-2.7,Python,Python 2.7,使用子流程执行命令后,将以字符串类型给出结果 cmd = "ping -c 2 stackoverflow.com | grep -i icmp* |wc -l" count = subprocess.check_output([cmd],shell=True) count '2\n' type(count) <type 'str'> cmd=“ping-c2 stackoverflow.com | grep-i icmp*| wc-l” 计数=子进程。检查输出([cmd],sh

使用子流程执行命令后,将以字符串类型给出结果

cmd = "ping -c 2  stackoverflow.com | grep -i icmp* |wc -l"
count = subprocess.check_output([cmd],shell=True)
count
'2\n'
type(count)
<type 'str'>
cmd=“ping-c2 stackoverflow.com | grep-i icmp*| wc-l”
计数=子进程。检查输出([cmd],shell=True)
计数
“2\n”
类型(计数)

但我需要“int”格式的计数,除了将其类型转换为“int(count)”,我如何在子流程命令级别执行此操作…是否有任何选项可以指定子流程本身中的数据类型?

命令输出始终是字符串缓冲区。如果需要的话,只需将其转换为
int

子流程
通过原始数据管道进行通信,原始数据管道作为
str
发送和接收(Python 3中的
字节
)。不可能有其他数据类型。正如您在问题中提到的,您只需要使用
count=int(count)
转换结果