简体   繁体   English

我如何使用F字符串格式重写语句:

[英]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. 我已经阅读并重新阅读了一些有关PEP和文字string内插的页面。
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. 但是仍然无法通过实验弄清楚哪种确切的语法将起作用,因此我可以从python脚本中的以下语句中删除%s。

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

Thanks~ 谢谢〜

Have you tried string.Formatter 您是否尝试过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. 内置的strunicode类提供了通过PEP 3101中描述的str.format()方法进行复杂的变量替换和值格式化的str.format()
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. 字符串模块中的Formatter类允许您使用与内置format()方法相同的实现来创建和自定义自己的字符串格式设置行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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