python 使用@propert装饰器实现setter和getter行为

如下图:

python 使用@propert装饰器实现setter和getter行为

python 使用@propert装饰器实现setter和getter行为

use_cuda默认是false;这里强调的是在调用config.use_cuda时,参数值是来自于torch.cuda.is_available();而不是来源于参数列表

python 使用@propert装饰器实现setter和getter行为python 使用@propert装饰器实现setter和getter行为

另外python中:

1.单下划线_foo代表不是直接访问类属性,需要通过类提供的接口进行访问,也不能from xxx import 进行导入;

2.双下划线开头的__foo代表类的私有成员;

3.以双下划线开头和结尾(__foo__)代表python中特殊方法专用符,eg:__init__代表类的构造函数