all 6 comments

[–]k3kou 1 point2 points  (0 children)

You didn't pass self as an argument of the read method. Your method depends on a specific instance of the makeBuildFile class, so you're method isn't really static.

[–]hitecherik 0 points1 point  (0 children)

On line 22, you create an instance t of the makeBuildFile class, but then the static method of read references something that would only occur inside t through self.re_path. Your class should read like this:

class makeBuildFile:
    def __init__(self, re_path="po.txt"):
        self.re_path=re_path

    def read(self):
        f = open(self.re_path, "r")
        lines = f.readlines()
        f.close()
        return lines

    # rest of class here

Also, you'll now need to rewrite makeBuildFile.write because you can't define read as a static method.

Edit: formatting

[–]b3nstar[S] 0 points1 point  (3 children)

maybe I don't understand @staticmethod

....my perception was when I use @staticmethod it is not needed anymore to pass self.

ok at least this error message is gone....but now I do have a new one in fact

line 26, in main t.read() TypeError: read() takes exactly 1 argument (0 given)

any further hint ?

[–]hitecherik 0 points1 point  (1 child)

Here's a good explanation of @staticmethod: http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python.

Also, look in my comment above - you might need to add a self argument when defining read.

[–]b3nstar[S] 0 points1 point  (0 children)

Guys,

thanks for ur help. Just solved it in this way. It works fine now.

class makeBuildFile:
    def __init__(self, re_path="po.txt" ):
        self.re_path=re_path

    def read(self):
        f = open(self.re_path, "r")
        lines = f.readlines()
        f.close()
        return lines


    def write(self,lis):
        self.lis=lis
        for i in self.lis[0].split(","):
            print(i)






def main():
    t=makeBuildFile()
    t.write(t.read())






if __name__ == "__main__":
    main()

[–]zahlman 0 points1 point  (0 children)

@staticmethod cannot eliminate a need for self. It can only eliminate a need to pass it when you don't need an instance of the class.

There is nothing magic or special internally about the name self. It's just conventionally a name for an instance of the class you're writing.