Struct cpython::PyModule [] [src]

pub struct PyModule(_);

Represents a Python module object.

Methods

impl PyModule
[src]

[src]

Create a new module object with the __name__ attribute set to name.

[src]

Import the Python module with the specified name.

[src]

Return the dictionary object that implements module's namespace; this object is the same as the __dict__ attribute of the module object.

[src]

Gets the module name.

May fail if the module does not have a __name__ attribute.

[src]

Gets the module filename.

May fail if the module does not have a __file__ attribute.

[src]

Gets a member from the module. This is equivalent to the Python expression: getattr(module, name)

[src]

Calls a function in the module. This is equivalent to the Python expression: getattr(module, name)(*args, **kwargs)

args should be a value that, when converted to Python, results in a tuple. For this purpose, you can use: * cpython::NoArgs when calling a method without any arguments * otherwise, a Rust tuple with 1 or more elements

Example

use cpython::NoArgs;
let sys = py.import("sys").unwrap();
// Call function without arguments:
let encoding = sys.call(py, "getdefaultencoding", NoArgs, None).unwrap();
// Call function with a single argument:
sys.call(py, "setrecursionlimit", (1000,), None).unwrap();

[src]

Adds a member to the module.

This is a convenience function which can be used from the module's initialization function.

[src]

Adds a new extension type to the module.

This is a convenience function that initializes the py_class!(), sets new_type.__module__ to this module's name, and adds the type to this module.

Trait Implementations

impl ToPyObject for PyModule
[src]

Identity conversion: allows using existing PyObject instances where T: ToPyObject is expected.

[src]

Converts self into a Python object.

[src]

Converts self into a Python object. Read more

[src]

Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object. Read more

impl<'source> FromPyObject<'source> for PyModule
[src]

[src]

Extracts Self from the source PyObject.

impl<'source> FromPyObject<'source> for &'source PyModule
[src]

[src]

Extracts Self from the source PyObject.

impl PythonObject for PyModule
[src]

[src]

Casts the Python object to PyObject.

[src]

Casts the Python object to PyObject.

[src]

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

[src]

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

impl PythonObjectWithCheckedDowncast for PyModule
[src]

[src]

Cast from PyObject to a concrete Python object type.

[src]

Cast from PyObject to a concrete Python object type.

impl PythonObjectWithTypeObject for PyModule
[src]

[src]

Retrieves the type object for this Python object type.