Chcę sformatować ciąg znaków i użyć operatora kropki, aby móc tworzyć ciągi szablonów zawierające np. {user.name}
, {product.price}
.Jak używać kropek w ciągach w formacie Python?
Próbowałem to:
'Hello {user.name}'.format({'user': { 'name': 'Markus' } })
KeyError: 'user'
'Hello {user.name}'.format(**{'user': { 'name': 'Markus' } })
AttributeError: 'dict' object has no attribute 'name'
Czy istnieje sposób to zrobić?
Co jest 'stuf'? – jonrsharpe
'stuf' jest podklasą' dict', która jest dostępna dla atrybutów. Zobacz link do pełnego opisu modułu. –
Ach, widzę; schludny! – jonrsharpe