Python "is" behavior
"Martin v. Löwis"
martin at v.loewis.de
Sat Jun 21 12:14:08 EDT 2008
> For some reason, stacking multiple statements reuses the same object.
Each code object has a co_consts tuple referring to all constants used
in the code. The compiler interns duplicate constants for a single
compiler run, resulting in the same object being used when the code
is put into a single line (or in a function, or module).
When the code is split into multiple interactive statements, the
compiler runs multiple times, and doesn't know anything about past
runs.
Regards,
Martin
More information about the Python-list
mailing list