Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

Python define method of class outside of class

We are currently porting a MATLAB project to Python and thinking about the structure of the classes as we do not want to port the structure from MATLAB to Python but rather ensure that we design in in the most Pythonic way possible.

We have identified a class X that has several methods and later on we want to add new methods that work on objects of type X. It would make sense to make these new methods part of X, but we don't want to redefine X every time. Also, some of those methods are experimental and we would like to avoid adding them and in a later version remove them again.

What would be the Pythonic way to deal with this? We thought about adding new static methods in other classes Y,Z that can take X as an argument.

question from:https://stackoverflow.com/questions/65831801/python-define-method-of-class-outside-of-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...