2013-12-08 27 views

回答

4

您不需要os模塊;只需打開一個文件進行寫入和關閉:

with open('index.html', 'w'): 
    pass 

你可能想沒有什麼明確寫入到它,就好像你只打開一個文件,而無需用它做任何其他開發商可能會混淆:

with open('index.html', 'w') as f: 
    f.write('') 
+0

你是什麼時候開始回答問題蟒蛇? –

+0

@GamesBrainiac當我喜歡它時,我會回答問題。我只是碰巧看到這個漂浮在附近。 – rightfold

+0

很高興有你在這裏的人! :d –

1

這只是創建一個帶有.html擴展名的空文本文件。

你可以做到這一點在Python有:

file = open('emptyfile.html', 'w') 
file.close() 
1
with open('example.html', 'w') as f: 
    # you can do something with f 
    pass