I am trying to read in an xyz file into python but keep getting these error messages. Kinda new to python so would love some help interpreting it!
def main():
atoms = []
coordinates = []
name = input("Enter filename: ")
xyz = open(name, 'r')
n_atoms = xyz.readline()
title = xyz.readline()
for line in xyz:
atom, x, y, z = line.split()
atoms.append(atom)
coordinates.append([float(x), float(y), float(z)])
xyz.close()
return atoms, coordinates
if __name__ == '__main__':
main()
Error:
Traceback (most recent call last):
File "Project1.py", line 25, in <module>
main()
File "Project1.py", line 16, in main
atom, x, y, z = line.split()
ValueError: not enough values to unpack (expected 4, got 3)
I believe the value error is because after a couple of lines there are only 3 values. But not sure why I am getting return errors.