lpt
lpt

Reputation: 1

How can i use f-string formatting to rewrite a statement:

I have read and re-read a handful of pages about PEP and literal stringinterpolation.
But still can't figure out through experimentation what exact syntax will work so i can remove the %s from following statement in my python script.

cmds.getAttr("%s.fileTextureName" %item, newPath,type="string")

Thanks~

Upvotes: 0

Views: 190

Answers (1)

Anil_M
Anil_M

Reputation: 11473

Have you tried string.Formatter

cmds.getAttr("{}.fileTextureName".format(item), newPath,type="string")

The built-in str and unicode classes provide the ability to do complex variable substitutions and value formatting via the str.format() method described in PEP 3101.
The Formatter class in the string module allows you to create and customize your own string formatting behaviors using the same implementation as the built-in format() method.

Upvotes: 1

Related Questions