23.python中的类属性和实例属性

  在上篇的时候,我们知道了:属性就是属于一个对象的数据或者函数,我们可以通过句点(.)来访问属性,同时 python 还支持在运作中添加和修改属性。

  而数据变量,类似于: name = 'scolia' 这样的形式,会称其为字段;而类里面的函数,又称为方法。而方法又分为实例方法,类方法和静态方法,这些我们以后在讲。

  我们先来看看类里面的普通字段:

class Test(object):
name = 'scolia' a = Test()
print Test.name # 通过类进行访问
print a.name # 通过实例进行访问

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXYAAAAqCAIAAAAoB+cKAAABTElEQVR4nO3cy3HCMBiFUZWlhuxy1I2rcTFkgd/k4UVuklHO2QBiMKy++a1hVB4AMeW3fwDQM4kBgiQGCJIYIEhigCCJAYJSiZlbLaWUMk6n5Wm8rgA9i04xr0GZ29Dm5FcCf8oPJwb4XyQGCLqVmGksi7re5qx7LXtDlpV6uBE6J2a5yik6r5cBenInMe9tqdTn0vbW3Gpt8/74wQcvK9tL8w706eaN0nMC2eLxSTuOb32ZmOOAJDHQoVtTTFvScpxZtmftG6aY/XpAV+4kZtswKacB5bw5c9mLOXxmXdoHlkNOlvFoGOp5Gwfogn/3AkESAwRJDBAkMUCQxABBEgMESQwQJDFAkMQAQRIDBDlYEwhysCYQ5NQ7IEhigCAHawJBDtYEghysCQQ5WBMIcrAmEOTfvUCQxABBEgMESQwQJDFAkMQAQRIDBL0BdpjSDO+eqGsAAAAASUVORK5CYII=" alt="" />

  我们发现都是可以访问的。

  但是,如果我们试图修改这个属性的话:

class Test(object):
name = 'scolia' a = Test()
Test.name = 'scolia good' # 通过类进行修改
print Test.name
print a.name

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsAAAA/CAIAAADmNCqDAAAEsElEQVR4nO2by7XbIBCGpyxKSCOmDLmCsNMmSQdsL3tVoQ0duAllwUO8JHNlyxnH/3fu8bVlYEbwaxghQ78A4AQtAHACigS8gCIBLx5WpJ2EmOyjrcySBiJtHm2nBX8PX4PR9IR+eIqtmxK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XfChY26qPuFpCCCjyDdlXZCsd9OMcv7JKCGXX/xsViyPx404kq8vUtnaPQJFvyN1Z2wecoLUdqaVf3VVkGv82dRPjaDBf2+p5A96JOzFSlVJYI49V6gkxci+SNSN0d4w0Eqs/78i+ImOQoiz85YllkckldcKhJB1MdvK64Hu5iDwFTakr9ueRUkqsSL4hnJ/Z7KcB4P+EsyJb4Rb877BWJPhAoEjACygS8AKKBLyAIgEvoEjACygS8AKKBLzArgbAC+xqALzAb8gBL6BIwAvsagC8wK4GwAvsagC8wK4GwAvsagC84PzMBrsaPhHOisSuhk+EtSLBBwJFAl5AkYAXUCTgBRQJeAFFAl5AkYAXUCTgBRQJeAFFAl78BUHHGuqahMkrAAAAAElFTkSuQmCC" alt="" />

  我们发现两者都修改成功了。

  如果通过实例来修改属性的话:

class Test(object):
name = 'scolia' a = Test()
a.name = 'scolia good' # 通过实例进行修改
print Test.name
print a.name

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAAvCAIAAABv6OZwAAABtUlEQVR4nO3cy5WCQBAF0A6rE5JwyIZoCGZmIfIfxjlHa0q4d6MW8lm9U7RY5QsgUPnvCwCuRegAoYQOEEroAKGEDhDqxaHTt7WUUkrTLcpds64AF/WOTmcbMX17a/s3nAn4ODGhAzAQOkCoo9DpmjKoj5ujx5rNlCpDpc5un5ahMxxlEUPbwwAXcRA6e0sz9V4aN/VtrW0/vf6w46oyftQTweUc317du5QxTg7SZL7p19CZN1FCB67lqNNph7CZ9zXju/YFnc50POAqDkJnXHgpiyZmucizWtOZ7fMoTU3NLGCGFup2q8vlIODsPJEMhBI6QCihA4QSOkAooQOEEjpAKKEDhBI6QCihA4QSOkCoU44rvV+Ff3VBRmcdV2poBiR11smBGa4B2CF0gFCJx5XOZmKUaf7O8lzbyjA0o5rUAzmlHVe6/c72XIcVoQMp5R1XOnZDdT3A8E9vgFzSjivd7bOe7nS6xk/mkFPicaXbHZ9f02maxpM6kFLaJ5KP79eAT5U2dPaaJuDz5Q0d4JSEDhBK6AChhA4QSugAoYQOEEroAKGEDhBK6AChhA4QSugAob4BTn1JzmQ4HjIAAAAASUVORK5CYII=" alt="" />

  我们发现类的属性没有修改,而实例的属性则修改成功了。这究竟是为什么?

  其实这里的情况非常类似于局部作用域和全局作用域。

  我在函数内访问变量时,会先在函数内部查询有没有这个变量,如果没有,就到外层中找。这里的情况是我在实例中访问一个属性,但是我实例中没有,我就试图去创建我的类中寻找有没有这个属性。找到了,就有,没找到,就抛出异常。而当我试图用实例去修改一个在类中不可变的属性的时候,我实际上并没有修改,而是在我的实例中创建了这个属性。而当我再次访问这个属性的时候,我实例中有,就不用去类中寻找了。

  如果用一张图来表示的话:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3YAAAGJCAIAAABJlDY/AAAgAElEQVR4nO2d/dPtVH32n79pYe0pvgGiBzrSwW5b5hQqFC1TB6YWQgveDvJAkcpLXwgtVTt6fkDrCHbOfoAqrTj0CIO0SrvteFpKdTpayiCWt7sqlEHy/JC9s1eSlexk7eTKSvK5fjnn3vvKypXku5LPXivZ+/8cHh7+13/9V9JYh4eHIZjJrDGTWWMms8ZMZo2ZzBozmTVmMnub/w+IKTOTWWMms8ZMZo2ZzBozmTVmMmvMgWQGMXVmMmvMZNaYyawxk1ljJrPGTGaNOZDMIKbOTGaNmcwaM5k1ZjJrzGTWmMmsMQeSGcTUmcmsMZNZYyazxkxmjZnMGjOZNeZAMoOYOjOZNWYya8xk1pjJrDGTWWMms8YcSGYQU2cms8ZMZo2ZzBozmTVmMmvMZNaYA8kMYurMZNaYyawxk1ljJrPGTGaNmcwacyCZQUydmcwaM5k1ZjJrzGTWmMmsMZNZYw4kM4ipM5NZYyazxkxmjZnMGjOZNWYya8yBZAYxdWYya8xk1pjJrDGTWWMms8ZMZo05kMwgps5MZo2ZzBozmTVmMmvMZNaYyawxB5J5jZiHYxOZNSKzRmTWiMwakVkjMmtEZm8xiqkzk1ljJrPGTGaNmcwaM5k1ZjJrzIFk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dWYya8xk1pjJrDGTWWMms8ZMZo05kMwgps5MZo2ZzBozmTVmMmvMZNaYyawxB5L5/wP/P21M26ZZTgAAAABJRU5ErkJggg==" alt="" />

  函数  dir()  就能查看对象的属性:

