Programmers disagree with the built-in functions of Python eval (). I found this problem when using the eval function:
>>> Class FOO: <br/>... val = 1 <br/>... </P> <p> Foo = Foo () <br/> Foo. val <br/> 1 <br/> eval_foo = eval ("foo") <br/> eval_foo <br/> <__main __. foo instance at 0x01c48080> <br/> eval_foo.val = 10000 <br/> Foo. val <br/> 10000 <br/>
Instead of class, the value is passed.
>>> A = 1 <br/> B = eval ("") <br/> B <br/> 1 <br/> B = 10000 <br/> B <br/> 10000 <br/> >>> A <br/> 1 <br/>
Think that int long float STR is a static (fixed length) type. When Python assigns values to these variables, it also allocates a definite space in the memory. After the value is re-assigned, when B = 10000 above, B has actually become another int object ..
However, if a class is used, it is only equivalent to obtaining a reference. Therefore, foo eval_foo points to the same object. Of course, the attributes are the same, and changing one will change the other.
In fact, it was later found that this feature was not related to eval ,,
If you do not want to obtain a reference, we need to use the copy function, including the copy function of the copy module and the deep copy function of the copy module ).