0

I am importing a function - func, from a module - mod, using

from mod import func

And using it as

X=func(x,y)

but before executing the function my program is executing the whole module. How do I make it to execute only the function?

0

1 Answer 1

1

If you want to avoid module execution put the code in the module under main

# stuff to run always here such as class/def
def main():
    pass

if __name__ == "__main__":
   # stuff only to run when not called via 'import' here
   main()

more complete answer: Why is Python running my module when I import it, and how do I stop it?

Sign up to request clarification or add additional context in comments.

1 Comment

If there is a "more complete answer" on another question, please flag or vote to close as duplicate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.