Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:08:19+00:00 2026-06-06T11:08:19+00:00

Apologies if this doesn’t make sense, i’m not much of an experienced programmer. Consider

  • 0

Apologies if this doesn’t make sense, i’m not much of an experienced programmer.

Consider the following code:

import mymodule

class MyClass:
    def __init__(self):
        self.classInstance = myModule.classInstance()

and then ……

from mymodule import classInstance

class MyClass(classInstance):
    def __init__(self):
        pass

If I just wanted to use the one classInstance in MyClass, is it ok to import the specific class from the module and have MyClass inherit this class ?

Are there any best practices, or things I should be thinking about when deciding between these two methods ?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:08:21+00:00Added an answer on June 6, 2026 at 11:08 am

    Allow me to propose a different example.

    Imagine to have the class Vector.
    Now you want a class Point. Point can be defined with a vector but maybe it has other extra functionalities that Vector doesn’t have.
    In this case you derive Point from Vector.

    Now you need a Line class.
    A Line is not a specialisation of any of the above classes so probably you don’t want to derive it from any of them.
    However Line uses points. In this case you might want to start you Line class this way:

    class Line(object):
        def __init__(self):
            self.point1 = Point()
            self.point2 = Point()
    

    Where point will be something like this:

    class Point(Vector):
        def __init__(self):
            Vector.__init__(self)
    

    So the answer is really: Depends what you need to do, but when you have a clear idea of what you are coding, than choosing between sub-classing or not becomes obvious.

    I hope it helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my apologies if this question doesn't make much sense, but I'm new(ish) to Actionscript,
Apologies if this doesn't make any sense, I'm very new to Python! From testing
I'm new to Cocoa so apologies if this doesn't make sense. I'm using an
Apologies if the title doesn't make much sense but I couldn't think of a
I apologize in advance, if this question doesn't make sense. I'm a newbie. I
I'm not experienced in Javascript, so apologies if this is a basic question, but
Apologies if this is a repost, I could not find the search terms to
Consider the following code (includes jQuery): <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
I've tried searching but haven't had much luck- apologies if this is answered somewhere.
[It seems odd this doesn't exist, so apologies in advance if it's a duplicate]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.