str的format原来是这样用的

继续爬虫。
中午运行爬去极客学院课程时,遇到了“TypeError: Can’t convert ‘int’ object to str implicitly”问题。

f.writelines(‘titles:’+each[‘title’]+’\n’.encode())

在stackoverflow看到了类似的解答。

one of Python’s mottos is “Explicit is better than Implicit” – Name McChange (显性比隐形好)

You cannot concatenate a string with an int. You would need to convert your int to string using str function, or use formatting to format your output.
Change: -
print(“Ok. You’re balance is now at ” + WORD + ” skill points.”)
to: -
print(“Ok. You’re balance is now at {} skill points.”.format(WORD))

你可能感兴趣的:(爬虫,python,str-format,显性)