list - Python, Grabbing information from a class object not working -


I do not know what the reason for this error is, I do not know how to describe it without informing you Here is the relevant part of my code:

  class node (object): def __init __ (self, content, children): self. Content = content itself Children = Children Deaf Head Node (District, Origin): new_contents = parent.contents new_contents.append (district) new = node (new_contents, []) parent.children.append (new) returns new root = node ([], [] Data = [[[1,1, 'R'], [1,2, 'D'], [1,2, 'R'], [1,4, 'D']] Download (data, Root)   

Here's the problem: new.contents have been modified as planned, but this is also parent.contents. what happened?

As you have stated in your comment, you should content pf 'new_contents In 'parent.contents' Otherwise, you are reaching the list from the context, which is not obvious what its purpose is.

In this way, your 'MacNode' function may start as follows:

  def makeNode (District, Guardian): new_content = copy.deepcopy (parent.contents ) ...   

I hope, I can clear things for later readers ...;)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -