-2

When I try to print the value of the self.store_obj_stack, it is giving me the location of that variable instead of the value.

class StackStorage(object):
def __init__(self, dataList):
self.dList = dataList
self.store_obj_stack = Stack()
print(self.store_obj_stack)

I have imported the Stack from the other class, which is like this:

from collections import deque
import copy

class Stack(object):
def __init__(self):
self.__stack = deque()

I am getting this:

<stack.Stack object at 0x1032fc580>

  • 1
    You need to define a `__str__()` method in the `Stack` class in order for it to print values – QuantumMecha Apr 04 '22 at 23:43
  • Does this answer your question? [How to print instances of a class using print()?](https://stackoverflow.com/questions/1535327/how-to-print-instances-of-a-class-using-print) – mkrieger1 Apr 05 '22 at 00:06

1 Answers1

0

You should use __repr__() if you want something back from Python.

For example, you could do

def __repr__(self):
    return whatever you want

Then you could do print(something).

For more information, visit https://www.educative.io/edpresso/what-is-the-repr-method-in-python