如何使用Python清空文件
在Unix shell中,我可以这样做清空一个文件:
cd /the/file/directory/ :> thefile.ext 我将如何去在Python中做这个?
 是os.system这里的方式,我不知道如何,因为我将不得不发送两个动作之后,即cd ,然后:> 。 
打开一个文件创build它(除非设置append('a'))用空白覆盖它,例如:
 open(filename, 'w').close() 
@rumpel的答案的替代forms
 with open(filename, 'w'): pass