numpy-cn icon indicating copy to clipboard operation
numpy-cn copied to clipboard

输入与输出章节:TypeError: a bytes-like object is required, not 'str'

Open BeyondYourself opened this issue 4 years ago • 2 comments

在章节https://github.com/teadocs/numpy-cn/blob/master/docs/user/basics/io.md中,运行一下代码data = "1, 2, 3, 4, 5, 6" np.genfromtxt(BytesIO(data), delimiter=",")出现TypeError: a bytes-like object is required, not 'str'错误 我得环境是python3.7. 此处的代码应该改为np.genfromtxt(BytesIO(data.encode()), delimiter=",")就可以正常运行

BeyondYourself avatar Mar 17 '20 03:03 BeyondYourself

你可以提RP

lisniuse avatar Mar 17 '20 03:03 lisniuse

改成StringIO就对了,BytesIO是对byte类型数据进行操作的,官网可能写错了。

2920533883 avatar Feb 16 '21 13:02 2920533883