TypeError:无法连接“ str”和“ Redditor”对象

时间:2018-12-14 17:57:56

标签: python python-3.x praw

Traceback (most recent call last):
  File "run.py", line 56, in <module>
    run(r, comments_replied_to)
  File "run.py", line 30, in run_bot
    b.write("Author=" + comment.submission.author + "\n")
TypeError: cannot concatenate 'str' and 'Redditor' objects

这是从代码中获得的追溯,我不确定如何解决此问题,谢谢。

这是代码

with open ("first.txt", "a") as f, open 
    ("second.txt", "a") as b:
        f.write(comment.id + "\n")
            b.write("author=" + comment.submission.author + "\n")

1 个答案:

答案 0 :(得分:2)

我猜您正在使用PRAW,并希望获得reddit用户名?现在,您正在尝试将字符串与Redditor对象连接起来。

相反,您需要使用Redditor.name来访问用户名。看看Redditor对象的文档。

在您的情况下

comment.submission.author.name