PyTorch学习记录之使用过的(不常用的)标准库模块 - easydict, __future

1. easydict

from easydict import EasyDict as edict

EasyDict可以让你像访问属性一样访问dict里的变量。

from easydict import EasyDict as edict

dict1 = edict({'name': 'Tiger&sheep', 'Age': 30})
print(dict1['name'])
print(dict1.name)

运行结果:

2. __future__

官方解释:

__future__ is a real module, and serves three purposes:
1. To avoid confusing existing tools that analyze import statements and expect to find the modules they’re importing.
2. To ensure that future statements run under releases prior to 2.1 at least yield runtime exceptions (the import of __future__ will fail, because there was no module of that name prior to 2.1).
3. To document when incompatible changes were introduced, and when they will be — or were — made mandatory. This is a form of executable documentation, and can be inspected programmatically via importing __future__ and examining its contents.

翻译如下:

_future_ 是一个真正的模块,用于三个目的:
1. 避免混淆分析导入语句并期望找到它们正在导入的模块的现有工具。
2. 确保future语句在 2.1 之前的版本下运行时,至少产生运行时异常(__future__ 的导入将失败,因为在 2.1 之前没有该名称的模块)。
3. 记录何时引入了不兼容的更改,以及何时将或已成为强制性的。 这是一种可执行文档形式,可以通过导入 __future__ 并检查其内容以编程方式进行检查。

应用例子:

个人理解: 

__future__模块包含了一些新版本的语言特性,当从__future__引入这些特性时,即使你当前的运行环境是较低版本的python,代码也会有高版本环境下一致的表现,即使用python2,也可以正常的运行在python3下运行正常的程序。__future__模块使程序更健壮,能够使用低版本的运行环境。

absolute_import(绝对引入)为python3里才有的import行为,即import一个模块会去引用标准库,而不是当前目录下的同名文件。
division 引入了python3的除法,即/代表精准除,//代表了floor除法。
print_function:python3的print是当做函数调用的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值