我在Python 2.6中打開一個隨機生成名稱的文件時遇到了問題。Python:打開()使用變量
import random
random = random.randint(1,10)
localfile = file("%s","wb") % random
然後我得到一個錯誤信息,最後一行:
TypeError: unsupported operand type(s) for %: 'file' and 'int'
我只是不能由我自己想出解決辦法,也沒有與谷歌,但必須有一個治癒這個,我相信。
您的基本認識是錯誤的。我認爲你需要查看Python教程。 – 2010-05-07 12:13:37
對不起,我剛剛開始使用Python – user335417 2010-05-07 12:18:24
你不說你想要什麼文件,但它看起來像你需要'tempfile'來代替。在標準庫的文檔中查找它。 – guillermooo 2010-05-07 15:52:54