class Test(object):
name = 'scolia' a = Test()
a.abc = 123
print dir(Test)
print dir(a)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABPMAAAA5CAIAAADcPvk4AAAOaUlEQVR4nO2d0ZWkthKGicROgxA2kVEYdgYkMGmM3h2FH0wCN4d94D4A3UIqQC1AlMT3nT3rdZ8G6S+VqlQCzTRDXVjzV9P83bT/9NMH/5rmr6b529hbuwUAAAAAAACn8v39/b+Z5u7OAAAAAAAAAHwMlS0AAAAAAACUDZUtAAAAAAAAlA2VLQAAAAAAAJQNlS0AAAAAAACUDZUtAAAAAAAAlA2VLQAAAAAAQG38btucf+6Wq6KytaZJ+BWzaVc9mVrtjK7jV2mjDu11qEjjydrTqNVitepK48nWqEN7HSr0g51djlrj7Goz6E/ftU3TNE1jLJXtiDVt12e66nZch7BmdIRsTWeyc5quZGtk9p+YEHNKeNU5L8YAJqubg1ut2j9Fp4qtETyPJ2tPQ6fFjlOrrjRut8Z5S/+Pw/3t2k9BlYqoVdNJeTlxhWZNEeu6hJYOmDT73Dm/spX703cdle0wDEPftQkjlnaVBvruy+14th2mzHbOtt+W33+8EUz+zt4d9M6L7WE67tKatcejWcXVYefJ2tPQbLEj1KorDQ3WOJ6b5vu040SKnFAatB9HoYpI+5+0217tui6BZJPeMHdOrTY3+lNvZdt3nb51w8fEqAi/87n22LlRmlV5k8SntBHc4OrKFq7myWP0ZO0wkSu/V0yR86jGEayysi2CZF03GCRXtVltZVuHE6e9cZqgPWdUygkR0KMmaVS2pfPkMXqydhjJlt8rpkRrlNjnXahs74LKNqTkyvb1HNo5MzwMw/weftOcdNbuGsJOTjJmWZKKfaXLT36m/zV2utL9jmsZaxpjzLv517v775f4Rat6fVaHNY3putbtom9DV9n0JeEqXfgjOJ08WfQ5H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v4Fcixyva9SzFt6Hx9tcFr5IcG7srX3pz6f+qj8E55oCJKqfOJ08oiFwS7QF1nvXMe81v6xjmVELR1znvwl/6ONdcOr1j8tuF/7okDY1evSuvARf7jj6DQ5x9hlAfN82LsmXPOxHPwYDff8UzPV90zJGef2cjrq8JhFGOH4+8iX6NCjDaDZPm9EXTvVsYIatC++I6dp5A9/JD/XotZMx55WoZn/6q0HlyV372csvzs6vyeSEZrSCsQQUloMS8XODc+1ve8nlDBCApRS1hDenFMzss767Gw9e1c6Zhg+ckrDvZdqzEeTrcO8vtaBpkt9r3U9RMZV7PPHfmZ7Xvc9/3nSOtBw5t1wR9/vl1bWIvuuo+i32cb0h9/MrLO9oO1R3GpnW8EXfVRh/Y6VKTxZO1p3G6xi/Lj7bpU8WRr1KG9DhX6wc4uH1hj72cjX9t6JpzSN0Nl62xiTPz65X9yVu6MbUveviobjXamree1pa0/17VVhwr9/dGvPab1Ii1m98/GFanrMp5sjTq016FCP9g5aw8vqGxVo/aZLQAAAAAAACRCZUtlCwAAAAAAUDZUtlS2AAAAAAAAZUNlS2ULAAAAAABQNlS2VLYAAAAAAABl87ttn/ZnoLIFAAAAAACA0qGyBQAAAAAAgLKhsgUAAAAAAICyobIFAAAAAACAsqGyBQAAAAAAgLKhsgUAAAAAAICyobIFAAAAAACAsqGyBQAAAAAAgLKhsgUAAAAAAICyobIFAAAAAACAsqGyBQAAAAAAgLKhsgUAAAAAAICyobIFAAAAAACAsnEr2/8DEWLFN5ItMKUAAAAASUVORK5CYII=" alt="" />

  它返回一个列表,包含所有能找到的属性的名字,这里我们为实例 a 创建了 abc 属性,这里就能看到了。

  有些同学会有疑问,为什么我才写了几个属性,结果却多出一堆我不认识的?

  因为我们这里用的是新式类,新式类继承于父类 object ,而这些我们没有写的属性,都是在 object 中定义的。

  如果我们用经典类的话:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATsAAAA1CAIAAACxw9tUAAADVElEQVR4nO2cy3njIBSFqWSmDUpII6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LIAmcCyAJnAsgCZwLIAmcCyAJnAsgCa+AVf2Apc+arNNAAAAAElFTkSuQmCC" alt="" />

  为了方便演示,下面都使用经典类,若没有特殊说明,新旧两式基本是一样的。

  其中 __doc__ 是说明文档,在类中的第一个没有赋值的字符串就是说明文档,一般在class的第二行写,没有就为 None。

   __module__ 表示这个类来自哪个模块,我们在主文件中写的类,其值应该为 ‘__main__’,在其他模块中的类,其值就为模块名。

class Test:
"""文档字符串"""
name = 'scolia' print Test.__doc__
print Test.__module__

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALIAAAA3CAIAAAAnlYdUAAAEPUlEQVR4nO2cy3HrMAxFURZLSCNmGXIH3Hn3OtA23LsKLcIO3ATfQqTED0RB1ifOzD2T8egDURBwCVDOJOT3455KPd3eUQZNHVFvD3Co4vM9vAbbkywOtGbwMqojuhPdSQ/LNg+T3M3qeAnd9YYoDvqNoLunoi6/V+JziELp4bu85eGJSLKTGWsbsqOtd+axdOGKLJx5KPPy3ns/6GWhJWY+GI/hc0/VjKMzz+TsG0F/mVv0yvZxKg8m+mzjcJWHUnZ7eCLC7ATmUjE9xeLjrMginWRJgKrhyiotlEUxzhtBTy8pL88y+mYf2e/hebyk2QnGXaymu2Uhj4LVXdIvxjY8Ffawq+04p+9E/XfYGH9mL415EN3nmR16xPj8obuXNqNhVbFMbpB6aHVH1GvdxXGu8DCDuephXL58yWxqtmg0W1Uwspj7vnq6A2XhbZ90qdrjucpZU/s37XYxSePxOCHmuV7beM/2CPsso1l62Gmbj3ymhznTRJ9u+jKqt2lPZGwK5LJIS4XnZFEOtaGJePdqFuFWPfdT5mzP+bfqbutJrO7qeWl1HTLWw/ngeR5yseryOjQeTAsDa5PykmanfAFhPZwqlvfblpxra92kSi+2N2KjbIeFgLJzMbNx5jFlca2/Fh4WI5/lIUeS0ZDOWC3UdEltUyLLTlEq8mevFumjz/IXVMHKK1TpeEld+myfT+toqYd5cuhh6u5x0Vr04NTm39c8pe5c+2Q9DKFRKq4nTvSw/2admd6rp5HV0xVfjWQ2LILscN9VhFdT9pVeD14gi00UZbCEK+wXM3m4VE5+3cNjqUuFiGNlsUSyzv8MwsI7qy6f5eHvco0swB8DsgAMkAVggCwAA2QBGCALwABZAIYNsiBqGRdnG8byU+07SgzAe2wL62pGJ4N6QzIOJRS76YBLbHoW0GB9OrZJLdONWiWr47Aj+GYJWdoGOxGFso54kY+GSpZGkJ9t3/q9QUCbA2SRHjmktrclJSldYCfSULbnZSMrS3VlKZeSI5JTYA9HyoJN0qakpusMVkCNUoGCcSCbm/rSbJ6OC1O1Og5rSWv9RfYoYIWDX1CXjstneS0OyOJ6DqgW6VnhcYm86g2PJnIV0jeROje1jV9IGztg416NI6gW1yD6OktySlgtVqc1WxskxuBAEFbAAFkABsgCMEAWgAGyAAyQBWCALAADZAEYrpSF1YS/8fwbXCkLZ25H/Lc7cD5oIoABsgAMe2XhjCJSShGp202Ril3CGTX+lkvH/2+V7sV9bYwimq8CH8L+amE1KeOmzzHx9YavlpxWB0FgKfpxHCILbbPPeJioqhCFLGrpgI/gJFnEDWcUZPEHOWRtQVrr6TMsFMZqoW43RaTMz1w8RgnE/VFLWVEBvw/eRADDiizmOR74+iqPHDXL7YX3AiugWgAGyAIwQBaAAbIADJAFYIAsAMN/1dCaonR9WYIAAAAASUVORK5CYII=" alt="" />

  文档字符串不一定非要用三引号,只是一般习惯上用三引号表示注释。实例也可以访问,实际访问的是创建它的类的文档字符串,但是子类并不会继承父类的文档字符串,关于继承的问题以后再讲。

  除了这两个特殊的属性之外,还有几个常用的,虽然没有显示出来,但也是可以用的。

__dict__

class Test:
"""文档字符串"""
name = 'scolia' a = Test()
a.name = 'good'
print Test.__dict__
print a.__dict__

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAABOCAIAAABXBOWIAAAOSElEQVR4nO2dy3HrOhJAEcl7aSCEl4gQhhzBcOfNzGSgrbF3FFpc1iTgFO6Cs+APf4IgSOqK55RLZctkA/0h0GxAlPgfA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PoES2nrtbOrTJUXAaf62ZgKhTO/pV/SylqQYAEAAMDeCdb4S9vIaIJlfEyvbfepYE2sqWBplUz4SLAAAAAgzJbnYLn/UlMRavhV6eltebtJIf76WwihlJpe55RmuYBVtMndqI4NJ+fvwRo6GmmT52ABAABAhC1Pcn99zJys7ocQeZI7AAAARHnz7yKcSmP7fEYxwJ9lHwAAANiDN0+wjgf7AAAAAAlWZbAPAAAAkGBVBvsAAAAACVZlsA8AAACQYFUG+wAAAEBJgsVP+mcPPwEAAMAfxOoECwAAAADSkGABAAAAVIYECwAAAKAyJFgAAAAAlSHBAgAAAKgMCRYAAABAZUiwAAAAACpDggUAAABQGRIsAAAAgMqQYAEAAABUhgQLAAAAoDIkWAAAAACVIcECAAAAqAwJFgAAAEBlSLAAAAAAKvN/E9xTnnec/x0AAAAASUVORK5CYII=" alt="" />

  这个属性就是将对象内的属性和值用字典的方式显示出来。这里可以明显的看出来,实例创建了一个同名的属性。

  我们也可以使用  vars()  函数,传给函数一个对象,其结果也是一样的。

__class__

class Test:
pass a = Test()
print a.__class__

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAP0AAAA2CAIAAACDeAjcAAAE90lEQVR4nO2cy5HbOhBFOyyEMIkIYVARGDtu/F4G3E7vFQUXRtkBKAl4gf+HEimR0nhwT7lYEt1AN4DLRoOeMf0BoD/o3QEA8AboNwD9Ad2DHoHuQY9A96BH6CcA/UEGgP6A7kGPQPegR3bSvb4IcdHP9jJLGogm3iOikq8f4WvgiXaYh118XZW4PZmzvD/Va2warNG9je9MdCY5L9uMKhkiS9+EznJDXA8NQ18EDbmvJGY39WWEj/LgRB/GmtXJjCW71ZFstBrXNXwwML8cS5N2ezKv6nT3EV1j0+C+7rUahboaY4yZ5fLjm5gZZ2yHpC/iplC0uiR/+4CqkpHz5PPHrHzM7LurIlzL0xEeyMrVccQEHEZx2HDSZK8vgoZW+nvRZOYraMwa3adpMmlfRVwWEit1X/TzwESkTcrm2YAfLHWej/A4rmtXx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zrm+/9ibe1/2w7FYB/nr3qe5JShmusLMgV/STUryQFSzYxJduHZUORXT8k/iiRpvLyeBG+p378TST9zvgG73MA2Mya/z+n4OOjvLNXtuQX+gJdg3wPegS6Bz0C3YMege5Bj0D3oEege9Aj0D3oEege9Ah0D3oEugc9At2DHoHuQY9A96BHoHvQI38BPBTKxnjrCYwAAAAASUVORK5CYII=" alt="" />

  这个属性只有实例中有,它表示创建这个实例的类是哪个,这里显示是 __main__ 模块,也就是主文件中的 Test 这个类创建的。

  但是其返回值并不是字符串,而是创建实例的类对象,但新旧式类返回有点不同:

经典类:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMcAAAAcCAIAAABanjx9AAABzUlEQVR4nO2Z0ZWEIAxFUxYNTfrYBqhmaWYpZvYDEIQg6omL4777pRmEGB4hMvQGQBua7QB4IFAV0AeqAvpAVUAfqAroM1dVjondVA9G3N/DOzJbVcb6zRbeGiIi/al13O22VNLYQ9CyoSrH165Sb83OGbsoYfS69dYEu+zh1XF5AD1V1RH31s4L5R+r6roH/wuiqpbFujA3jndT1Rs74zaCquqAhQokwt/pnt3yE38xETEzEVF+ONZEB8OfKqlixtvEWTfJPqbRWkvjj+PW5+Llxn4iYXVoVSWu4MqYhedsuHAcpiKXIsvVoWXtrQkjrUvmavR4215svEXyJ3vY+rwRgRbsg13EHXA8SXEicuEqznTOcLujv0fTZd9VtirVUVk2tNhT7VE/QWRntZ5unUvGsJ2Uk1plgiIDeH88V5XfBx1nctuUMQuhNBYxV1UWcbhhcEDNzpMF6dhotbM5JmPMuolQIe0g5aHQ+dKHUP2Y18sQGftTtopjtRahrrLWWdM6OBANThaGnD8FXQf3Qcs3p0BwkhOqEj6ToumzP7aXYu2zX+MO4N9loA9UBfSBqoA+UBXQB6oC+kBVQB+oCugDVQF9oCqgD1QF9PkFR+wdzSLpeeYAAAAASUVORK5CYII=" alt="" />

新式类:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHQAAAAWCAIAAACexC8hAAABIklEQVRYhe2X2xmDIAyFM1Ymyh5dgGmaaRiGPlAuoi1qORT9+J+QIgdOk4DkJjDo3wu4M9NcIOOYq0KiF5u5wkjmsrEXm7nCTnNVsP+9NQwyYHtm9H48e8wt08oa0y3LYFo9akXVXGu4WETPEgbVgpeLirmlvgol5BmeReNP8hAiEhEiovSyNbzsqNNBax05Tflu7mbgFJ3JfzW+oeItSOUuto4GC1oLm4XVsrCWX5dgZmOzMyIOyBspBo9sBqoFr28nDrTwqBo6fR7GMSo+JTeiyTlrz0Rue60hDjRPfnV5l7QP+er8hpmXQ8JLB3eE0hrnKlZnuVZsUPTU+pEfzc1O8KKr/S2np1Ybxvn8vSHTXCDTXCDTXCDTXCDTXCDTXCAvjgNi8xY80qIAAAAASUVORK5CYII=" alt="" />

  因为返回的是创建实例的类对象,也就是说我们也要用这个返回的类对象再进行实例化。

b = a.__class__()
print b

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQkAAAAgCAIAAACO3hp5AAADH0lEQVR4nO2Zy3UkIQxFFRYhOJEiDDsDojH7iWIWJpieBV8JQX26bNNz3l30aWM+KqEnRDU9buOvpXeiD+vvm/I5vH0n+iDzJ6SG5SwEK0O/bQAAiwJtAKADbQCgA20AoANtAKADbQCgA20AoANtAKDzA9rwll761zZviUh/hFd/NDBDaMPb+/c6uM2F/W7niAGb+Pb4HGkgOLOINoIzRERkJq7u+uSG7ELmVOMCa8kPOvI8C506c2lULPyOaLuRVhsvlAWDc74Y7N057cXBZ7jTM+dX3x9VNertSB1dnyZneZuDOD9pcEa01JmrN5Lnk1yYDMpaZT7NwqVDrmhjnRR4BO9Tnovb5s9YfmE/btzCa1PNRwVnTA1zXRyyzxebs3xvYjl1b/7FWoRJ6mzp++fMwrGaf5ukjbMGBmeIjDFEZtuMckrXtMEySqrdnTM75/8huohJy9eJawFg2gy3V4rJebwla606dV9INI8l3HFs9YEPJ6P6WPTZ2OTwz2HsphWbM0FUPp1sqkEjbdRzIzizu/qyaTlq41oqja6Pn737Rr7wttayT7pEzFC2WGS4+aiePA/LnWQ9T75yqn71EiLTyBiad3yU2jNGXCmchrPxZ5qeG+zL5NxoJLZtZlcbq1ZWpaY6a1/roGZsTXITbfR7fw1Fddrq4oi6EJ0jm8WWi9WvKfOIDwWjiiVmrlmftsfOsytqaavZgYWpeVpTLSmMxxN3cVUb/U2un/b7tNFsQAhxF12Ngc6e4S1FPTdES29Av3pbWrjDq099OBil3XTzuZH/0/dpa5ls4VAJvO7Kj7W1OlRvL+wU4xY+VhbG4/I73FgTxxo8fjbVRzpKybgvL94B5r+joOZFvzBM9tTeWspSXb6kZI3zRMzvG8752MQHcavk6lr1fmR17sNwaJTwhs9b4psfZ7Q+hXQ7F2ef3D85rLtH8ZU077zmO1xwEpbawf+Gqg2eUYiI3t5ky10x8ZNr3UWxedW3j+AOcG4AoANtAKADbQCgA20AoANtAKADbQCgA20AoANtAKADbQCgA20AoANtAKADbQCg8w9iA0pkYUwYRgAAAABJRU5ErkJggg==" alt="" />

  这里用的是新式类为例,实际上新旧式类都能这样做。下面是旧式类的:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAAgCAIAAAAnqtLtAAADdUlEQVR4nO2awZnjIAyF1dVSwnSwFURlZDrgtlXsNdy3ihxCB9NE9mBjy0hgkjghnnn/Id+Mg5EEPCSYoetDnJn++Fj8OvDf8JiBh5k8PDMZzryBh9vy5d2RXxTSK229GxvGfqZNutH9Mh2JPt9nhgIfiT7J/Us7xtt5CH4mgY9PEiEAoBWIEIDOQIQAdAYiBKAzECEAnYEIAegMRAhAZyBCADrzYhEGpt39eXyPPoM9URFh4O3XXvSHyn+53UlgmtmJz72J3hERkauEptqkB2mYxe+i2fR0nAoxPWJysq1N2bLeesaKfAdKItzR9h+9D5PDwd8mmOHl57nVi7r16N2kkJIMVRuxGQUm4tM1hqDeDZyEFJj4JA1E76ZFFb0T6lK25l4GW7MMd7Msb8AU4TwmeyCEcJ2nZ/it+d2nTWrf5VK3Hr0TGcdWYd7msuhzEJgWoXyr6lRgYk6JTduqeFjeNnaLIcJbo4zeETnniNzh4IziZVmWyHkgIvberZRFTahlN5qfO54LnOFZSxXb5nNLz8vRKMSeD5kRhaZS/hXi0nIa3nE+jo6dVBvZT5JI8IdDKkinyMegVPGpi9FprzdtTWGoEPaVIxrQIrxjCx+Kh+kzG9nKdAYeZ+/xvKHPGGlZiOpImWixu+pzS8/msGT9TOWafJJFUXGvJpuyb9IWh7nmLPa2SFJe7ENjtkwbhk6Kczfjd6notGyl85+VW79bUWqWo7cGObSXn+mxPlqvLM27MaRiWc+yyn0iNBf9Ws/5aNR3q0oUloMr45xRKvbESazQRrZQTvBpkaTMcLIsR2QVn7r0tcb/+7DJxYwpwvSDPI6/ToRiXmMctnY/LyS971ZOkus5raFnPRq6n/m7dK2ioyi7Z45zIS7rYiZlwvSNbiMVFr1fXLqIpCYz4cVqs7zicT6aFzOyjv+JFzMDrRfCw5mEmafPuQCk8aBIzl/E9ifORTQqt77ZZ47lLa0L9/yolN+vLx6WLDf4fGrsWY7Gr8NvM/bUfe2UWHIyjXOUrxXfykYspGkbz4Sh1EZksOXpV18FyOtNGYOsGqYjaOXPITJTf0MFXvEfMwB0Z1WEy/2PiOjjI3+y1f70SlsAvAvIhAB0BiIEoDMQIQCdgQgB6AxECEBnIEIAOgMRAtAZiBCAzkCEAHQGIgSgMxAhAJ35D8xFAh7Kj763AAAAAElFTkSuQmCC" alt="" />

  但是,这并不意味不能通过实例来修改类中的属性。我们知道对于不可修改类型的‘修改’,其实就是重新赋值。这个也和函数中的局部作用域和全局作用域类似,我在函数内部尝试‘修改’一个不可变类型其实就是创建新的同名变量。但我却可以访问全局某个可修改的对象来修改它。

  看代码:

class Test:
list1 = [] a = Test()
a.list1.append(123) # 同通过实例修改类中的列表
print Test.list1
print a.list1

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARsAAAAzCAIAAAAoxzuZAAADqUlEQVR4nO2bzXnjIBCGpyxK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E1QFIAmKApAExQFoAlPeAE04VQ8gCacigfQhFPxAJpwKh5AE07FA2jCqXgATTgVD6AJp+IBNOFUPIAmvDMBoAnv9QFogqIANEFRAJqgKABNUBSAJigKQBMUBaAJigLQ5DdtXM4YDrbwMAAAAABJRU5ErkJggg==" alt="" />

  我通过实例访问到了一个对象,这个对象是可修改的,所以我可以修改这个对象。这相当于直接操作那个对象。

  但是,等号这样的显式赋值行为还是创建新的对象:

