【简介】python
因为python-2.x 并无locale这个层次的命名空间,因此临时变量有可能会泄漏,进而影响到了包涵它的命名空间ui
【看一下pyhont-2.x是怎么泄漏临时变量的】spa
python Python 2.7.10 (default, Aug 17 2018, 17:41:52) [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = 100 >>> s = [x for x in range(10) ] >>> x 9 >>>
能够看到列表推导中用的临时变量x泄漏致使变局命名空间中的x被污染code
【看一下python-3的状况】orm
python3 Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = 100 >>> s = [x for x in range(10) ] >>> x 100
能够看到临时变量并没能污染到全局变量、多亏了python-3的locale命名空间blog
【总结】it
因为 python2 ~ python3 多出了一个locale命名空间,影响是很是深远的;编写代码的时候要多加当心。 io
---form