关于字典输出的问题

dic
{1: 'one', 'two': 2, 'home': 'family'}
print '%(1)s boy has %(two)d good %(home)s' % dic
Traceback (most recent call last):
File "", line 1, in
KeyError: '1'

小弟的问题就是如果key是数字的话, print的格式该怎么写?
[b]问题补充:[/b]
这是在python console里写的例子,
[b]问题补充:[/b]
dic = {1: 'one', 'two': 2, 'home': 'family'}
然后用下面格式打印出内容:
print '%(1)s boy has %(two)d good %(home)s' % dic
但是由于第一个数据的key = 1 是一个数字,所以不知道该怎么写了, 于是问问大伙儿.

下面是华蟒上的回答, 或者对你有用

这个是Python中String Formatting Operations中已有的限制。

详情参见Python Documentation: 3.6.2 String Formatting Operations

有段描述为:
2. Mapping key (optional), consisting of a parenthesised sequence of
characters (for example, (somename)).

这个是py的代码么?没有看明白。说说具体你想干什么吧

你的print语句出现的问题,我确实想不到好的解决方法。
最后,我只能是采用了最基本的方式。
print '%s boy has %d good %s' % (dict[1], dict['two'], dict['home'])

-------- 分割线 ---------
还有,我帮你到华蟒上发帖了,看看那边又没有好的解决方案。