python - Reasons to rename property to _property -


i reading source code of collections.py yesterday.

in namedtuple function, template string generated , execed in temporary namespace.

in namespace dict, property renamed _property , tuple _tuple.

i wonder what's reason behind this. problems renaming helps avoid?

in general, underscore names used in standard library to keep namespace clean.

in case of _tuple, necessary because you're allowed use "tuple" field name:

>>> example = namedtuple('example', ['list', 'tuple', 'property']) >>> e.list [10, 20, 30] >>> e.tuple (40, 50, 60) >>> e.property 'boardwalk' 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -