Python3-os-tmpfile

提供:Dev Guides
移動先:案内検索

Python 3-os.tmpfile()メソッド

説明

メソッド* tmpfile()*は、更新モード(w+ b)で開かれた新しい一時ファイルオブジェクトを返します。 ファイルにはディレクトリエントリが関連付けられておらず、ファイル記述子がなくなると自動的に削除されます。

構文

以下は* tmpfile()*メソッドの構文です-

os.tmpfile

パラメーター

NA

戻り値

このメソッドは、新しい一時ファイルオブジェクトを返します

次の例は、tmpfile()メソッドの使用法を示しています。

# !/usr/bin/python3
import os

# The file has no directory entries associated with it and will be

# deleted automatically once there are no file descriptors.
tmpfile = os.tmpfile()
tmpfile.write('Temporary newfile is here.....')
tmpfile.seek(0)

print tmpfile.read()
tmpfile.close

結果

上記のプログラムを実行すると、次の結果が生成されます-

Temporary newfile is here.....