Q:

Python Object not callable

I'm new to python: 
Created a Class:
class NodeStruct:
"""Struct to hold node data for search trees"""

  def __init__(self, name, children, parent_name, edge_weight):
      self.name = name
      self.childNodes = children
      self.parent = parent_name
      self.weight = edge_weight

  def name(self):
      return self.name

  def parent(self):
      return self.parent

  def path_cost(self):
      return self.weight

  def children(self):
      return self.childNodes

  def child_keys(self):
      return self.childNodes.keys()

Instantiate:
this_node = NodeStruct(start, problem[start], 'root', 0)

The Problem: when I make a call to name()
name = this_node.name()

I get the following error:
TypeError: 'str' object is not callable

Looks like it should be straight forward... What am I missing?

A:

When you define your class, name is a function. As soon as you instantiate it, though, __init__ is called, and name is immediately set to whatever you pass in (a string in this case). The names of functions are not kept separate from the names of other objects. Use a unique name.

A:

Which one of the names do you expect this_node.name() to find?
      self.name = name
      # ...

  def name(self):
      return self.name

The solution is likely to change the name of the attribute to self._name:
      self._name = name
      # ...

  def name(self):
      return self._name