a.list1 = [123]   # 显式的创建一个新对象

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAA6CAIAAAABREMXAAAD2klEQVR4nO2dzY3bMBBGpyyWkEY8ZcgVhDedkg50Ne+qQhc2ELgJ5iD+k1rIBrVeDL6HwLC0Q3JEPY8oa5GlfwF3DqbFnIs0PHEK3ZgmojvRnU3aZOOcWYjuRMvDv9n/7aNsTIvWM9Fd6afvya6KJqJZ29hPE7MH6rncs+kyIM/Q8ES0ME+hn+/IsKDTatbWNzedmJbt/NlxZiG1hm5iw9SDYX++Ulg+epgT43cet6rH2qf9qVWW6t6bmhUtf/RMNCs1kVpuavIzFodLCTezusdcJ7QzC/EWNtq53jgcpNHtzKa8g177/qdWs7bO2VX55m2Mcx2bnTNr7UGd4cSm7PnKDEtCqzTofsqf+haHbmMqzgv91KoqN5XQbVft6BvTVIjbT6Aay/djOMiazxgtD7ex/yTvr7nEX8+8c257WehwVM455+yzXyk6GXQO1Ttnlt7MVpsvvcknK2G4netuhmnndRn25moqa/++My/G3Zic59mzU5bMgwzjVeJo9O7hVK26Y1VVvBj94Tfz1yrJr3J+Weis8m2cyluf7Jp++NmlbpZmO1ChW/+KGKvn6J/V6xefqCbDquerMuyRuehFDBU6XZrbmJpzZ6cqmeWxh1R17Kc6rjR656rba1WOZddbqDWG9w5Dz2ah7xc6nON7/zRX+Gt6aNJeKM1SltIQyVv6KPNWLKE6a8085u+vVEjuvWViN8M9YFYqrJsvzDCesxLfKutZrTYsFk0npsuJs1OXTOecs3rO7nDyfrKx8tGz24lsfppW/fJc3F0YF5a/vDBNpH4T3ZmX+LpfJONw+T1YMavvraFfpLpo1vSWAd9MzPCohH88w7G05VnGWJ6rhT4i+w7hZ+Bvz4uK/rMyBGf4lNAAXAKEBqKA0EAUEBqIAkIDUUBoIAoIDUTxptCGiYiIlLbOWa32LXxnCz7Nu0Lr9vGf1RpCgw8DoYEoIDQQBYQGooDQQBQQGogCQgNRQGggCggNRIEnhUAU+F0OIAoIDUQBoYEoIDQQBYQGooDQQBQQGogCQgNRjHiw8h54HAMuYOCj7/fAA3MwkmFCG84qbay+sf6Gkt5UZAgNRjJCaC9r9r+M38JPDRPxwxmOaxOrVaE0hAYjGVWhDVP293f677s7IDQYyRVCJ6xW2W2j4c4tIIQGI7lQ6NLmo0AIDUZyldCGj77SqyIhNBjJJUJbrbI7RF3cFNamQ2gwkoHfcsRvOrLt+Owl7atWJhAajARPCoEo8LscQBQQGogCQgNRQGggCggNRAGhgSggNBAFhAaigNBAFBAaiAJCA1FAaCAKCA1EAaGBKP4DV9rbah58AeUAAAAASUVORK5CYII=" alt="" />

  这可能有点绕,需要对变量的赋值、可修改对象与不可修改对象的了解,可以参考我以前的相关博文。

  这里又有个问题了,我们通常使用 __init__ 来初始化时,会为其添加数据属性,例如 self.name = xxx ,但是却几乎不会为实例添加方法,也就是说实例中的方法,都是在类中找的。这样做其实有好处,因为方法一般是通用的,如果每一个实例都要保存一套方法的话,实在太浪费资源,而把这些方法统一保存到类中,用到的时候来类里找,就节约了许多。

  当然,我们也可以任性地为某个实例添加方法,python 支持动态添加属性。

class Test:
pass def fangfa():
print '我是某个实例的方法' a = Test()
b = Test()
a.abc = fangfa # 特意添加一个方法
a.abc()
b.abc() # b 没有这个方法

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhwAAABwCAIAAADaNT4jAAAP1ElEQVR4nO2dS3LDuhFFuZssIdyQsYvIKwhnHmWYocaYZaBNPFXqcQN53gQy4A8EGkCTgiSaPqdcLpkCuxugiIu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La85oqgc6ZO5jyO2KkCKXaJizcWY62oYHn/ud9wJj6QKjgs86VbMm7V3P12YtVsCeF7f8bJe6YDd36E+mfs4YKsCJNkjKnfTXG1/a6cP+vTk+SUt1frIH8Pj6xtz77uvdZn1YnGYZPduxgLzC8GXG2dOl2ZeARgzZYWOJu9yPIGdVBkVUS8QRriskl2GpXCxXqHVoMXG1fZb1/qP/ddYXidplu0ISZqjWogVD+xECaGjCAUjyXiy3iNfh/tkqtibQhvgEOwQlXEB9278/CXF8aC9Cp2IUGadZFfMkBicNS8oz3uV8Uwl9h4fmeysvKc6vjzKCPNnaSzb69jR5FNJxmcJSZrXduIkzXEtxPBS8WxKdinGo07pVkgs/cZPpobdKbQBDsEOUVky5nq3oubW3dfZFW9dL5648LgApVkD2df9iRQjdNN43B/D7hMVsX1KlvckaRZrkQrPvwRGUfeiHd1FkX0d55OpY28KbYAjsF1U+u66rLT4K07BLkJwRHnrxnOFcW1B6CZGy95XX/p+PYqcv8OjERVxplJFVIQIp7yQUpeU24kpd3YKy9OfqyTNwYs4SXNci0x40QvPlxRh0c6WmcriK657ujXkAOY/q3wyNYhXR5dCG+AAbBYVb4xpvW/Q90NyXG+F1zviLTcvK2bewXntOE6yO6wvX4y5LsYjX+v15fBLvbF3MZ7Jjr+nIpQpK80Unt/3hSvgY5lki4mELTYOhOc6Xhrzh9Kyl6T5H3//+Hdk5+65U6/jC/Hc174ubfeXHKHCjmZ/Yu1r7n8P8snU8kAKbYC3w3/UAwBANRAVAACoBqICAADVQFQAAKAaiAoAAFQDUQEAgGogKgAAUA1EBQAAqoGoAABANRAVAACoBqICAADVQFQAAKAaiAoAAFQDUQEAgGogKgAAUA1EBQAAqoGoAABANRAVAACoxv8BDnGg9iPcY7YAAAAASUVORK5CYII=" alt="" />

  同样的,我们也可以为类动态添加一个方法:

class Test:
pass def fangfa(self): # self 代表是实例方法,只能由实例调用
print '我是方法' Test.abc = fangfa
a = Test()
a.abc()

aaarticlea/png;base64,iVBORw0KGgoAA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+3/Q8w+JVaB+4HYFRH64rwp4H/R4NagBZBLUCLoBagRVAL0CKoBWgR1AK0CGphhxaJiIjmi4wBY8sy46XQEtyMokwzYaUX4q04svcjaPHnsK8usov0OlMXxU9fqaDgZryqRdEgM5KZzmwKxQpuw0FZlFc+ccGMr3JjcDPOrIvl6+QFLToFt+clLYYXhbVzKih+heuAm3H8nc6uVpv/dMse4vtRlCY730nZ4K6imA5mCjC4MaW/XaZEast1aJkOpqvlB7cWgRxvz+7zItOKeLu355YfQMujBf8dB3s0G2SFTdTQ1vRyhUGL9wbZBbUALYJagBZBLUCLoBagRVAL0CKoBWgR1AK0CGoBWgS1AC2CWoAWQS1Ai6AWoEVQC/8ADCBuJW6hAMoAAAAASUVORK5CYII=" alt="" />

  关于方法以后再细说。

  当然一般情况下我们很少这样做,因为这样会变得不可控,因为你不知道某个方法在你调用的时候有没有创建。


