1. with open('test.txt', 'w') as f:
    2. print('Hello World!', file=f)

    文件必须是以文本模式打开, 如果以二进制模式打开就会出错.