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

时间:2020-08-20 09:22:15   收藏:0   阅读:67
# -*- 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‘

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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!