Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “如何修复”;TypeError:不支持的操作数类型“;?_Python - Fatal编程技术网

Python “如何修复”;TypeError:不支持的操作数类型“;?

Python “如何修复”;TypeError:不支持的操作数类型“;?,python,Python,我正在尝试在file.write函数中使用var值: profile = open("/tmp/%s.pcf", 'w+') % uid 我得到了这个错误: TypeError: unsupported operand type(s) for %: 'file' and 'str' 知道我做错了什么吗?将字符串格式化操作数移动到字符串本身: profile = open("/tmp/%s.pcf" % uid, 'w+') 您试图将其应用于open()调用的结果,该调用是一个文件。您需要其

我正在尝试在file.write函数中使用var值:

profile = open("/tmp/%s.pcf", 'w+') % uid
我得到了这个错误:

TypeError: unsupported operand type(s) for %: 'file' and 'str'

知道我做错了什么吗?

将字符串格式化操作数移动到字符串本身:

profile = open("/tmp/%s.pcf" % uid, 'w+')

您试图将其应用于
open()
调用的结果,该调用是一个文件。

您需要其中的字符串格式

profile = open("/tmp/%s.pcf" % uid, 'w+')
试试这个:

profile = open("/tmp/%s.pcf" % uid, 'w+')