找到 Python TypeError : coercing to Unicode: need string or buffer, 元组

标签 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)

所以我正在制作一个程序来检查文件是否具有“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/

相关文章:

datetime - 如何获得一片元组(小时,分钟)

python - Sklearn StandardScaler + ElasticNet 具有可解释系数

Python在父类中使用派生类的方法?

Python:检查哪个元组项字符串以1结尾(如果它以1结尾)

python - n 层嵌套元组数据到带有引号的逗号分隔字符串

c - 向管道写入一些随机数?

python - python中列表的排序列表

python - Pandas Groupby 仅相同 ID 且列值为 false 时

JavaFx将文件复制到系统剪贴板并粘贴到操作系统中

c++ - 为什么 4 个进程比 4 个线程好?