小编use*_*417的帖子

Python:使用变量打开()

我在Python 2.6中打开一个随机生成名称的文件时遇到了问题.

import random

random = random.randint(1,10)

localfile = file("%s","wb") % random
Run Code Online (Sandbox Code Playgroud)

然后我收到有关最后一行的错误消息:

TypeError: unsupported operand type(s) for %: 'file' and 'int' 
Run Code Online (Sandbox Code Playgroud)

我不能自己解决这个问题,也不能用谷歌解决这个问题,但我相信必须有一个治愈方法.

python string-formatting

2
推荐指数
1
解决办法
3896
查看次数

标签 统计

python ×1

string-formatting ×1