简体   繁体   English

类型错误:应为字符缓冲区对象

[英]TypeError: expected a character buffer object

I am running into the following error while writing the value into a file.将值写入文件时遇到以下错误。 Can you please help me figure out what is the issue here and how to fix it?你能帮我弄清楚这里的问题是什么以及如何解决吗?

row = 649
with open(r'\\loc\dev\Build_ver\build_ver.txt','r+') as f:
    f.write(row)
print row

Error:错误:

Traceback (most recent call last):
  File "latest_rev.py", line 6, in <module>
    f.write(row)
TypeError: expected a character buffer object

假设您只想将字符串'649'写入文件,将row更改为'649'或发出f.write(str(row))

你可以做 timgeb 所做的或者你可以做的

row = str(649)

I had the same error, in my code:我有同样的错误,在我的代码中:

s.translate(table)

The s obj was string . s obj 是string The issue was s.translate was expecting a unicode string.问题是s.translate一个 unicode 字符串。 So, the fix was to use:因此,修复方法是使用:

unicode(s).translate(table)

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

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