hello I am trying to load coordinates for plotting from a text file and I keep getting an error I don’t understand. The coordinates look like this in the file (0.1, 0.0, 0.0), Here is the code I am trying to run:
(0.613125, 0.52202, 0.19919)
from visual import *
with open ('/Desktop/Coordlist2.txt','r') as open_file:
rightFace = curve(pos=[(1,-1,-1), (1,-1,1), (1,-1,-1),(1,1,-1),(1,1,-1),(1,1,1),(1,1,1),(1,-1,1)], radius=0.01, color=color.cyan)
backFace = curve(pos=[(1,-1,-1), (-1,-1,-1), (-1,-1,-1),(-1,1,-1),(-1,1,-1),(1,1,-1)], radius=0.01, color=color.cyan)
leftFace = curve(pos=[(-1,-1,-1), (-1,-1,1), (-1,-1,1),(-1,1,1),(-1,1,1),(-1,1,-1)], radius=0.01, color=color.cyan)
frontFace = curve(pos=[(-1,-1,1), (1,-1,1), (1,1,1),(-1,1,1)], radius=0.01, color=color.cyan)
for line in open_file.readlines():
coords = line
points(pos=[coords], size=1, color=color.yellow)
This is the error message I am getting:
Traceback (most recent call last):
File "/Users/Graphs.py", line 15, in <module>
points(pos=[coords], size=1, color=color.yellow)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vis/primitives.py", line 84, in __init__
self.process_init_args_from_keyword_dictionary( keywords )
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vis/primitives.py", line 212, in process_init_args_from_keyword_dictionary
setattr(self, key, value)
ValueError: Object cannot be converted to array.
Any help would be greatly appreciated
How they look in the file is irrelevant; they’re read as strings. You’ll need to parse the lines before they can be used; try
ast.literal_eval().