首页 > 解决方案 > 如何摆脱“numpy.ndarray”没有属性拆分?

问题描述

我尝试编辑一个 stl 文件。关于这一点,我使用 numpy-stl 读取了 stl 文件。现在,当我尝试拆分其中存在的行时,它向我显示一个错误:

“numpy.ndarray”对象没有属性“split”

如何克服这一点?下面是代码。

import numpy as np
import stl
from stl import mesh


lines = mesh.Mesh.from_file('mesh.stl')
count = 0
for line in lines:
   if line.split()[0] == "solid":
      repl = line.split()[1]
      print(repl)

任何线索将不胜感激。

问候, Sunag R A.

标签: pythonnumpysplitattributeerrornumpy-stl

解决方案


只需使用str(line)替代tostring(line)方法


推荐阅读