Skip to content

Instantly share code, notes, and snippets.

@1c7
Created August 16, 2013 02:56
Show Gist options
  • Save 1c7/6246893 to your computer and use it in GitHub Desktop.
Save 1c7/6246893 to your computer and use it in GitHub Desktop.
(Python) 最短的写文件代码
out = open('a.txt', 'w')
print('Hello Earth!', file=out)
out.close()
# 在 Python3.3.0 能成功运行
# 2.7不行
# 这会创建一个叫做a.txt的文件, 内容是'Hello Earth!', 屏幕上并不会有任何输出
@1c7
Copy link
Author

1c7 commented Aug 16, 2013

这段代码是看Head First Python学来的
在实体书的p110
电子书的p153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment