How to get rid of "numpy.ndarray" has no attribute split?

5.1k Views Asked by At

I have try to edit one stl file. With regards to this, I read the stl file using numpy-stl. Now, when I try to split the lines present in it, it shows me an error as:

'numpy.ndarray' object has no attribute 'split'

How to overcome this? Below is the code.

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)

Any leads will be appreciated.

Regards, Sunag R A.

2

There are 2 best solutions below

5
On

It's because you obtain an ndarray object where you apply split.

Just convert it to a string (with tostring() method) before doing it, and it will work.

0
On

simply use str(line) instead tostring(line) method