Python上的Symbian应用程序note usag

2024-09-26 18:01:03 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用这个命令时

appuifw.note(u"Connecting to %s" % (address), "conf");

我得到错误:“不是所有的参数在字符串格式化期间转换”

如何修复此错误?在


Tags: to字符串命令参数addressconf错误note
2条回答

你提到的错误出现在

>>> print "my name is %s" %('foo','bar')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting

这意味着我有2个值来替换('foo', 'bar'),但只提供了one占位符{}。在

来纠正它

^{pr2}$

还有另一种方法可以使用str.format()来实现这一点。在

>>> print "my name is {0} {1}".format('foo','bar')
    my name is foo bar

字典还有另一个选择

mydict = {'foo': 'bar', 'foo2': 'bar2'}
print "my name is %(foo)s" % mydict

这样你就可以只使用foo。在

注意最后一个's'代表'string',所以如果你添加一些类似于%(foo)d的东西,它就意味着有了foo的%d。在

相关问题 更多 >

    热门问题