字段私有化:

  我们可以对属性进行私有化,以限制部分访问,但关于方法私有化以后在讲,现在先说说字段私有化。

  一般公有字段我们可以通过实例对象访问,类对象访问,类里面的方法也可以访问。

  而私有字段一般仅类里面的方法可以访问了。

  私有化的方法非常简单,只需要在变量名前面加上两个下划线即可:

class Test:
__name = 'scolia' # 私有字段 def a(self):
print Test.__name #内部还需要用类来方问 a = Test()
a.a()
print Test.__name # 在外部使用类来访问

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAloAAAB8CAIAAAA+U4m/AAAS60lEQVR4nO2dzZXDKrZGiaR7+FIghE7EZHHtCJqZR30z0LSZvYGTuF5vtSJoJ8EbSEL8g2X5r2rvVctly3CAI4lPB2QhbBktz3pcPoy3sZLUXpUYTOb9klufpb5ZMyiTzeJ/vOuNNeoo9S2qjVFxBQo1XDc+r4Y5Xx2FOAlxEkGVPG/n0/jceveOGYS8eN9mazgV5wympWebE+XKlrXYmbcHpf97/ui/RpWs1zmqUlKfop3QP5l90bnfQzt+280g9UWJo4idnPXqXQdS6at0h/bswXBjvAezpTSP3n0t1/dpvgcoNLN+v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jtB6RvW3Bgv0q3OWKpzeUHgonNKdHqjnitrdtq/lar21DC1k/q50qiKD9MtrzzG9qLh57/mVbLda7Q0NHfQADyXuhyuqxp5XU9PV7VhpfuersqrT5p4HkLsEZtt3X1Kn/wsIcgxaFd0vZ9uaRaXeqNkuXOw1HdmT52bdvrcmy/rc46xvWj4+a/g2s5P/H0riAF8I1U5HPWwBIVX5Y9PRjNY0ZbOriqNz+bxq0y3OFv2bqsbx/B6391V2COH2ehwQ1/jokP/doxCpzzq89LBLavVr11esiVLKY5ZvZGz05xxLKtFrc49du6JDteysnV+4zG2Fw0/F+TwefUBgICaHHrRgPF+xTVeZDRb5m3xJmPW8VVv4zIXZS7aTLnc7NT8oz2lhtV4UlY4Vxf//CAtPVufxY4/d5hJ06ORS94po5sKSps/TQgdpf7v0qhT0szqjygWV/i6Es9cZu2k+ytowBB6L5iKq9W5z07PvFdY1i1f57cdYzvR9vMff/v7SYhBKfc6t+4p9QGAGJ5KAwAAgBwCPMo6vTf9/SH+8We4hWk/gM8HOQQAAEAOAQAAkEMAAACLHAIAAFjkEAAAwCKHAAAAFjkEAACwyCEAAIBFDgEAACxyCAAAYJFDAAAAixwCAABY5BAAAMAihwAAABY5BAAAsMghAACARQ4BAAAscggAAGCRQwAAAIscAgAAWOQQAADAIocAAAAWOQQAALDIIQAAgLX2/wGdMNnnwlcNjgAAAABJRU5ErkJggg==" alt="" />

  我们可以看到在外部通过类来访问是不行的,但内部通过类来访问却可以。

  同样的,通过实例访问也不允许。

print a.__name

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfUAAABVCAIAAADfQeocAAAMpklEQVR4nO2dS5brKBKGWUn3sJdQLKE3YnZR9gqamUdVsx5qzKwG3sT16VNawc1N0AMB4hEIJKPHJf/v5MnjVEpBEBK/cMgmmAYAANAj7GwHAAAA7AL0HQAA+gT6DgAAfQJ9BwCAPulP38fXTX6d7cT3BqcAgEtwpL6rgbE7E++Vh73FiqPegr/G1Z51xpfkjzDU6Z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q+H4kso5sLb1/aoMHlW/8Ir6fqUrE4ALkdF3Je5CDMHkNB0A2xZorDmksprHTlqzbFa9lbdPdr3iDZY/4TDZvaC+X+rKBOBC0Pr+FmxQ44vHBS6iJXPnqhdVtff0NDzmin22ht/be0FX44ur39mFfKOGbOu0P5Gd3D5VJOM8qc/n0jhmhbWaKoM11QrrLIfVCmk7xJrG5SqDalisX0h7SBjJ+rNc4zBu63JXZhNQJxK0gdR3k7Z7C++6Kc+SamvvJRX7itWa0up36fw9bT3dYu0U6gXWUOnh8lE1lhfqBS4flVYpieyML+7Uv77KYKF+YXWJRNKf6OwsBGe5tteJV2YrUCcSNIDUd6/a3HyV1IyibbpTHEVp9Tu/eJ7KaMrCllVKRFL0UNtZmD+T2qbvZHxKluNqhTV9J3uRc88/BWllxNTDop26k0K3dZ0rsxWFOKNOJKiB0vdRDnMqwE+JRBnnaEvlKMpU7FOCGLHGclr9zpuw3HLz5XQLOX9vou+Ehy8TQ0odlrL2Zd2psGz/nKsVpnbc/N09M6ypMpiXP68tysOinTXz96AK46WuzFYU4ow6kaAGQt+9mZfyPhecVsjztlTV3tNaq5dUL+5vMVnFuxDDbDxpK8wUx59QTFsn/bF2/Pw7sU9Z9K17vgzFuWyzTzZiJBXVCn9UWvZrCv52+2++7mAhIx/6V6xfeOfyJ+1hhZ2a3HHY1hcd1dOuzEaU44w6kaAGfH8VAAD6BPoOwJHMKfIH6kSCnYG+AwBAn0DfAQCgT6DvAADQJ9B3AADoE+g7AAD0CfQdAAD6BPoOAAB9An0HAIA+gb4DAECfQN8BAKBPoO8AANAn/wfg2Im2H+0sYQAAAABJRU5ErkJggg==" alt="" />

  但是,私有化并不是语法上的强制,而是 python 隐藏了私有字段的访问入口,所以我们可以在新的入口中访问到私有字段:

