0

I have a url:

https://enterpriseefiling.fcc.gov/dataentry/api/download/dbfile/Current_LMS_Dump.zip

Let

u1 = ['https://enterpriseefiling.fcc.gov/dataentry/api/download/dbfile/Current_LMS_Dump.zip']

I run the following code in my python interpreter

import requests, io
r = requests.get(u1, stream=True)
io.BytesIO(r.content)

I get the following response

<_io.BytesIO object at 0x000002244592F1A8>

My question is: what does this mean? Where is 0x000002244592F1A8? What does 0x000002244592F1A8 refer to?

rafaelc
  • 57,686
  • 15
  • 58
  • 82
joshua libin
  • 41
  • 10
  • 6
    It's the internal ID of the BytesIO object, which is automatically returned by the interpreter when you reference an object on the command line. Why are you doing that? – Daniel Roseman Aug 03 '18 at 17:47
  • @DanielRoseman I am just trying to understand what these functions return – joshua libin Aug 03 '18 at 19:46

3 Answers3

0

When python needs to print out an object, and the object doesn't otherwise have a built-in method that tells the interpreter how to print it out (for example, requests.Response and python's built-in list and dict types do have this sort of instruction), python uses this format:

<[objecttype] object at [pointer]>

where pointer is literally a pointer to the object's location in memory. That's what you see here: when you do io.BytesIO(r.content) in your interpreter, you create an io.BytesIO object.

A different method tends to get called when, on the interpreter, you do

>>> print(<object>)

rather than just

>>> <object>

and the io.BytesIO class certainly has methods you can use for more useful output, if you look at its documentation. Try assigning it to a variable instead of printing it:

b = io.BytesIO(r.content)
Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
  • Thanks! So the pointer here is a pointer formatted as a hexidecimal and it identifies the actual physical memory register in the computer's hardware? – joshua libin Aug 03 '18 at 18:11
0

My understanding is that 0x000002244592F1A8 here is the formatted id of the object in memory. I say "formatted", because, if you do id() on the same object, the representation will be a little different (it will be formatted as an int or a long instead of a pointer address:

In [1]: import io

In [2]: obj = io.BytesIO()

In [3]: obj
Out[3]: <_io.BytesIO at 0x10da1ca70>

In [4]: id(obj)
Out[4]: 4523674224

To convert the id() to the format you see, you can do something like this (stolen from this post):

In [5]: format(id(obj), '#010x' if sys.maxsize.bit_length() <= 32 else '#18x')
Out[5]: '       0x10da1ca70'

This ^^ is not particularly useful, but it just shows you how id() lines up with what you are seeing.

The reason you are seeing it is just that it is displayed as part of the default __repr__() for the BytesIO object.

elethan
  • 16,408
  • 8
  • 64
  • 87
  • @RafaelC please see the rest of the original post, plus the SO link I posted. I am currently editing the post to provide more detail. – elethan Aug 03 '18 at 18:03
0

What does 0x000002244592F1A8 refer to?

It refers to the identity of the object. The number is an implementation detail (in CPython it happens to be the address of the object in memory, the same number returned by the id builtin), but what you can count on is that the number will be different for every BytesIO object currently extant in the process.

That kind of information is included in the __repr__ of many objects because it can come useful when debugging, allowing one to distinguish different objects that might have identical content.

user4815162342
  • 141,790
  • 18
  • 296
  • 355