I have a function and I'm making another one in which I need to call the first function. I don't have experience in Python, but I know that in languages like MATLAB it's possible as long as they're in the same directory.
A basic example:
def square(x):
square = x * x
(and saved)
Now in my new function I want to use the function square I tried:
def something (y, z)
import square
something = square(y) + square(z)
return something
Which displays: builtins.TypeError: 'module' object is not callable.
What should I do?
squarewhich you import, then that overrides the name of the function of the same name. It is not usual in Python to put each function in its own file (and therefore module). Just put all your functions in one file (module). Modules are used only in case you have very large structures which logically do not fit into one thing. - Alfe