print Test._Test__name

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUUAAAAfCAIAAAD/dEgvAAACL0lEQVR4nO3ay5GjMBSF4RuWQphErDAggtHOu8lA29HeUbBRBiShWfCSQLhpN6Zcd/6vurptWeiBOC2osqRDemcakVbEh6Wws8XbSfBiu+UQ84ibCsb1lcZtl1JnZXod/NJjfBhpRO4uplqdP7+GkuFn6fH5CIcKd2MakdaGosLZI/R/q4MZj8paNo84Hj5VLupUHVid4LcLEd19OGPT3Od2sr7y3se5tCJtdn42R637GqaTnxkfhmrSivVWGjG/RVpr/fzbuD7vzoads7quszOLfAXrs5jGY/zNNNP483XPz8bdxVRvp3aeg/Uh9SFkfa3XtHOuc8V1WF6Ze2MurrqUUpJ0vs5mHWwFW8vYpeYR1gP/ASM8V+9MYy+a0pV9fZoT576zFX3lHXneM/5//ZzFDnZ1B/FxI8T/aXNlHtFZaa7MM4D3Is+AHuQZ0IM8A3qQZ0AP8gzoQZ4BPcgzoMcb8xydERGR1bczgl2XADjHu/fnbXqjuz35MiiA112fZwDvQp4BPY7mOVgZmelueXo+XgI7lpjsfrrM89hKkfBtMwBeczDPtcdgMxTNH0VnjIvL350DVyXzW3Zy4KeO328Pe+uc1CdBzT/6Ms/51k+egR85uj+7Mcf5bjy/cifsz0t7AF50MM/zQ64UW2/5QL16fs6OmYqWrTjL7rjx326mfPQG8E18PwzQgzwDepBnQA/yDOhBngE9yDOgB3kG9CDPgB7kGdCDPAN6kGdAj38e6EUDw5Ht3AAAAABJRU5ErkJggg==" alt="" />

  其格式是: 对象._类__字段名;这里是类的私有字段,所以使用的对象是类对象。

  上面的代码使用的是类对象,也可以使用实例对象进行访问 a._Test__name 。

  私有化其实就是‘混淆’了相应的属性,这样做还有一个好处,可以保护 __xxx 变量不会与父类中的同名变量冲突。如果父类中有也有一个 __xxx 的变量的话,父类中的变量不会被子类中 __xxx 覆盖。如果是非私有的字段 xxx ,就会被子类中的覆盖掉。所以私有化也是保护关键变量的好选择。

  我们上面讲的都是类中的字段的私有化,同样的,我们也可以为实例的字段进行私有化。

class Test:
def __init__(self):
self.__name = 'scolia' # 实例的私有字段 def a(self):
print self.__name # 只能有内部方法能访问 a = Test()
a.a()
print a.__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WnNLZfCfg7qqvFn7Zb1rkgeM77D8CE/rtU8oD6f6ZAL8HGR5+NLdzfZ3FcbDCc64nlN+VQUKdUPrWsKLTgFHv7wXcujQMFTndPJ24GjyLucnsJO6poqom4iCic5rUOOhhDUhUWtCq9ZZXodWle0Ih5CXQ6LaWzbYqpxDwUgyP/mArKGv030ym/DkoLYAMqI8jEuWX9r72JXHaLWBQqPwosXYcHGoznj2EHuPUyY7heCmNVTmMH9XjeVMcNP8XXFQo8BOf1ezeNSHRC0EW62O5yrmJ3g6mcrJRxJ84SezFc8MagsgI8qDFxpz+ZDVNMJ93VaxEcahOv1InzbRJWVSNnVkIsUcumkM6I/j9smDWD8ly2Fo1Zqyi6VIZc9/BHEY1ziHRTt1D0X2dZ5PZisK9dwuqC1AEkkeenNb1jH89ZxgtT1IqWyEifCiVgsNfrQch+r0hkuX1Gg9ThFnD03kQcjhFANO6lxyOxblbqvC8vTfJbRqbGeePczbrTUhUdO9p+dLymHRzpbZwypk7Kk+ma0o1HPToLYAMoI8eOM+630fPA7n6aVUBQp1ztm7sXflp4wrqh9a3xbjka/1Knn41dLYu5ifyY6/9yBcU9aMKXt+Lxau44/XJGtMpCK06q9Ky34A1L9f/p0OklrYjVjnrxhs9UOZP+QcVtipWTdf+/qWa/Vln8xGlOu5aVBbABn+ahoAAASQB4BnsmwPfL5VUFv4E4I8AACAAPIAAAACyAMAAAggDwAAIIA8AACAAPIAAAACyAMAAAggDwAAIIA8AACAAPIAAAACyAMAAAggDwAAIIA8AACAAPIAAAACyAMAAAggDwAAIIA8AACAAPIAAAAC/wfB+sN1POkokAAAAABJRU5ErkJggg==" alt="" />

  当然,因为实例属性类中并没有,所以不用考虑通过类来访问了。

  同样的,这里也是隐藏了入口,访问格式依然是一样的,只不过这里的对象指的是实例了。

print a._Test__name 

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM8AAAApCAIAAAAd/uqXAAADv0lEQVR4nO2az5XjIAzGVRYlbCOhDKcDbr5tB74Od1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0tEDGeGPnqoN26ao7fNp8jYTVIadLL0yJ3hb7k/4ZFrUloorILZFC7mibkNt4qVsY0hZwTRvN0VLPuETkb8lCP0QtQn9ELUJ/RC1Cf0QtQn9ELUJ/RC1Cf0QtQn9ELUJ/RC1Cf0QtQn9ELUJ/fgHq1ic/jt1kIwAAAAASUVORK5CYII=" alt="" />

  总结:公用字段可以通过类对象,实例对象,类里面的方法进行访问。

     而私有字段则一般通过类里面的方法进行访问。

       一般不建议强制访问私有字段。


  关于类中的字段,和其私有化就先将这么多,以后有需要再补充。

上一篇:Unity3d iOS基本优化和高级优化


下一篇:Python下的OpenCV学习 02 —— 图像的读取与保存