PyClass: Create a python class

Description Usage Arguments Examples

View source: R/class.R

Description

Create a python class

Usage

1
PyClass(classname, defs = list(), inherit = NULL)

Arguments

classname

Name of the class. The class name is useful for S3 method dispatch.

defs

A named list of class definitions - functions, attributes, etc.

inherit

A list of Python class objects. Usually these objects have the python.builtin.type S3 class.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
Hi <- PyClass("Hi", list(
  name = NULL,
  `__init__` = function(self, name) {
    self$name <- name
    NULL
  },
  say_hi = function(self) {
    paste0("Hi ", self$name)
  }
))

a <- Hi("World")

## End(Not run)

reticulate documentation built on Sept. 17, 2021, 9:08 a.m.