I create a list by appending dictionary entries containing display_name, browse_name and node_id of OPCUA
server nodes. When I print the list, all the elements are on one line. I have no idea why. Please help!
# Code for inserting elements into the Listbox
def display_nodes(self, nodes_list):
# Code zum Anzeigen der Nodes im GUI
i = 0
print(nodes_list,sep=" ")
display_text=""
self.nodes_listbox.delete(0,tk.END)
for node in nodes_list:
display_text=str(node)
self.nodes_listbox.insert(tk.END,display_text)
pass
# Code for reading nodes and adding them to the List
def read_nodes(self,node):
# Code zum Lesen der Nodes vom Server
for childId in node.get_children():
ch = self.client.get_node(childId)
print(ch.get_node_class())
if ch.get_node_class() == ua.NodeClass.Variable:
#if str(ch.get_browse_name()).find("QualifiedName(1:") != -1:
if (str(ch.nodeid)).find("ns=1")!= -1:
node_data={
'display_name':ch.get_display_name(),
'browse_name':ch.get_browse_name(),
'node_id':str(ch.nodeid),
}
print(node_data)
self.nodes_list.append(node_data)
else:
#if str(ch.get_browse_name).find("QualifiedName(1:") != -1:
node_data={
'display_name':ch.get_display_name(),
'browse_name':ch.get_browse_name(),
'node_id':str(ch.nodeid),
#"data_type":ch.get_data_type_as_variant_type(),
}
print(node_data)
self.read_nodes(ch)
return[self.nodes_list]
When i print the list, all the elements are in one line.
The problem can be fixed by using asterik(*)
Change this:
self.nodes_listbox.insert(tk.END,display_text)
to:
self.nodes_listbox.insert(tk.END, *display_text)