TypeError: cannot concatenate 'str' and 'Redditor' objects
TypeError: cannot concatenate 'str' and 'Redditor' objects
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")
我猜你正在使用 PRAW 并想获得 reddit 用户名?现在,您正在尝试将字符串与 Redditor 对象连接起来。
相反,您需要使用 Redditor.name
访问用户名。查看 Redditor
对象的文档。
你的情况是
comment.submission.author.name
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")
我猜你正在使用 PRAW 并想获得 reddit 用户名?现在,您正在尝试将字符串与 Redditor 对象连接起来。
相反,您需要使用 Redditor.name
访问用户名。查看 Redditor
对象的文档。
你的情况是
comment.submission.author.name