On 1/21/20 3:11 PM, Ned Batchelder wrote:
On 1/21/20 1:42 PM, Johan Vergeer wrote:
     def __repr__(self):
         return f"{nameof(Person)}({nameof(self.name)}: {self.name}, {nameof(self.age)}: {self.age})"


I'm trying to understand what you are looking for.  Why isn't the above line just:

   return f"Person(name: {self.name}, age: {self.age})"

That is, instead of "{nameof(self.name)}" just use "name"?  You had to type "name" in your string anyway.  How would nameof be helping here?



Oops, sorry, just after sending, I understood: the nameof expression would raise an error if you changed the name of self.name and left it behind.  That seems like a long way to go to get that effect.

--Ned.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IHXME3F5XEQZAN6JSK2PMC4UOWV7AVSF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to