|
|
Subscribe / Log in / New account

PHP and P++

PHP and P++

Posted Aug 16, 2019 10:39 UTC (Fri) by h2g2bob (subscriber, #130451)
In reply to: PHP and P++ by juliank
Parent article: PHP and P++

As NYKevin said, the problem is that comparing bytes and unicode will return False. So you'll find this code the hard way:

enable_foo = b'true'
if enable_foo == u'true':
...

Obviously enable_foo is from one or more read() or recv() in a different module. Or from ctypes. Or from users of your library code.


to post comments

PHP and P++

Posted Aug 16, 2019 11:03 UTC (Fri) by juliank (guest, #45896) [Link] (1 responses)

Yeah, it would be easier if comparison were strictly typed.

PHP and P++

Posted Aug 18, 2019 3:00 UTC (Sun) by k8to (guest, #15413) [Link]

Do you mean an exception on type mismatch?

That sounds probably useful for most code i write, and it would cause huge explosions in most code I have to work on that other people write. Probably a good idea all around.

PHP and P++

Posted Aug 18, 2019 23:25 UTC (Sun) by mjblenner (subscriber, #53463) [Link]

You could try the -b (or -bb) switch. e.g:

python3 -bb

>>> b'true' == 'true'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BytesWarning: Comparison between bytes and string


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds