Struct cpython::PyModule [−][src]
pub struct PyModule(_);
Expand description
Represents a Python module object.
Implementations
Create a new module object with the __name__
attribute set to name.
Import the Python module with the specified name.
Return the dictionary object that implements module’s namespace;
this object is the same as the __dict__
attribute of the module object.
Gets the module name.
May fail if the module does not have a __name__
attribute.
Gets the module filename.
May fail if the module does not have a __file__
attribute.
Gets the module filename object.
May fail if the module does not have a __file__
attribute.
Gets a member from the module.
This is equivalent to the Python expression: getattr(module, name)
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();
Adds a member to the module.
This is a convenience function which can be used from the module’s initialization function.
Trait Implementations
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
Casts the Python object to PyObject.
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyModule, PythonObjectDowncastError<'p>>
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyModule, PythonObjectDowncastError<'p>>
Cast from PyObject to a concrete Python object type.
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyModule, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyModule, PythonObjectDowncastError<'p>>
Cast from PyObject to a concrete Python object type.
Retrieves the type object for this Python object type.
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
type ObjectType = PyModule
Converts self into a Python object.
Converts self into a Python object. Read more