微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在python中将变量值插入到字符串中

python中将变量[i]引入字符串中.

例如,查看以下脚本,我只想为图像命名,例如geo [0]. Tiff …到geo [i]. tiff,或者如果你使用会计,因为我可以替换价值链的一部分来生成一个计数器.

    data = self.cmd("r.out.gdal in=rdata out=geo.tif")

    self.dataOutTIF.setValue("geo.tif")

谢谢你的回答

解决方法:

data = self.cmd("r.out.gdal in=rdata out=geo{0}.tif".format(i))
self.dataOutTIF.setValue("geo{0}.tif".format(i))

06001

Perform a string formatting operation. The string on which this
method is called can contain literal
text or replacement fields delimited
by braces {}. Each replacement field
contains either the numeric index of a
positional argument, or the name of a
keyword argument. Returns a copy of
the string where each replacement
field is replaced with the string
value of the corresponding argument.

06002

See Format String Syntax for a description of the varIoUs formatting
options that can be specified in
format strings.

This method of string formatting is the new standard in Python 3.0, and
should be preferred to the %
formatting described in String
Formatting Operations in new code.

06003

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