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 7801459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:57:29+00:00 2026-06-02T00:57:29+00:00

I’m trying to pick up Python for a project, and I’m a bit confused

  • 0

I’m trying to pick up Python for a project, and I’m a bit confused about how to use abstraction and classes. (I’m not a very experienced programmer, so apologies for the basic level of this question.) I come from a Java/Ocaml background, and what I’ve been trying to do is as follows: I have abstract classes for a graph and a graphadvanced (a graph with some more fancy methods), that look something like this

class AbstractGraph: 
   def method1(self): 
      raise NotImplementedError
   ...

class AbstractAdvanced:
   def method2(self):
      raise NotImplementedError 
   ... 

I then have an implementation of a graph:

class Graph(AbstractGraph):
   def method1(self):
      * actual code * 

Now my question is: can I do something like this?

class Advanced(AbstractAdvanced, AbstractGraph):
   def method2(self):
      *actual code, using the methods from AbstractGraph*

In other words, how can I define the methods of Advanced abstractly in terms of the methods of AbstractGraph, and then somehow pass Graph into a constructor to get an instance of Advanced that uses Advanced’s definitions with Graph’s implementation?

In terms of Ocaml, I’m trying to treat AbstractAdvanced and AbstractGraph as module types, but I’ve played around a little with python and I’m not sure how to get this to work.

  • 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-02T00:57:31+00:00Added an answer on June 2, 2026 at 12:57 am

    If you want to create abstract base classes, you can, but they are of limited utility. It’s more normal to start your class hierarchy (after inheriting from object, or some other third-party class) with concrete classes.

    If you want to create a class that pieces together various classes that partially some protocol, then just inherit from your implementing classes:

    #Always inherit from object, or some subtype thereof, unless you want your code to behave differently in python 2 and python 3
    
    class AbstractGraph(object): 
       def method1(self): 
          raise NotImplementedError
    
    class Graph(AbstractGraph):
       def method1(self):
          * actual code * 
    
    class GraphToo(AbstractGraph):
       def method1(self):
          * actual code * 
    
    class AbstractAdvanced(AbstractGraph):
       def method2(self):
          raise NotImplementedError 
    
    class Advanced(Graph,AbstractAdvanced):
       def method2(self):
          *actual code, using the methods from Graph*
    
    # order of classes in the inheritance list matters - it will affect the method resolution order
    class AdvancedToo(GraphToo, Advanced): pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.