- 论坛徽章:
- 0
|
本帖最后由 luofeiyu_cu 于 2014-08-21 09:35 编辑
print('My name is {0.name}'.format(open('out.txt', 'w')))
上面的语句为何输出:
My name is out.txt
这里的{0.name} 这里的0 是什么意思?
.name通过测试的方式,得到一点启示
>>> print('My name is {0.mode}'.format(open('out.txt', 'w')))
My name is w
>>> print('My name is {0.encoding}'.format(open('out.txt', 'w')))
My name is cp936
>>> print('My name is {encoding}'.format(open('out.txt', 'w')))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'encoding'
0. 这个含义还是有点不清楚。 |
|