문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top