Python基础指随笔

>>> def fn():
...     print("ok")
...
>>> fn()
ok
>>> fn.s=123
>>> fn.s
123
>>> fn.ss
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'ss'
>>> getattr(fn,"ss")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'ss'
>>> getattr(fn,"ss",2)
2
>>> b=getattr(fn,"sss",4)
>>> b
4
>>>

  

posted @ 2019-02-26 12:48  巨兽~墨菲特  阅读(124)  评论(0编辑  收藏  举报