简体   繁体   中英

Expected a character buffer object error

I'm programming in Python, and I keep getting an error when I run my code:

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

The function write(str) writes the string str to the file, so you need to convert your content to string before writing them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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