Format using Getitem and Getattr

suggest change

Any data structure that supports __getitem__ can have their nested structure formatted:

person = {'first': 'Arthur', 'last': 'Dent'} 
'{p[first]} {p[last]}'.format(p=person) 
# 'Arthur Dent'

Object attributes can be accessed using getattr():

class Person(object):
    first = 'Zaphod'
    last = 'Beeblebrox'

'{p.first} {p.last}'.format(p=Person())
# 'Zaphod Beeblebrox'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents