Python - extending properties like you'd extend a function

前端 未结 4 1616
甜味超标
甜味超标 2021-01-11 17:42

Question

How can you extend a python property?

A subclass can extend a super class\'s function by calling it in the overloaded version, a

4条回答
  •  甜味超标
    2021-01-11 18:39

    You have some possibilities to consider:

    1/ Inherit from logfile and override parse in your derived sensor class. It should be possible to modify your methods that work on dataframe to work regardless of the number of members that dataframe has - as you are using pandas a lot of it is done for you.

    2/ Make sensor an instance of logfile then provide its own parse method.

    3/ Generalise parse, and possibly some of your other methods, to use a list of data descriptors and possibly a dictionary of methods/rules either set in your class initialiser or set by a methods.

    4/ Look at either making more use of the methods already in pandas, or possibly, extending pandas to provide the missing methods if you and others think that they would be accepted into pandas as useful extensions.

    Personally I think that you would find the benefits of options 3 or 4 to be the most powerful.

提交回复
热议问题