#!/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)
所以我正在制作一个程序来检查文件是否具有“ErrorScatter”有效负载,但在测试我的创作时我不断遇到错误。因为我是新手,所以我不知道如何解决这个问题。
这是我遇到的错误:
TypeError: coercing to Unicode: need string or buffer, tuple found
有人知道怎么解决吗?
最佳答案
,Python中的运算符用于创建元组,例如
1, 2, 3
制作三元素元组
(1, 2, 3)
和
"blah", "bleh"
表示二元组
("blah", "bleh")
要连接字符串,您可以使用 +
作为 Gaurav already suggested :
fixpath = filepath + "/Contents/MacOS/ErrorScatter"
但其实更好的办法是
import os
fixpath = os.path.join(filepath, "Contents/MacOS/ErrorScatter")
甚至
fixpath = os.path.join(filepath, "Contents", "MacOS", "ErrorScatter")
(使用 os.path.join
是一种习惯,一旦您碰巧在 Windows 上运行一些脚本,您就会欣赏这种习惯,这种可能性不大,但习惯会随着重复而养成...)
关于找到 Python TypeError : coercing to Unicode: need string or buffer, 元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28826241/