Python TypeError:强制转换为Unicode:需要字符串或缓冲区,找到元组

ACi*_*AiN 8 python operating-system tuples typeerror

#!/usr/bin/env python
import sys
import os

print "Scan a file for ""ErrorScatter"" payload"
print "Drag the suspicious file here then press enter."
filepath = raw_input("File Location: ")
fixpath = filepath , "/Contents/MacOS/ErrorScatter"
scan = os.path.exists(fixpath)
Run Code Online (Sandbox Code Playgroud)

所以我正在制作一个程序来检查文件是否有"ErrorScatter"有效负载,但是在测试我的创建时我一直遇到并出错.因为我是新手,我不知道如何解决这个问题.

这是我得到的错误:

TypeError: coercing to Unicode: need string or buffer, tuple found
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

Mek*_*ekk 14

例如,Python中的运算符用于创建元组

1, 2, 3
Run Code Online (Sandbox Code Playgroud)

制作3元素元组

(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)

"blah", "bleh"
Run Code Online (Sandbox Code Playgroud)

意味着2元素元组

("blah", "bleh")
Run Code Online (Sandbox Code Playgroud)

来连接字符串,你可以使用+拉夫已经建议:

fixpath = filepath + "/Contents/MacOS/ErrorScatter"
Run Code Online (Sandbox Code Playgroud)

但实际上更好的方法是

import os

fixpath = os.path.join(filepath, "Contents/MacOS/ErrorScatter")
Run Code Online (Sandbox Code Playgroud)

甚至

fixpath = os.path.join(filepath, "Contents", "MacOS", "ErrorScatter")
Run Code Online (Sandbox Code Playgroud)

(使用os.path.join是一种习惯,一旦你碰巧在Windows上运行一些脚本,你会很感激,这个不太可能,但习惯会因重复而增长......)