Python3 变量命名空间、import 整理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/snake1900/article/details/90142434

变量命名空间

每个函数 function 有自己的命名空间,称local namespace,记录函数的变量。
每个模块 module 有自己的命名空间,称global namespace,记录模块的变量,包括functions、classes、导入的modules、module级别的变量和常量。
build-in 命名空间,它包含build-in function和exceptions,可被任意模块访问。

import 模块语法

目录


/common/log/LogFactory.py
/common/util/DateUtils.py
/common/util/StringUtils.py

引包方式

**import** common.log.LogFactory
**from** common.util **import** DateUtils
**from** common.util.StringUtils

使用方式

logger = common.log.LogFactory.getLogger("main")
nowTime = DateUtils.getNowTime()
newStr = strFormat( "test" )    // strFormat 来自 StringUtils.py

猜你喜欢

转载自blog.csdn.net/snake1900/article/details/90142434