Was "Accessing parent objects."

On 03/25/2018 12:26 PM, Jugurtha Hadjar wrote:
>> print("I am {0.__class__.__name__} foo".format(self))
> 
> I prefer keyword arguments, but if I used it that way I'd do:
> 
> print("I am {0} foo".format(self.__class__.__name__))

These are contrived examples.  In real code I might do something like this:

fmt_class_name = "I am {0.__class__.__name__} foo".format
...
for x class_list:
  print(fmt_class_name(x))

IOW when I define the format string I want it clear what it is supposed
to print.  The actual use of the format could happen in a completely
different place.

> self.__class__.__name__ looks better (+ makes more sense to me) than
> 0.__class__.__name__.
> 
>> print(f"I am {self.__class__.__name__} foo")
> 
> f-strings are only available in python 3.6 as far as I know and.

I'm not even sure if I am a big fan of f-strings but I do like to run
current versions of Python so they are there for me.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to