[Tutor] problem with program in python in easy steps

boB Stepp robertvstepp at gmail.com
Thu Oct 26 20:11:37 EDT 2017


On Thu, Oct 26, 2017 at 3:02 PM, Chris Coleman <anrkris at gmail.com> wrote:
>
> i wrote these programs and saved them per instructions on page 128 and 129
> in the book "python in easy steps".
>
> class Person:
>     '''A base class to define Person properties.'''
>     def__init__(self,name):

The above line should generate an error as there is no space between
"def" and "__init__".

>         self.name = name
>     def speak( self,msg = '(Calling The Base Class)'):
>         print(self.name,msg)
>
> from Person import*
>     '''A derived class to define Man properties.'''
> class Man(Person):
>     def speak(self,msg):
>         print(self.name,':\n\tHello!',msg)
>
> from Person import*
>     '''A derived class to define Hombre properties.'''
> class Hombre(Person):
>     def speak(self,msg):
>         print(self.name,':\n\tHola!',msg)
>
> from Man import*
> from Hombre import*
> guy_1 = Man('Richard')
> guy_2 = Hombre('Ricardo')
> guy_1.speak('It\'s a beautiful evening.\n')
> guy_2.speak('Es una tarde hermosa.\n')
> Person.speak(guy_1)
> Person.speak(guy_2)
>
> i ran the program override.py and get this error message:
>
> Traceback (most recent call last):
>   File "scripts/override.py", line 1, in <module>
>     from Man import*
>   File "/home/chris/scripts/Man.py", line 2
>     '''A derived class to define Man properties.'''
>     ^
> IndentationError: unexpected indent

So, did you try removing the indentation in front of '''A derived
class ... '''?  And once you do, you will get the same error later on
where you did the same thing.  Recall that Python uses indentation to
define its code blocks.



-- 
boB


More information about the Tutor mailing list