10-15-2023, 01:44 PM
I have written a program to get the views stored in the station by View manager and use them in my code.
At first, I save the items in Tools/Options/ViewNames in a file with an txt extension (coppy and past). Then write the following code to save each of these views with a name and apply them to the environment when called in the main program:
import ast
def read_file(filename):
name_matrix = []
data_matrix = []
with open(filename, 'r') as file:
line = file.readline().strip()
items = line.split('||')
for item in items:
name, vector = item.split('|')
float_vector = ast.literal_eval(vector)
name_matrix.append(name)
data_matrix.append(float_vector)
return name_matrix, data_matrix
def print_matrices(name_matrix, data_matrix):
print("Name Matrix:")
for name in name_matrix:
print(name)
print("Data Matrix:")
for vector in data_matrix:
print(vector)
def main():
filename = r'C:\Users\rezaj\OneDrive\Desktop\Temp.txt'
name_matrix, data_matrix = read_file(filename)
print_matrices(name_matrix, data_matrix)
if __name__ == "__main__":
main()
Is the program that I have written suitable and practical or is there a better way to interact between the code environment and the program environment?
At first, I save the items in Tools/Options/ViewNames in a file with an txt extension (coppy and past). Then write the following code to save each of these views with a name and apply them to the environment when called in the main program:
import ast
def read_file(filename):
name_matrix = []
data_matrix = []
with open(filename, 'r') as file:
line = file.readline().strip()
items = line.split('||')
for item in items:
name, vector = item.split('|')
float_vector = ast.literal_eval(vector)
name_matrix.append(name)
data_matrix.append(float_vector)
return name_matrix, data_matrix
def print_matrices(name_matrix, data_matrix):
print("Name Matrix:")
for name in name_matrix:
print(name)
print("Data Matrix:")
for vector in data_matrix:
print(vector)
def main():
filename = r'C:\Users\rezaj\OneDrive\Desktop\Temp.txt'
name_matrix, data_matrix = read_file(filename)
print_matrices(name_matrix, data_matrix)
if __name__ == "__main__":
main()
Is the program that I have written suitable and practical or is there a better way to interact between the code environment and the program environment?