预期字符缓冲区对象错误

时间:2015-10-15 09:19:16

标签: python

我正在使用Python进行编程,并且在运行代码时出现错误:

  

预期的字符缓冲区对象

任何想法/帮助?

enter code here`fd = open('Comments', 'w'
with open('Comments.txt', 'w') as f:
blockname = raw_input('what is your block? ')
f.write(blockname)
rating = input('Rating from 1 to 10 please! ')
f.write(rating)
Comments = raw_input('please write your comments on this class here ')
f.write(Comments)
f.write('                                   ')

1 个答案:

答案 0 :(得分:0)

f.write(blockname)f.write(rating)f.write(Comments)更改为f.write(str(blockname))f.write(str(rating))f.write(str(Comments))

函数write(str)字符串 str写入文件,因此您需要在编写内容之前将其转换为字符串。