Search code examples
pythonstrip

AttributeError: 'function' object has no attribute 'strip'


I am trying to strip the white space from the platform.system value so I can compare it in some if/else logic. I am getting the error below. What am I missing?

line 9, in print(os_name.strip()) AttributeError: 'function' object has no attribute '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')

Solution

  • Try this;

    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