0

I have classA wherein I have a get method to get the updated matrix, when I am trying to call the matrix in classB to print it out on console. I am getting something like

<packageA.prod.Cell.CellClass instance at 0x02C55558>,  
<packageA.prod.Cell.CellClass instance at 0x02C55580>, 

How can I get the values stored in such location to be printed out?

How can I split such values, as I am getting a list of such values and as list cannot be split

Smple_V
  • 838
  • 3
  • 13
  • 32
  • You have the objects; each object has attributes and methods which you can access. And lists don't need to be split, you can access them by index. – Daniel Roseman Mar 01 '16 at 09:57
  • @DanielRoseman Thx mate, can you be bit more specific like what kind of method or attributes are we talking here. I mean to say is there any built in method that would help me in resolving " packageA.prod.Cell.CellClass instance at 0x02C55558>" – Smple_V Mar 01 '16 at 10:07
  • I have no idea. What is CellClass? It's an object from your code. Your log is just showing the string representation of that class, but you have the actual object. – Daniel Roseman Mar 01 '16 at 10:21

1 Answers1

1

You have to implement the __repr__ method in your class. Example:

class CellClass:
  def __init__(self, value):
    self.value = value
  def __repr__(self):
    return 'Cell value: %s' % (self.value)
c = CellClass('cell text')

Output:

In [2]: c
Out[2]: Cell value: cell text

Credit/further reference: Purpose of Python's __repr__

Community
  • 1
  • 1
Gustavo Bezerra
  • 9,984
  • 4
  • 40
  • 48