.PythonNew {RSPython} | R Documentation |
This function creates an instance of a Python class. Generally, this returns a reference to that object so that it can be used in subsequent Python calls from R.
.PythonNew(className, ..., .module=NULL, .convert=F)
className |
the name of the class of which an new instance is to be created |
... |
any arguments to the \_\_init\_\_ method of the class, including
named arguments |
.module |
the ``name'' of the module in which the class is defined. This is
usually a single string, but for nested modules is a character vector whose elements
are in the top-level to sub-module order; e.g. if a class C is defined in the module B
which is in A (i.e. A.B.C in Python terms), the .module is given as
c("A","B") |
.convert |
a logical value indicating whether to attempt to convert the newly created object
or not. This is usually only FALSE when creating the object has a useful side-effect. |
If .convert
is FALSE
, a reference to the
newly created object is returned. This is an object of
class . Otherwise, an attempt to convert the newly created
object using the built-in and the current user-specified converters
is performed. The result depends on what these return. If no converter
is found, a reference to the newly created object is returned, just
as if
.convert
was specified as FALSE
.
Duncan Temple Lang
http://www.omegahat.org/RSPython, http://www.python.org
# Get a class that we know exists! e <- .PythonNew("ArithmeticError") e <- .PythonNew("ArithmeticError", 'a simple messge string') e$"__str__"() ## Not run: u <- .PythonNew("urlopen", "http://www.omegahat.org/index.html", .module="urllib") .PythonMethod(u, "geturl") txt <- u$read() u$geturl() u$close() ## End(Not run)