NewModule imports a module leaving the globals and locals arguments set to NULL and level set to 0. When the name argument contains a dot (when it specifies a submodule of a package), the fromlist argument is set to the list ['*'] so that the return value is the named module rather than the top-leve
(name string)
| 45 | // the submodules specified in the package’s __all__ variable are loaded.) Return a new reference to the imported module, |
| 46 | // or NULL with an exception set on failure. A failing import of a module doesn't leave the module in sys.modules. |
| 47 | func NewModule(name string) (*Module, error) { |
| 48 | n := C.CString(name) |
| 49 | defer C.free(unsafe.Pointer(n)) |
| 50 | mod := C.PyImport_ImportModule(n) |
| 51 | if mod == nil { |
| 52 | return nil, fmt.Errorf("couldn't import %q module", name) |
| 53 | } |
| 54 | return &Module{ |
| 55 | PyObject: &PyObject{rawptr: mod}, |
| 56 | name: name, |
| 57 | }, nil |
| 58 | } |
| 59 | |
| 60 | // MethFlags is the type alias for the method flags |
| 61 | type MethFlags int |
no outgoing calls