Why I am getting error ‘module’ object is not callable here
import platform
mm = ['architecture', 'collections', 'java_ver', 'libc_ver', 'mac_ver', 'machine', 'node', 'os', 'platform', 'processor', 'python_branch', 'python_build', 'python_compiler', 'python_implementation',
'python_revision', 'python_version', 'python_version_tuple', 're', 'release', 'sys', 'system', 'system_alias', 'uname', 'uname_result', 'version', 'win32_edition', 'win32_is_iot', 'win32_ver']
for i in mm:
c = getattr(platform,i)()
print(c)
I am trying to call output like platform.archirecture() so have added parentheses
>Solution :
You can use the try-except block to prevent this error.
import platform
mm = ['architecture', 'collections', 'java_ver', 'libc_ver', 'mac_ver', 'machine', 'node', 'os', 'platform', 'processor', 'python_branch', 'python_build', 'python_compiler', 'python_implementation',
'python_revision', 'python_version', 'python_version_tuple', 're', 'release', 'sys', 'system', 'system_alias', 'uname', 'uname_result', 'version', 'win32_edition', 'win32_is_iot', 'win32_ver']
for i in mm:
try:
c = getattr(platform,i)()
except TypeError:
c = getattr(platform,i)
print(c)