首页 > 其他 > 详细

Config类中的属性在调用时候显示不存在

时间:2020-08-20 09:22:15      阅读:67      评论:0      收藏:0      [点我收藏+]
# -*- coding:utf-8
print(‘2‘)
class Config(object):
def __init__(self,GPU_number=38):
print(‘1‘)
if GPU_number == 147:
self.code_exp_dataset = r‘/code/CGVSNI/code_exp_dataset‘


if GPU_number == 38:
self.code_exp_dataset = r‘/code/CGVSNI/code_exp_dataset‘


如果属性放在构造方法中,需要用self.属性名,如果没有self直接是属性名,那么在实例化后,调用的时候会显示没有这个属性


或者也可以
class Config(object):
  code_exp_dataset = r‘/code/CGVSNI/code_exp_dataset‘
  code_exp_dataset = r‘/code/CGVSNI/code_exp_dataset‘

使得属性直接不放在方法中,

Config类中的属性在调用时候显示不存在

原文:https://www.cnblogs.com/baitian963/p/13532745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!