python variable sharing between packages/modules

前端 未结 3 1788
离开以前
离开以前 2021-01-23 16:02

trying to understand and learn how to write packages... testing with something i\'ve always used, logging...

Can you please help me understand why the \'log\' variable i

3条回答
  •  忘掉有多难
    2021-01-23 16:49

    log is a global variable in the differentlogging module. Thus you can access it as clusterlogging.differentlogging.log.

    You could also do something like from clusterlogging.differentlogging import log and then access it as just log.

    Edit: actually, on reviewing your code again I don't know what to make of it. Could you please fix up your code indentation so that it makes sense? Are you defining log inside the consolelogging function? If so, you'll need to either make it global with global log or return it from the function and assign it to a variable log on the line where you call the function.

提交回复
热议问题