Python Help in Object Orientation

0

What's wrong with this code? The compiler points to error in line 8 ...

class Pai(object):
    Nome='Carlos'
    Sobrenome='Maria'
    Residencia='Rio de Janeiro'
class Filha(Pai):
    Nome='Luciana'
    def __init__(self, humor):
        self.humor = humor

f = Filha('alegre')
print(f.Nome)
print(Nome.Pai)
print(f.Sobrenome)
print(f.Residencia)
print(f.olho)
    
asked by anonymous 17.05.2016 / 00:19

1 answer

0

The code has some conceptual errors, see the code below:

class Pai(object):
    Nome='Carlos'
    Sobrenome='Maria'
    Residencia='Rio de Janeiro'

class Filha(Pai):
    Nome='Luciana'
    def __init__(self, humor):
        Pai.__init__(self) # Lembre-se de sempre iniciar a classe pai
        self.humor = humor

f = Filha('alegre')
print(f.Nome)
print(f.Sobrenome)
print(f.Residencia)

Other considerations: At line print(Nome.Pai) can not be obtained because there is no instance of Nome . If you want to find the parent name, it will not be possible because the Name attribute was overwritten by the child class.

The f.olho attribute is invalid because it does not exist in the

    
29.05.2016 / 00:37