[Tutor] TypeError: 'str' object is not callable

me smile2me at nobodiesfool.com
Sat May 15 10:13:20 EDT 2021


Hello,

I'm on my very first steps with python and I have a problem where I don't see, 
what's wrong.

This is the code:
-----<snip>-----------
#!/usr/bin/env python3
import glob

class foo:
    def __init__(self, path):
        self.path = path


    def path(self):
        return self.path


def main():
    hs = []
    drives = glob.glob('/dev/sd?') 
    for d in drives:
        print(d)
        hs.append(foo(d))
    for e in hs:
        print(e.path())


if __name__ == '__main__':
    main()
-----<snap>-----------

and this is the error message:
Traceback (most recent call last):
  File "test.py", line 24, in <module>
    main()
  File "test.py", line 20, in main
    print(e.path())
TypeError: 'str' object is not callable

Ok, I understand, that str() will be called internally by conversion of print 
argument. But that argument should already be a string.
So I don't know, how this could happen




More information about the Tutor mailing list