问题描述
我正在尝试从 platform.system 值中去除空白区域,以便我可以在某些 if/else 逻辑中进行比较。我收到以下错误。我错过了什么?
第 9 行,在 打印(os_name.strip()) AttributeError: 'function' 对象没有属性 'strip'
import platform
os_name = platform.system
os_name_strip = os_name.strip()
print('OS Name :',os_name_strip)
if os_name == 'Windows':
print('we have an OS match')
else:
print('we do not have an OS match')
解决方法
您已将实际函数 def repeate(c,rep):
c=input("what str")
rep=int(input("how many times?"))
for i in range(rep):
print(c*rep)
return i
repeat=repeate(0,0)
print(repeat)
分配给您的 platform.system
变量。要执行函数并存储输出值,请确保包含括号:
os_name
,
试试这个;
import platform
os_name = platform.system()
os_name_strip = os_name.strip()
print('OS Name :',os_name_strip)
if os_name == 'Windows':
print('we have an OS match')
else:
print('we do not have an OS match')
OS Name : Windows
we have an OS match