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?

ruskin23
  • 145
  • 1
  • 10

1 Answers1

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?

Community
  • 1
  • 1
Urban48
  • 1,398
  • 1
  • 13
  • 26