I understand this is the correct way to include a function inside a class, but feels overly complicated and awkward to have to rename existing functions:
from numpy import sin, cos, tan
class Foo1:
def my_sin(self, x):
return sin(x)
def my_cos(self, x):
return cos(x)
def my_tan(self, x):
return tan(x)
a1 = Foo1()
print(a1.my_sin(2))
print(a1.my_cos(2))
print(a1.my_tan(2))
In contrast, this works just as well, and feels neater.
class Foo2:
from numpy import sin, cos, tan
a2 = Foo2()
print(a2.sin(2))
print(a2.cos(2))
print(a2.tan(2))
Why is this wrong, assuming I will only use those functions inside this class? Why does it even work?
(I've redacted my example heavily from my original text to keep it focused.)