Python/Code/Python10Code/com/twowater/mtest3.py

17 lines
364 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
class User(object):
name=''
def __setattr__(self, name, value):
# 每一次属性赋值时, __setattr__都会被调用因此不断调用自身导致无限递归了
# 会造成程序奔溃
self.name = value
if __name__ == '__main__':
user = User()
user.name='两点水'