简体   繁体   English

预期的字符缓冲区对象错误

[英]Expected a character buffer object error

I'm programming in Python, and I keep getting an error when I run my code: 我使用Python进行编程,运行代码时始终出现错误:

expected character buffer object 预期字符缓冲区对象

Any ideas/help? 有任何想法/帮助吗?

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('                                   ')

Change f.write(blockname) , f.write(rating) , and f.write(Comments) to f.write(str(blockname)) , f.write(str(rating)) , and f.write(str(Comments)) f.write(blockname)f.write(rating)f.write(Comments)更改为f.write(str(blockname))f.write(str(rating))f.write(str(Comments))

The function write(str) writes the string str to the file, so you need to convert your content to string before writing them. 函数write(str)字符串 str写入文件,因此您需要在写入内容之前将内容转换为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM