.PythonNew {RSPython}R Documentation

Create an instance of a Python class

Description

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.

Usage

.PythonNew(className, ..., .module=NULL, .convert=F)

Arguments

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.

Value

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.

Author(s)

Duncan Temple Lang

References

http://www.omegahat.org/RSPython, http://www.python.org

See Also

.PythonMethod .Python

Examples

   # 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)

[Package RSPython Index]