Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>:

> It seems to me that he's just assuming that symbols ought to be
> singletons, hence his focus on identity rather than equality.

Yes.

A practical angle is this: if I used strings as symbols and compared
them with "==", logically I shouldn't define them as constants but
simply use strings everywhere:

   class Connection:
       def __init__(self):
           self.state = "IDLE"

       def connect(self, address):
           if self.state == "IDLE":
               ...
           elif self.state == ...

The principal (practical) problem with that is that I might make a typo
and write:

           if self.state == "IDLE ":

which could result in some hard-to-find problems. That's why I want get
the help of the Python compiler and always refer to the states through
symbolic constants:

           if self.state == self.IDLE:


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to