line = line.split(comment, 1)[0] AttributeError: ‘numpy.int64’ object has no attribute ‘split’
import obspy时报错
line = line.split(comment, 1)[0] AttributeError: 'numpy.int64' object has no attribute 'split'
File "/Users/jiangyue/miniforge3/envs/python38/lib/python3.8/site-packages/numpy/lib/npyio.py", line 977, in split_line line = line.split(comment, 1)[0]
打开这个npyio.py文件,找到报错的这一行
def split_line(line: str):
"""Chop off comments, strip, and split at delimiter."""
for comment in comments: # Much faster than using a single regex.
line = line.split(comment, 1)[0]
line = line.strip('\r\n')
return line.split(delimiter) if line else []
把line转换为str类型:
def split_line(line: str):
"""Chop off comments, strip, and split at delimiter."""
for comment in comments: # Much faster than using a single regex.
line = str(line).split(comment, 1)[0]
line = line.strip('\r\n')
return line.split(delimiter) if line else []
本文介绍了解决在使用numpy int64类型时遇到的AttributeError错误,具体错误为尝试调用不存在的'split'属性。通过将numpy int64类型的变量转换为字符串类型,成功解决了此问题。
1202

被折叠的 条评论
为什么被折叠?



