[Tutor] Class learning

jarod_v6 at libero.it jarod_v6 at libero.it
Fri Jan 23 02:44:33 CET 2015


Dear All
How can gave the attributes __name__ to a function? 
class Foo(object):

     
    def __init__(self):
        steps = {}
        tmp = open("rnaseq.base.ini","rb")
        config.readfp(tmp)
        readsets = parse_illumina_readset_file("/home/mauro/Desktop/readset.csv")

    
    @property
    def steps(self):
        return [
            
            self.one,
            self.two,
            self.fmit,
            
            
        ]
    def one(self):
        a = 5
        return a
    def two(self):
        b = 5
        return b

    def fmit(self):
        c = 7
        return c

    #@property
    def show(self):
        ftp="\n".join([str(idx + 1) + "- " + step.__name__  for idx, step in enumerate(self.steps)])

        print ftp
It is working

In [5]: F =  Foo()

In [6]: F.show()
1- one
2- two
3- fmit

Why if I define the data in the same way  I have this error?

<ipython-input-83-a3c57022a089> in <module>()
----> 1 rna.show()

<ipython-input-79-b1a3b6d221ae> in show(self)
    261         #@property
    262         def show(self):
--> 263                 ftp="\n".join([str(idx + 1) + "- " + step.__name__  for idx, step in enumerate(self.steps)])
    264 
    265                 print ftp

AttributeError: 'str' object has no attribute '__name__'
Here you find all the other code the principal are the same:http://pastebin.com/nYGEiXY4
rna = Rnaseq()
rna.show()
thanks so much!!



More information about the Tutor mailing list