What method is it called when I type the name of the object?
I always thought that it was calling either repr
or str
but that doesn't hold in case of the PageObject of PyPDF2. As you can see, the output of __repr__
or __str__
is different to the one we get when we type the name of the variable in the interactive console.
>>> reader = PdfFileReader(f)
>>> page = reader.pages[0]
>>> page
'/Encoding': {'/Differences': [32,
'/space',
40,
'/parenleft',
'/parenright',
46,
'/period',
'/slash',
'/zero',
'/one',
'/two',
'/three',
'/four',
'/five',
'/six',
56,
'/eight',
'/nine',
69,
...
>>> page.__str__()
"{'/Annots': [], '/Contents': IndirectObject(12, 0), '/Group': {'/CS': '/DeviceRGB', '/S': '/Transparency', '/Type': '/Group'}, '/MediaBox': RectangleObject([0, 0, 460.8, 345.6]), '/Parent': IndirectObject(2, 0), '/Resources': IndirectObject(8, 0), '/Type': '/Page', '/ArtBox': RectangleObject([0, 0, 460.8, 345.6]), '/BleedBox': RectangleObject([0, 0, 460.8, 345.6]), '/CropBox': RectangleObject([0, 0, 460.8, 345.6]), '/TrimBox': RectangleObject([0, 0, 460.8, 345.6])}"
```
>>> page.__repr__()
<same-as-above>
P.S. Probably there's an answer out there for this question and it's just that I haven't typed my query correctly.
UPDATE I observe this behavior in IPython (version 5.5.0). Running with the builtin REPL the output I get when typing the variable name matches the repr
output.