Inheritance and imports

Viewed 7017

This is my first question here in stackoverflow, so if I make one or two mistakes, please, let me now. Also, I'm not an English native speaker, so be prepared for some grammar mistakes as well.

The thing is that I'm a total newbie, and I am learning programming through python and javascript. Right now I've covered the essentials and I'm experimenting with my first app in python, so it's the first time that I practice with modules, inheritance and etc. And I have some doubts regarding the importation of methods/classes through various modules:

  1. I write a class (e.g. Class_1). Then I write another class (e.g. Class_2) in another Module. Class_2 inherits from Class_1. At the same time, I have some methods from yet another Module imported at the Class_1.__init__ method level. When I write Class_2, I have to import again in the __init__ method the methods imported in Class_1 or the inheritance implies also the methods imported at the Class_1 level?

Example:

class Class_1(object):
    def __init__(self, args):
    from Module_5.Module_A import method_x
    # Class definition...

class Class_2(Class_1):
    def __init__(self, args):
    from Module_5.Module_A import method_x again?
    # Class definition...
  1. I have a Module with, say, 10 classes and 30 methods. Imagine that two of my classes need the same method (e.g. method_x) from another Module (again, in the __init__ method of each class). Is there some performance implication for the classes that don't use the method_x if I import a method at the Module level, instead of at the class level? What is the 'usual' or the 'more pythonic' way (if there is such a think in this case), importing the method at the module level or at the class level when a) only one class in the module needs the imported method and when b) 1 < [number of classes that need the method] < [small percentage of classes in the Module] need the imported method?
2 Answers
Related