pythonbook/Python高级编程/对象属性管理3.py

34 lines
667 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class People:
country='China'
def __init__(self,name):
self.name=name
def people_info(self):
print('%s is xxx' %(self.name))
obj=People('aaa')
print(hasattr(People,'country'))
#返回值True
print('country' in People.__dict__)
#返回值True
print(hasattr(obj,'people_info'))
#返回值True
print(People.__dict__)
class Foo:
def run(self):
while True:
cmd=input('cmd>>: ').strip()
if hasattr(self,cmd):
func=getattr(self,cmd)
func()
def download(self):
print('download....')
def upload(self):
print('upload...')
obj=Foo()
obj.run()