Python Forum
Python Anytree - Is not of type 'NodeMixin' error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Anytree - Is not of type 'NodeMixin' error
#4
georgebijum Wrote:will you be able to share few lines of code that will handle the issue

The anytree documentation about the «parent» attribute suggests that you can set the attribute after creation, so I suggest something like

nodes = {}
with open("SampleHierarchy.csv", "r") as f:
    # creation step
    csv_reader = csv.DictReader(f)
    for row in csv_reader:
        for item in (row['Code'], row['Parent']):
            if item and (item not in nodes):
                nodes[item] = Node(item)
    # parent setting step
    f.seek(0)
    csv_reader = csv.DictReader(f)
    for row in csv_reader:
        c, p = row['Code'], row['Parent']
        if c and p:
            nodes[c].parent = nodes[p]
Reply


Messages In This Thread
RE: Python Anytree - Is not of type 'NodeMixin' error - by Gribouillis - May-05-2022, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,385 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 1,404 Jul-22-2023, 11:33 PM
Last Post: jhancock
  Incorrect Type Error milkycow 4 3,013 Jun-25-2021, 06:04 AM
Last Post: milkycow
Star Type Error: 'in' object is not callable nman52 3 3,499 May-01-2021, 11:03 PM
Last Post: nman52
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,161 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  Type Error in Python MarcusB 3 2,663 Mar-30-2021, 06:34 PM
Last Post: buran
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,137 Feb-09-2021, 05:40 PM
Last Post: soft
  Type Error or Value Error? spalisetty06 3 2,462 Jul-21-2020, 04:56 AM
Last Post: deanhystad
  anytree implicit node? gw1500se 0 1,754 Jun-07-2020, 08:42 PM
Last Post: gw1500se
  Modifying anytree Nodes gw1500se 1 2,727 Jun-05-2020, 03:44 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020