willieswanjala
willieswanjala

Reputation: 678

What is the rightway of importing and inheriting classes?

I am relatively new to programming. So far I have seen two ways that classes

are imported and inherited in python. The first one which is also what I

have been doing while learning Flask is:

 from package.module import SuperClass

 class SubClass(SuperClass):

The other one which I am seeing quite often in most Django code is:

 from package import module

 class SubClass(module.SuperClass):

Which one is the right way of doing things? Is there a significant

advantage of using one over the other?

Upvotes: 0

Views: 43

Answers (2)

Brachamul
Brachamul

Reputation: 1974

Short answer : they are the same, choose the most explicit / legible one.

Long answer : more details in this question from the Software Engineering StackExchange.

Upvotes: 1

Hybrid
Hybrid

Reputation: 7049

They are the same thing. The only difference is that it is sometime preferable to import an entire module if there would be too many individual packages to import (you wouldnt want to write from ... import module1, module2, module3, 100 times).

Upvotes: 0

Related Questions