Python open()関数
例
ファイルを開き、コンテンツを印刷します。
f = open("demofile.txt", "r")
print(f.read())
定義と使用法
このopen()
関数はファイルを開き、それをファイルオブジェクトとして返します。
ファイル処理の詳細については、ファイル処理に関する章を参照してください。
構文
open(file,
mode)
パラメータ値
Parameter | Description |
---|---|
file | The path and name of the file |
mode | A string, define which mode you want to open the file in:
In addition you can specify if the file should be handled as binary or text mode
|
関連ページ
ファイルの読み取りチュートリアルでファイルを開く方法を学ぶ
ファイルの書き込み/作成チュートリアルでファイルの書き込み/作成方法を学ぶ
ファイルの削除チュートリアルでファイルを削除する方法を学ぶ