Excercise 41 Read More Code

I don’t quite understand. Are we supposed to look at the source code for the program that we used to memorize phrase?

“You will look for all the files with classes, and then do the
following”

“1. For each class, give its name and what other classes it inherits from”

What files?

So I am supposed to look at the source code for each class and give its name? How do I know its name?

Hello @Trezor.

I cannot stop thinking that you have skipped the study drills and rushed through the book.
Have you? If so I suggest that you go back a lesson or two.

I help you a bit on the way.

# 1
class TopClass(object):
    pass

    def a_method(self):
        pass


#2
class SubClass(TopClass):
    pass

Class nr 1 is called TopClass
Class nr 2 is called SubClass and inherit methods from TopClass

1 Like

Thanks ulfen69, I get it now.

No I don’t, I accidentally looked at the source code for ex42 instead of 41. I don’t see any classes in ex41 because there are no code with the keyword “class”. Help.

How about ex43?

Well this aplies to anything in a Python file that start with ”class”
Next comes the name of the class.
And they always starts with a uppercase letter.

Myclass

Then it is a bit different sometimes.
They can end with a

: or
(): or
(object):

If the brackets contains a name it is the ”parent class” of the current one.

class Son(Father):
    pass

The book says “1. For each class, give its name and what other classes it inherits from.”

But there are no classes in the code!

Oh no!. Its this one :cold_sweat:

:slight_smile:
On this one you are suppose to write down in a file called oop_test.py.
When you run it

python3 op_test.py

it will give you a piece of a class.
You are suppose to give it a name.
Then the answer comes after

class Drop(Downtown): # explain this.
> make a class named Drop that is-a Downtown # you answer

ANSWER: Make a class named Drop that is-a Downtown. # The program gives the correct answer

doll.chain = 'dog'
> # Your call again.       

When I did the book for Python 2 Zed was very clear that all code should not be copied and pasted. One learn better if type it your self.

3 Likes

Thanks you so much ulfen69.