Reticulate, UserList and View

When using Python's collections.UserList via reticulate, the View function fails in RStudio, see below an example. Can anything fix that? The issue is that if you have multiple objects converted from python in the environment and you click on them you get a cryptic exception.

Python's collections.UserList are wrappers around Python's lists, and can be used for example to customize how do you print a list, or to add functions to apply to all elements, etc.

This is tested in RStudio server 1.3.959.

Python file called '', containing:

import collections

class TestCustomList(collections.UserList):
  def __init__(self):
    super(TestCustomList, self).__init__() = [5,6,7]

custom_list = TestCustomList()

Executed in RStudio console:


Result is:

> library(reticulate)
> py_run_file("")
[5, 6, 7]
> py$custom_list
[5, 6, 7]
> in_r<-py$custom_list
> View(py$custom_list)
Error in py_get_item_impl(x, key, FALSE) : 
  TypeError: list indices must be integers or slices, not str

Detailed traceback: 
  File "/usr/local/lib/python3.7/collections/", line 1098, in __getitem__

(and clicking on in_r in the environment will result in the same error)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.