简体   繁体   English

TypeError:int()参数必须是字符串或数字,而不是“ Popen” Python

[英]TypeError: int() argument must be a string or a number, not 'Popen' Python

I have these lines using Popen 我有这些行使用Popen

numcpu = sub.Popen("($(cat /proc/cpuinfo | grep 'physical id' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)
numcores = sub.Popen("($(cat /proc/cpuinfo | grep 'cpu cores' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)  
numsibling = sub.Popen("($(cat /proc/cpuinfo | grep 'siblings' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)

but run into this traceback error 但是碰到这个回溯错误

Traceback (most recent call last):
File "./cputool", line 53, in <module>
CpuTool()
File "./cputool", line 45, in CpuTool
numthreads = int(numsibling)/int(numcores)
TypeError: int() argument must be a string or a number, not 'Popen'

On this line 在这条线上

numthreads = int(numsibling)/int(numcores)

I'm new to scripting is there anyway to assign these Popen values to a string or int so this works? 我是脚本的新手,无论如何都可以将这些Popen值分配给字符串或整数,所以这可行吗? I don't think doing a simple numcpu== 'anything' works but I could be wrong? 我不认为做一个简单的numcpu =='anything'可以,但是我可能错了? Any help for a beginner? 对初学者有帮助吗? Nothing I can find on here (SO) for similar cases, work for my case unfortunately. 对于类似的案例,我在这里(SO)找不到任何东西,很遗憾,我的案例无法正常工作。 Thanks! 谢谢!

您可以使用proc_name.stdout.readline()读取标准输出,然后将其转换为int

numthreads = int(numsibling.stdout.readline())/int(numcores.stdout.readline())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:TypeError:int()参数必须是字符串或数字,而不是“ IPv4Network” - Python: TypeError: int() argument must be a string or a number, not 'IPv4Network' TypeError:int()参数必须是字符串或数字,而不是使用ouchdb-python的“元组” - TypeError: int() argument must be a string or a number, not 'tuple' with couchdb-python TypeError:int()参数必须是字符串或数字,而不是&#39;Binary&#39; - TypeError: int() argument must be a string or a number, not 'Binary' TypeError:int()参数必须是字符串或数字,而不是“列表” - TypeError: int() argument must be a string or a number, not 'list' TypeError:int()参数必须是字符串或数字,而不是&#39;tuple&#39; - TypeError: int() argument must be a string or a number, not 'tuple' 类型错误:INT()参数必须是字符串或数字,而不是“字典” - TypeError: int() argument must be a string or a number, not 'dict' TypeError:float()参数必须是python的字符串或数字 - TypeError: float() argument must be a string or a number for python 错误测试python代码:TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“ NoneType” - Error testing python code: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' TypeError : int() 参数必须是字符串、类似字节的对象或数字,而不是 Python Tkinter 中的“条目” - TypeError : int() argument must be a string, a bytes-like object or a number, not 'Entry' in Python Tkinter TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是 python3 中的“NoneType”错误 - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' error in python3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM