Message353844
This is nothing to do with platform.system. You can see the same behaviour with any string comparison, or ints.
The `is` operator is not a cute way of spelling `==`, it tests for object identity, not equality. It tests whether the two arguments are the same object. The Python interpreter caches some strings, and some ints, to save memory, so the result of ``expression is "somestring"`` will depend on the operating system, the version of Python, what happens to be in the cache, and whatever memory optimization tricks are being used by the interpreter.
Never use ``is`` for testing whether two things are equal. Only use it for testing object identity, like ``obj is None``.
By the way, this question about ``is`` has been asked many, many times on places like Stackoverflow. If you have any further questions about this, you should check the answers there. |
|
Date |
User |
Action |
Args |
2019-10-03 12:51:19 | steven.daprano | set | recipients:
+ steven.daprano, xtreak, Светломир Балевски |
2019-10-03 12:51:19 | steven.daprano | set | messageid: <1570107079.14.0.955782891773.issue38362@roundup.psfhosted.org> |
2019-10-03 12:51:19 | steven.daprano | link | issue38362 messages |
2019-10-03 12:51:19 | steven.daprano | create | |
|