Python3 变量命名空间、import 整理
2021/12/1 11:06:11
本文主要是介绍Python3 变量命名空间、import 整理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
变量命名空间
每个函数 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
使用方式
# 方式1,使用 import common.log.LogFactory logger = common.log.LogFactory.getLogger("main") # 方式2,使用 from common.util import DateUtils nowTime = DateUtils.getNowTime() # 方式3,使用 from common.util.StringUtils newStr = strFormat( "test" ) // strFormat 来自 StringUtils.py
这篇关于Python3 变量命名空间、import 整理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python