Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:应为字符缓冲区对象_Python - Fatal编程技术网

Python TypeError:应为字符缓冲区对象

Python TypeError:应为字符缓冲区对象,python,Python,我在将值写入文件时遇到以下错误。你能帮我找出问题所在以及解决方法吗 row = 649 with open(r'\\loc\dev\Build_ver\build_ver.txt','r+') as f: f.write(row) print row 错误: Traceback (most recent call last): File "latest_rev.py", line 6, in <module> f.write(row) TypeError: ex

我在将值写入文件时遇到以下错误。你能帮我找出问题所在以及解决方法吗

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

Traceback (most recent call last):
  File "latest_rev.py", line 6, in <module>
    f.write(row)
TypeError: expected a character buffer object
回溯(最近一次呼叫最后一次):
文件“最新版本py”,第6行,在
f、 写入(行)
TypeError:应为字符缓冲区对象

假设您只想将字符串
'649'
写入文件,请将
行更改为
'649'
或发出
f.write(str(row))
我的代码中有相同的错误:

s.translate(table)
s
obj是
string
。问题是
s.translate
需要一个unicode字符串。因此,修复方法是使用:

unicode(s).translate(table)

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

row = str(649)
i、 e.
write()
不会接受int,因此将
强制转换为字符串。的可能重复项