Retrieve all functions and attributes from an already instanced parent in the child class












0















I'm trying to do this : Initialise child class with instance of parent class.



genomic_feature_instance is instanced and contains what follows :




{'name': 'ENSG00000223972.5', 'type': 'gene', 'iv': , 'source': 'HAVANA',
'score': '.', 'frame': '.', 'attr' : {'ID': 'ENSG00000223972.5',
'gene_id': 'ENSG00000223972.5', 'gene_type':
'transcribed_unprocessed_pseudogene', 'gene_status': 'KNOWN',
'gene_name': 'DDX11L1', 'leve l': '2', 'havana_gene':
'OTTHUMG00000000961.2'}}




I want to create a custom/child instance to manipulate attributes and functions from this class of genomic_feature_instance.



 aCustomGenomicFeature = CustomGenomicFeature(genomic_feature_instance,'kikou')


This is what I have done but I would like to use super() to inherit all attribute values from this genomic_feature (instance of GenomicFeature)



class CustomGenomicFeature(GenomicFeature):

def __init__(self,genomic_feature_instance,kikou):

# call parent constructor to set name and color
self.genomic_feature = genomic_feature_instance
# Subclass-specific stuff follows
self.kikou=kikou









share|improve this question



























    0















    I'm trying to do this : Initialise child class with instance of parent class.



    genomic_feature_instance is instanced and contains what follows :




    {'name': 'ENSG00000223972.5', 'type': 'gene', 'iv': , 'source': 'HAVANA',
    'score': '.', 'frame': '.', 'attr' : {'ID': 'ENSG00000223972.5',
    'gene_id': 'ENSG00000223972.5', 'gene_type':
    'transcribed_unprocessed_pseudogene', 'gene_status': 'KNOWN',
    'gene_name': 'DDX11L1', 'leve l': '2', 'havana_gene':
    'OTTHUMG00000000961.2'}}




    I want to create a custom/child instance to manipulate attributes and functions from this class of genomic_feature_instance.



     aCustomGenomicFeature = CustomGenomicFeature(genomic_feature_instance,'kikou')


    This is what I have done but I would like to use super() to inherit all attribute values from this genomic_feature (instance of GenomicFeature)



    class CustomGenomicFeature(GenomicFeature):

    def __init__(self,genomic_feature_instance,kikou):

    # call parent constructor to set name and color
    self.genomic_feature = genomic_feature_instance
    # Subclass-specific stuff follows
    self.kikou=kikou









    share|improve this question

























      0












      0








      0








      I'm trying to do this : Initialise child class with instance of parent class.



      genomic_feature_instance is instanced and contains what follows :




      {'name': 'ENSG00000223972.5', 'type': 'gene', 'iv': , 'source': 'HAVANA',
      'score': '.', 'frame': '.', 'attr' : {'ID': 'ENSG00000223972.5',
      'gene_id': 'ENSG00000223972.5', 'gene_type':
      'transcribed_unprocessed_pseudogene', 'gene_status': 'KNOWN',
      'gene_name': 'DDX11L1', 'leve l': '2', 'havana_gene':
      'OTTHUMG00000000961.2'}}




      I want to create a custom/child instance to manipulate attributes and functions from this class of genomic_feature_instance.



       aCustomGenomicFeature = CustomGenomicFeature(genomic_feature_instance,'kikou')


      This is what I have done but I would like to use super() to inherit all attribute values from this genomic_feature (instance of GenomicFeature)



      class CustomGenomicFeature(GenomicFeature):

      def __init__(self,genomic_feature_instance,kikou):

      # call parent constructor to set name and color
      self.genomic_feature = genomic_feature_instance
      # Subclass-specific stuff follows
      self.kikou=kikou









      share|improve this question














      I'm trying to do this : Initialise child class with instance of parent class.



      genomic_feature_instance is instanced and contains what follows :




      {'name': 'ENSG00000223972.5', 'type': 'gene', 'iv': , 'source': 'HAVANA',
      'score': '.', 'frame': '.', 'attr' : {'ID': 'ENSG00000223972.5',
      'gene_id': 'ENSG00000223972.5', 'gene_type':
      'transcribed_unprocessed_pseudogene', 'gene_status': 'KNOWN',
      'gene_name': 'DDX11L1', 'leve l': '2', 'havana_gene':
      'OTTHUMG00000000961.2'}}




      I want to create a custom/child instance to manipulate attributes and functions from this class of genomic_feature_instance.



       aCustomGenomicFeature = CustomGenomicFeature(genomic_feature_instance,'kikou')


      This is what I have done but I would like to use super() to inherit all attribute values from this genomic_feature (instance of GenomicFeature)



      class CustomGenomicFeature(GenomicFeature):

      def __init__(self,genomic_feature_instance,kikou):

      # call parent constructor to set name and color
      self.genomic_feature = genomic_feature_instance
      # Subclass-specific stuff follows
      self.kikou=kikou






      python-3.x inheritance






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 18 at 16:24









      ZheFrenchZheFrench

      51821537




      51821537
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Within the init() method of the CustomGenomicFeature class you can explicitly invoke the init() method of the GenomicFeature class by just calling super().init()



          class CustomGenomicFeature(GenomicFeature):

          def __init__(self,genomic_feature,kikou):
          super().__init__(genomic_feature)
          self.kikou=kikou





          share|improve this answer































            0














            With __dict__.update



            I would rather advice the use of __dict__ instead of super, because super won't help you to copy the value of the attributes of the parent object. So you could do something like that:



            class A():
            def __init__(self):
            self.x = 1

            class B(A):
            def __init__(self, a):
            super(B, self).__init__()
            self.__dict__.update(a.__dict__)

            a = A()
            b = B(a)

            print(b.x) # displays '1'

            a.x = 3
            b2 = B(a)

            print(b2.x) # displays '3'. Without the __dict__update, it would return '1'


            That way you set every attribute your parent class has without modifying the attributes of the child class that the parent does not have.



            In your case:



            class CustomGenomicFeature(GenomicFeature):

            def __init__(self,genomic_feature_instance,kikou):

            self.__dict__.update(genomic_feature_instance.__dict__)

            # Subclass-specific stuff follows
            self.kikou=kikou


            With Composition



            Another way (and probably more clean), would be to use composition instead of inheritance:



            class CustomGenomicFeature(GenomicFeature):

            def __init__(self,genomic_feature_instance,kikou):

            # keep ref to the genomic_feature_instance
            self._genomic_feature = genomic_feature_instance

            # Subclass-specific stuff follows
            self.kikou=kikou

            @property
            def name(self):
            return self._genomic_feature.name


            More:




            • Inheritance vs. Composition






            share|improve this answer
























            • Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

              – ZheFrench
              14 hours ago











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257853%2fretrieve-all-functions-and-attributes-from-an-already-instanced-parent-in-the-ch%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Within the init() method of the CustomGenomicFeature class you can explicitly invoke the init() method of the GenomicFeature class by just calling super().init()



            class CustomGenomicFeature(GenomicFeature):

            def __init__(self,genomic_feature,kikou):
            super().__init__(genomic_feature)
            self.kikou=kikou





            share|improve this answer




























              0














              Within the init() method of the CustomGenomicFeature class you can explicitly invoke the init() method of the GenomicFeature class by just calling super().init()



              class CustomGenomicFeature(GenomicFeature):

              def __init__(self,genomic_feature,kikou):
              super().__init__(genomic_feature)
              self.kikou=kikou





              share|improve this answer


























                0












                0








                0







                Within the init() method of the CustomGenomicFeature class you can explicitly invoke the init() method of the GenomicFeature class by just calling super().init()



                class CustomGenomicFeature(GenomicFeature):

                def __init__(self,genomic_feature,kikou):
                super().__init__(genomic_feature)
                self.kikou=kikou





                share|improve this answer













                Within the init() method of the CustomGenomicFeature class you can explicitly invoke the init() method of the GenomicFeature class by just calling super().init()



                class CustomGenomicFeature(GenomicFeature):

                def __init__(self,genomic_feature,kikou):
                super().__init__(genomic_feature)
                self.kikou=kikou






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 18 at 17:00









                BMac413BMac413

                464




                464

























                    0














                    With __dict__.update



                    I would rather advice the use of __dict__ instead of super, because super won't help you to copy the value of the attributes of the parent object. So you could do something like that:



                    class A():
                    def __init__(self):
                    self.x = 1

                    class B(A):
                    def __init__(self, a):
                    super(B, self).__init__()
                    self.__dict__.update(a.__dict__)

                    a = A()
                    b = B(a)

                    print(b.x) # displays '1'

                    a.x = 3
                    b2 = B(a)

                    print(b2.x) # displays '3'. Without the __dict__update, it would return '1'


                    That way you set every attribute your parent class has without modifying the attributes of the child class that the parent does not have.



                    In your case:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    self.__dict__.update(genomic_feature_instance.__dict__)

                    # Subclass-specific stuff follows
                    self.kikou=kikou


                    With Composition



                    Another way (and probably more clean), would be to use composition instead of inheritance:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    # keep ref to the genomic_feature_instance
                    self._genomic_feature = genomic_feature_instance

                    # Subclass-specific stuff follows
                    self.kikou=kikou

                    @property
                    def name(self):
                    return self._genomic_feature.name


                    More:




                    • Inheritance vs. Composition






                    share|improve this answer
























                    • Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                      – ZheFrench
                      14 hours ago
















                    0














                    With __dict__.update



                    I would rather advice the use of __dict__ instead of super, because super won't help you to copy the value of the attributes of the parent object. So you could do something like that:



                    class A():
                    def __init__(self):
                    self.x = 1

                    class B(A):
                    def __init__(self, a):
                    super(B, self).__init__()
                    self.__dict__.update(a.__dict__)

                    a = A()
                    b = B(a)

                    print(b.x) # displays '1'

                    a.x = 3
                    b2 = B(a)

                    print(b2.x) # displays '3'. Without the __dict__update, it would return '1'


                    That way you set every attribute your parent class has without modifying the attributes of the child class that the parent does not have.



                    In your case:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    self.__dict__.update(genomic_feature_instance.__dict__)

                    # Subclass-specific stuff follows
                    self.kikou=kikou


                    With Composition



                    Another way (and probably more clean), would be to use composition instead of inheritance:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    # keep ref to the genomic_feature_instance
                    self._genomic_feature = genomic_feature_instance

                    # Subclass-specific stuff follows
                    self.kikou=kikou

                    @property
                    def name(self):
                    return self._genomic_feature.name


                    More:




                    • Inheritance vs. Composition






                    share|improve this answer
























                    • Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                      – ZheFrench
                      14 hours ago














                    0












                    0








                    0







                    With __dict__.update



                    I would rather advice the use of __dict__ instead of super, because super won't help you to copy the value of the attributes of the parent object. So you could do something like that:



                    class A():
                    def __init__(self):
                    self.x = 1

                    class B(A):
                    def __init__(self, a):
                    super(B, self).__init__()
                    self.__dict__.update(a.__dict__)

                    a = A()
                    b = B(a)

                    print(b.x) # displays '1'

                    a.x = 3
                    b2 = B(a)

                    print(b2.x) # displays '3'. Without the __dict__update, it would return '1'


                    That way you set every attribute your parent class has without modifying the attributes of the child class that the parent does not have.



                    In your case:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    self.__dict__.update(genomic_feature_instance.__dict__)

                    # Subclass-specific stuff follows
                    self.kikou=kikou


                    With Composition



                    Another way (and probably more clean), would be to use composition instead of inheritance:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    # keep ref to the genomic_feature_instance
                    self._genomic_feature = genomic_feature_instance

                    # Subclass-specific stuff follows
                    self.kikou=kikou

                    @property
                    def name(self):
                    return self._genomic_feature.name


                    More:




                    • Inheritance vs. Composition






                    share|improve this answer













                    With __dict__.update



                    I would rather advice the use of __dict__ instead of super, because super won't help you to copy the value of the attributes of the parent object. So you could do something like that:



                    class A():
                    def __init__(self):
                    self.x = 1

                    class B(A):
                    def __init__(self, a):
                    super(B, self).__init__()
                    self.__dict__.update(a.__dict__)

                    a = A()
                    b = B(a)

                    print(b.x) # displays '1'

                    a.x = 3
                    b2 = B(a)

                    print(b2.x) # displays '3'. Without the __dict__update, it would return '1'


                    That way you set every attribute your parent class has without modifying the attributes of the child class that the parent does not have.



                    In your case:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    self.__dict__.update(genomic_feature_instance.__dict__)

                    # Subclass-specific stuff follows
                    self.kikou=kikou


                    With Composition



                    Another way (and probably more clean), would be to use composition instead of inheritance:



                    class CustomGenomicFeature(GenomicFeature):

                    def __init__(self,genomic_feature_instance,kikou):

                    # keep ref to the genomic_feature_instance
                    self._genomic_feature = genomic_feature_instance

                    # Subclass-specific stuff follows
                    self.kikou=kikou

                    @property
                    def name(self):
                    return self._genomic_feature.name


                    More:




                    • Inheritance vs. Composition







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 18 at 17:03









                    olinox14olinox14

                    35117




                    35117













                    • Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                      – ZheFrench
                      14 hours ago



















                    • Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                      – ZheFrench
                      14 hours ago

















                    Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                    – ZheFrench
                    14 hours ago





                    Ok but then you need to define all properties from the parent class then...well ok but i you have many attributes that can be long and I also want to keep function from parent, so inheritance was not so bad idea , no?

                    – ZheFrench
                    14 hours ago


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257853%2fretrieve-all-functions-and-attributes-from-an-already-instanced-parent-in-the-ch%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Liquibase includeAll doesn't find base path

                    How to use setInterval in EJS file?

                    Petrus Granier-Deferre