我正在使用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(' ')
答案 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写入文件,因此您需要在编写内容之前将其转换为字符串。