Accessing parent objects

Jugurtha Hadjar jugurtha.hadjar at gmail.com
Sun Mar 25 13:26:04 EDT 2018


On 03/25/2018 12:07 PM, D'Arcy Cain wrote:
> On 03/25/2018 05:10 AM, Jugurtha Hadjar wrote:
>>          print("I am {self.__class__.__name__} foo".format(self=self))
> Unrelated to the original issue but why not one of the following?
>
> 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__))

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.

-- 
~ Jugurtha Hadjar,




More information about the Python-list mailing list