简体   繁体   中英

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 string interpolation.
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~

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM