
Pythonで
・テキストファイルを新規作成
できます!
コード
ここでは例として
・デスクトップ配下にファイル「aiueo.txt」を新規作成して
・文字列「hogehoge」と書き込み
をします。
# 作成するファイルパス
file_path = r'C:\Users\lunch\Desktop\aiueo.txt'
# テキストファイルを開く(既にファイルが存在する場合は追記)
with open(file_path, mode='a') as f:
f.write('hogehoge\n')
実行結果
テキストファイルを新規作成できました。
※デスクトップ配下にファイル「aiueo.txt」を新規作成できました。



参考①
Excelファイルを新規作成することもできます。
詳細は以下の記事をご確認ください。
参考②
上記のVBAコードで使用した以下の詳細は、公式サイトをご確認ください。
●組み込み関数の「open」
●Fileオブジェクト