Singletons: if the sys.modules entry is removed and the module is re-imported,Ī new module object is created, and the old module is subject to normal garbageīy default, multiple modules created from the same definition should be Unlike modules created using single-phase initialization, these modules are not The distinction is similar to the _new_() and _init_() methods Is created, and the execution phase, when it is populated. Initialization is split between the creation phase, when the module object Inicialização multifásica ¶Īn alternate way to specify extensions is to request “multi-phase initialization”.Įxtension modules created this way behave more like Python modules: the Object is typically populated using functions like PyModule_AddObjectRef(). When using single-phase initialization, m_slots must be NULL.Ī maioria dos usos dessa função deve ser feita com PyModule_Create() use-o apenas se tiver certeza de que precisa.īefore it is returned from in the initialization function, the resulting module PyModuleDef_Slot * m_slots ¶Īn array of slot definitions for multi-phase initialization, terminated by PyMethodDef * m_methods ¶Ī pointer to a table of module-level functions, described by m_size não negativo é necessário para inicialização multifásica. Sub-interpreters, because it has global state.ĭefini-lo como um valor não negativo significa que o módulo pode ser reinicializado e especifica a quantidade adicional de memória necessária para seu estado. Setting m_size to -1 means that the module does not support M_free function has been called, if present. This memory area is allocated based on m_size on module creation,Īnd freed when the module object is deallocated, after the This makes modules safe for use in multiple sub-interpreters. Retrieved with PyModule_GetState(), rather than in static globals. Module state may be kept in a per-module memory area that can be const char * m_doc ¶ĭocstring for the module usually a docstring variable created with Sempre inicializa este membro para PyModuleDef_HEAD_INIT. Geralmente, há apenas uma variável inicializada estaticamente desse tipo para cada módulo. Part of the Stable ABI (including all members).Ī estrutura de definição de módulo, que contém todas as informações necessária para criar um objeto de módulo. Ver Construindo extensões C e C++ ou Extending Embedded Python para mais detalhes.Ī função de inicialização pode passar uma instância de definição de módulo para PyModule_Create() e retornar o objeto de módulo resultante ou solicitar “inicialização multifásica” retornando a própria estrutura de definição. Objetos de módulos são geralmente criados a partir de módulos de extensão (bibliotecas compartilhadas que exportam uma função de inicialização), ou módulos compilados (onde a função de inicialização é adicionada usando PyImport_AppendInittab()). Unencodable filenames, use PyModule_GetFilenameObject() instead. Obsoleto desde a versão 3.2: PyModule_GetFilename() raises UnicodeEncodeError on Or if it is not a string, SystemError is raised and NULL is returned. Part of the Stable ABI since version 3.7. PyObject * PyModule_GetNameObject ( PyObject * module ) ¶ PyObject_* functions rather than directly manipulate a module’s It is recommended extensions use other PyModule_* and SystemError is raised and NULL is returned. If module is not a module object (or a subtype of a module object), Is the same as the _dict_ attribute of the module object. Return the dictionary object that implements module’s namespace this object PyObject * PyModule_GetDict ( PyObject * module ) ¶ Semelhante a PyModule_NewObject(), mas o nome é uma string codificada em UTF-8 em vez de um objeto Unicode. PyObject * PyModule_New ( const char * name ) ¶ Alterado na versão 3.4: _package_ e _loader_ são definidos como None.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |