如何解决AttributeError: 'function' 对象没有属性 'strip'
我正在尝试从 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。