反射

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __author__=="HAI"


class dog(object):

    def player(self):
        print(' 在玩')

    def eat(self):
        print('在吃东西')


d = dog()
chioce = input('>>')

if hasattr(d, chioce):
    fn = getattr(d, chioce)
    fn()
else:
    val_e = input('这个属性不存在,重新设置 他的值value:')
    setattr(d, chioce, val_e)
    v = getattr(d, chioce)
    print(chioce, v)

    delattr(d, chioce)
    print(hasattr(d, chioce))

import sys

a = sys.modules

hasattr(sys.modules[__name__], 'aaa')
上一篇:[hadoop3.x]HDFS存储类型和存储策略(五)概述


下一篇:[hadoop3.x]HDFS存储类型和存储策略(五)概述