Question

In Google python style guide it states (towards the end for "Main")

"All code at the top level will be executed when the module is imported"

I'm under the impression that top level code is any code in a module(file) that is indented at 0. So does that mean for example functions requiring arguments to be passed to them are executed? How is this possible or am I misunderstanding what top level code is and/or how things are being executed during import?

Here is a link for the guide

Was it helpful?

Solution

if you have a module like:

a = 10

def some_function(a,b):
  do_something

on import assignment a = 10 will be executed and a function some_function() only when you call it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top