Dataset Viewer
Auto-converted to Parquet Duplicate
text
stringlengths
0
5.25k
source
stringclasses
31 values
The Python/C API Release 3. 12. 6 Guido van Rossum and the Python development team September 17, 2024 Python Software Foundation Email: docs@python. org
c-api.pdf
c-api.pdf
CONTENTS 1 Introduction 3 1. 1 Codingstandards........................................... 3 1. 2 Include Files............................................. 3 1. 3 Usefulmacros............................................ 4 1. 4 Objects,Typesand Reference Counts................................ 6 1. 4. 1 Reference Counts....
c-api.pdf
6. 6. 1 Parsingarguments...................................... 75 6. 6. 2 Buildingvalues....................................... 81 6. 7 Stringconversionandformatting................................... 83 6. 8 Py Hash API............................................. 85 6. 9 Reflection.......................................
c-api.pdf
8. 6. 4 Descriptor Objects..................................... 177 8. 6. 5 Slice Objects........................................ 178 8. 6. 6 Memory Viewobjects.................................... 179 8. 6. 7 Weak Reference Objects.................................. 180 8. 6. 8 Capsules.....................................
c-api.pdf
11. 10 tracemalloc CAPI.......................................... 249 11. 11 Examples............................................... 249 12 Object Implementation Support 251 12. 1 Allocating Objectsonthe Heap.................................... 251 12. 2 Common Object Structures...................................... 25...
c-api.pdf
C. 3. 15 zlib............................................. 335 C. 3. 16 cfuhash........................................... 336 C. 3. 17 libmpdec.......................................... 336 C. 3. 18 W3CC14Ntestsuite.................................... 337 C. 3. 19 Audioop........................................... 337...
c-api.pdf
vi
c-api.pdf
The Python/C API, Release 3. 12. 6 Thismanualdocumentsthe APIusedby Cand C++programmerswhowanttowriteextensionmodulesorembed Python. Itisacompaniontoextending-index, whichdescribesthegeneralprinciplesofextensionwritingbutdoes notdocumentthe APIfunctionsindetail. CONTENTS 1
c-api.pdf
The Python/C API, Release 3. 12. 6 2 CONTENTS
c-api.pdf
CHAPTER ONE INTRODUCTION The Application Programmer's Interfaceto Pythongives Cand C++programmersaccesstothe Pythoninterpreter atavarietyoflevels. The APIisequallyusablefrom C++,butforbrevityitisgenerallyreferredtoasthe Python/C API. Therearetwofundamentallydifferentreasonsforusingthe Python/CAPI. Thefirstreasonistowri...
c-api.pdf
The Python/C API, Release 3. 12. 6 Note Usercodeshouldneverdefinenamesthatbeginwith Pyor_Py. Thisconfusesthereader,andjeopardizesthe portabilityoftheusercodetofuture Pythonversions,whichmaydefineadditionalnamesbeginningwithoneof theseprefixes. The header files are typically installed with Python. On Unix, these are loc...
c-api.pdf
The Python/C API, Release 3. 12. 6 If Python is built in debug mode (if the Py_DEBUG macro is defined), the Py_ALWAYS_INLINE macro doesnothing. Itmustbespecifiedbeforethefunctionreturntype. Usage: static inline Py_ALWAYS_INLINE int random( void ){return 4;} Addedinversion3. 11. Py_CHARMASK (c) Argumentmustbeacharactero...
c-api.pdf
The Python/C API, Release 3. 12. 6 A use for Py_UNREACHABLE() is following a call a function that never returns but that is not declared _Py_NO_RETURN. Ifacodepathisveryunlikelycodebutcanbereachedunderexceptionalcase,thismacromustnotbeused. Forexample,underlowmemoryconditionorifasystemcallreturnsavalueoutoftheexpectedr...
c-api.pdf
The Python/C API, Release 3. 12. 6 1. 4. 1Reference Counts Thereferencecountisimportantbecausetoday'scomputershaveafinite(andoftenseverelylimited)memorysize; itcountshowmanydifferentplacestherearethathavea strong reference toanobject. Suchaplacecouldbeanother object,oraglobal(orstatic)Cvariable,oralocalvariableinsome C...
c-api.pdf
The Python/C API, Release 3. 12. 6 or list with newly created objects; for example, the code to create the tuple (1, 2, "three") could look like this(forgettingabouterrorhandlingforthemoment;abetterwaytocodethisisshownbelow): Py Object *t; t=Py Tuple_New( 3); Py Tuple_Set Item(t, 0,Py Long_From Long( 1L)); Py Tuple_Set...
c-api.pdf
The Python/C API, Release 3. 12. 6 Itisimportanttorealizethatwhetheryouownareferencereturnedbyafunctiondependsonwhichfunctionyoucall only— the plumage (thetypeoftheobjectpassedasanargumenttothefunction) doesn't enter into it! Thus,ifyou extractanitemfromalistusing Py List_Get Item(),youdon'townthereference—butifyouobta...
c-api.pdf
The Python/C API, Release 3. 12. 6 1. 4. 2Types There are few other data types that play a significant role in the Python/C API; most are simple C types such as int,long,doubleandchar*. Afewstructuretypesareusedtodescribestatictablesusedtolistthefunctions exported by a module or the data attributes of a new object type...
c-api.pdf
The Python/C API, Release 3. 12. 6 (continuedfrompreviouspage) item =dict[key] except Key Error : item =0 dict[key] =item +1 Hereisthecorresponding Ccode,inallitsglory: int incr_item (Py Object *dict, Py Object *key) { /* Objects all initialized to NULL for Py_XDECREF */ Py Object *item =NULL,*const_one =NULL,*incremen...
c-api.pdf
The Python/C API, Release 3. 12. 6 1. 6Embedding Python Theoneimportanttaskthatonlyembedders(asopposedtoextensionwriters)ofthe Pythoninterpreterhavetoworry aboutistheinitialization,andpossiblythefinalization,ofthe Pythoninterpreter. Mostfunctionalityoftheinterpreter canonlybeusedaftertheinterpreterhasbeeninitialized. T...
c-api.pdf
The Python/C API, Release 3. 12. 6 Pleasereferto Misc/Special Builds. txt inthe Pythonsourcedistributionformoredetailedinformation. 1. 7. Debugging Builds 13
c-api.pdf
The Python/C API, Release 3. 12. 6 14 Chapter 1. Introduction
c-api.pdf
CHAPTER TWO C API STABILITY Unlessdocumentedotherwise,Python's CAPIiscoveredbythe Backwards Compatibility Policy, PEP 387. Most changestoitaresource-compatible(typicallybyonlyaddingnew API). Changingexisting APIorremoving APIis onlydoneafteradeprecationperiodortofixseriousissues. CPython's Application Binary Interface(...
c-api.pdf
The Python/C API, Release 3. 12. 6 2. 2. 1Limited C API Python3. 2introducedthe Limited API,asubsetof Python's CAPI. Extensionsthatonlyusethe Limited APIcanbe compiledonceandworkwithmultipleversionsof Python. Contentsofthe Limited APIare listed below. Py_LIMITED_API Definethismacrobeforeincluding Python. h tooptintoonl...
c-api.pdf
The Python/C API, Release 3. 12. 6 2. 2. 4Limited API Caveats Notethatcompilingwith Py_LIMITED_API isnotacompleteguaranteethatcodeconformstothe Limited API or the Stable ABI. Py_LIMITED_API onlycoversdefinitions,butan APIalsoincludesotherissues,suchasexpected semantics. One issue that Py_LIMITED_API does not guard agai...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Buffer_Fill Contiguous Strides() Py Buffer_Fill Info() Py Buffer_From Contiguous() Py Buffer_Get Pointer() Py Buffer_Is Contiguous() Py Buffer_Release() Py Buffer_Size From Format() Py Buffer_To Contiguous() Py Byte Array Iter_Type Py Byte Array_As String() Py Byte Array_Concat() P...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py CMethod_New() Py Call Iter_New() Py Call Iter_Type Py Callable_Check() Py Capsule_Destructor Py Capsule_Get Context() Py Capsule_Get Destructor() Py Capsule_Get Name() Py Capsule_Get Pointer() Py Capsule_Import() Py Capsule_Is Valid() Py Capsule_New() Py Capsule_Set Context() Py Ca...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Complex_Real As Double() Py Complex_Type Py Descr_New Class Method() Py Descr_New Get Set() Py Descr_New Member() Py Descr_New Method() Py Dict Items_Type Py Dict Iter Item_Type Py Dict Iter Key_Type Py Dict Iter Value_Type Py Dict Keys_Type Py Dict Proxy_New() Py Dict Proxy_Type P...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Err_Bad Argument() Py Err_Bad Internal Call() Py Err_Check Signals() Py Err_Clear() Py Err_Display() Py Err_Display Exception() Py Err_Exception Matches() Py Err_Fetch() Py Err_Format() Py Err_Format V() Py Err_Get Exc Info() Py Err_Get Handled Exception() Py Err_Get Raised Excepti...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Err_Set Interrupt Ex() Py Err_Set None() Py Err_Set Object() Py Err_Set Raised Exception() Py Err_Set String() Py Err_Syntax Location() Py Err_Syntax Location Ex() Py Err_Warn Ex() Py Err_Warn Explicit() Py Err_Warn Format() Py Err_Write Unraisable() Py Eval_Acquire Lock() Py Eval_...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Exc_Buffer Error Py Exc_Bytes Warning Py Exc_Child Process Error Py Exc_Connection Aborted Error Py Exc_Connection Error Py Exc_Connection Refused Error Py Exc_Connection Reset Error Py Exc_Deprecation Warning Py Exc_EOFError Py Exc_Encoding Warning Py Exc_Environment Error Py Exc_...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Exc_Resource Warning Py Exc_Runtime Error Py Exc_Runtime Warning Py Exc_Stop Async Iteration Py Exc_Stop Iteration Py Exc_Syntax Error Py Exc_Syntax Warning Py Exc_System Error Py Exc_System Exit Py Exc_Tab Error Py Exc_Timeout Error Py Exc_Type Error Py Exc_Unbound Local Error Py ...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Float_From String() Py Float_Get Info() Py Float_Get Max() Py Float_Get Min() Py Float_Type Py Frame Object Py Frame_Get Code() Py Frame_Get Line Number() Py Frozen Set_New() Py Frozen Set_Type Py GC_Collect() Py GC_Disable() Py GC_Enable() Py GC_Is Enabled() Py GILState_Ensure() P...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Import_Reload Module() Py Index_Check() Py Interpreter State Py Interpreter State_Clear() Py Interpreter State_Delete() Py Interpreter State_Get() Py Interpreter State_Get Dict() Py Interpreter State_Get ID() Py Interpreter State_New() Py Iter_Check() Py Iter_Next() Py Iter_Send() ...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Long_As Void Ptr() Py Long_From Double() Py Long_From Long() Py Long_From Long Long() Py Long_From Size_t() Py Long_From Ssize_t() Py Long_From String() Py Long_From Unsigned Long() Py Long_From Unsigned Long Long() Py Long_From Void Ptr() Py Long_Get Info() Py Long_Type Py Map_Typ...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Module Def_Base Py Module Def_Init() Py Module Def_Type Py Module_Add Functions() Py Module_Add Int Constant() Py Module_Add Object() Py Module_Add Object Ref() Py Module_Add String Constant() Py Module_Add Type() Py Module_Create2() Py Module_Exec Def() Py Module_From Def And Spec...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Number_In Place Remainder() Py Number_In Place Rshift() Py Number_In Place Subtract() Py Number_In Place True Divide() Py Number_In Place Xor() Py Number_Index() Py Number_Invert() Py Number_Long() Py Number_Lshift() Py Number_Matrix Multiply() Py Number_Multiply() Py Number_Negati...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py OS_vsnprintf() Py Object Py Object. ob_refcnt Py Object. ob_type Py Object_ASCII() Py Object_As Char Buffer() Py Object_As File Descriptor() Py Object_As Read Buffer() Py Object_As Write Buffer() Py Object_Bytes() Py Object_Call() Py Object_Call Function() Py Object_Call Function O...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object_Get Buffer() Py Object_Get Item() Py Object_Get Iter() Py Object_Get Type Data() Py Object_Has Attr() Py Object_Has Attr String() Py Object_Hash() Py Object_Hash Not Implemented() Py Object_Init() Py Object_Init Var() Py Object_Is Instance() Py Object_Is Subclass() Py Object...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Sequence_Del Item() Py Sequence_Del Slice() Py Sequence_Fast() Py Sequence_Get Item() Py Sequence_Get Slice() Py Sequence_In() Py Sequence_In Place Concat() Py Sequence_In Place Repeat() Py Sequence_Index() Py Sequence_Length() Py Sequence_List() Py Sequence_Repeat() Py Sequence_Se...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Struct Sequence_Set Item() Py Struct Sequence_Unnamed Field Py Super_Type Py Sys_Add Warn Option() Py Sys_Add Warn Option Unicode() Py Sys_Add XOption() Py Sys_Format Stderr() Py Sys_Format Stdout() Py Sys_Get Object() Py Sys_Get XOptions() Py Sys_Has Warn Options() Py Sys_Reset Wa...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Thread_get_key_value() Py Thread_get_stacksize() Py Thread_get_thread_ident() Py Thread_get_thread_native_id() Py Thread_init_thread() Py Thread_release_lock() Py Thread_set_key_value() Py Thread_set_stacksize() Py Thread_start_new_thread() Py Thread_tss_alloc() Py Thread_tss_creat...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Type_Get Qual Name() Py Type_Get Slot() Py Type_Get Type Data Size() Py Type_Is Subtype() Py Type_Modified() Py Type_Ready() Py Type_Slot Py Type_Spec Py Type_Type Py Unicode Decode Error_Create() Py Unicode Decode Error_Get Encoding() Py Unicode Decode Error_Get End() Py Unicode D...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Unicode_As Decoded Unicode() Py Unicode_As Encoded Object() Py Unicode_As Encoded String() Py Unicode_As Encoded Unicode() Py Unicode_As Latin1String() Py Unicode_As MBCSString() Py Unicode_As Raw Unicode Escape String() Py Unicode_As UCS4() Py Unicode_As UCS4Copy() Py Unicode_As U...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Unicode_Decode UTF7Stateful() Py Unicode_Decode UTF8() Py Unicode_Decode UTF8Stateful() Py Unicode_Decode Unicode Escape() Py Unicode_Encode Code Page() Py Unicode_Encode FSDefault() Py Unicode_Encode Locale() Py Unicode_FSConverter() Py Unicode_FSDecoder() Py Unicode_Find() Py Uni...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Unicode_Write Char() Py Var Object Py Var Object. ob_base Py Var Object. ob_size Py Vectorcall_Call() Py Vectorcall_NARGS() Py Weak Reference Py Weakref_Get Object() Py Weakref_New Proxy() Py Weakref_New Ref() Py Wrapper Descr_Type Py Wrapper_New() Py Zip_Type Py_Add Pending Call()...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py_Get Platform() Py_Get Prefix() Py_Get Program Full Path() Py_Get Program Name() Py_Get Python Home() Py_Get Recursion Limit() Py_Get Version() Py_Has File System Default Encoding Py_Inc Ref() Py_Initialize() Py_Initialize Ex() Py_Is() Py_Is False() Py_Is Initialized() Py_Is None() ...
c-api.pdf
The Python/C API, Release 3. 12. 6 descrgetfunc descrsetfunc destructor getattrfunc getattrofunc getbufferproc getiterfunc getter hashfunc initproc inquiry iternextfunc lenfunc newfunc objobjargproc objobjproc releasebufferproc reprfunc richcmpfunc setattrfunc setattrofunc setter ssizeargfunc ssizeobjargproc ssizessize...
c-api.pdf
CHAPTER THREE THE VERY HIGH LEVEL LAYER Thefunctionsinthischapterwillletyouexecute Pythonsourcecodegiveninafileorabuffer,buttheywillnotlet youinteractinamoredetailedwaywiththeinterpreter. Severalofthesefunctionsacceptastartsymbolfromthegrammarasaparameter. Theavailablestartsymbolsare Py_eval_input,Py_file_input, and Py...
c-api.pdf
The Python/C API, Release 3. 12. 6 int Py Run_Simple String (constchar*command ) This is a simplified interface to Py Run_Simple String Flags() below, leaving the Py Compiler Flags *argumentsetto NULL. int Py Run_Simple String Flags (constchar*command, Py Compiler Flags *flags ) Executesthe Pythonsourcecodefrom command...
c-api.pdf
The Python/C API, Release 3. 12. 6 from the provided standard input file, returning the resulting string. For example, The readline module setsthishooktoprovideline-editingandtab-completionfeatures. Theresultmustbeastringallocatedby Py Mem_Raw Malloc() or Py Mem_Raw Realloc(),or NULLif anerroroccurred. Changed in versi...
c-api.pdf
The Python/C API, Release 3. 12. 6 Addedinversion3. 4. Py Object*Py_Compile String Ex Flags (constchar*str,constchar*filename,intstart, Py Compiler Flags *flags,intoptimize ) Return value: New reference. Like Py_Compile String Object(),butfilenameisabytestringdecoded fromthe filesystem encoding and error handler. Added...
c-api.pdf
The Python/C API, Release 3. 12. 6 intcf_feature_version cf_feature_version istheminor Pythonversion. Itshouldbeinitializedto PY_MINOR_VERSION. Thefieldisignoredbydefault,itisusedifandonlyif Py CF_ONLY_AST flagissetin cf_flags. Changedinversion3. 8: Added cf_feature_version field. int CO_FUTURE_DIVISION Thisbitcanbeset...
c-api.pdf
The Python/C API, Release 3. 12. 6 46 Chapter 3. The Very High Level Layer
c-api.pdf
CHAPTER FOUR REFERENCE COUNTING Thefunctionsandmacrosinthissectionareusedformanagingreferencecountsof Pythonobjects. Py_ssize_t Py_REFCNT (Py Object*o) Getthereferencecountofthe Pythonobject o. Notethatthereturnedvaluemaynotactuallyreflecthowmanyreferencestotheobjectareactuallyheld. For example,someobjectsare“immortal”...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py_INCREF(obj); self->attr =obj; canbewrittenas: self->attr =Py_New Ref(obj); Seealso Py_INCREF(). Addedinversion3. 10. Py Object*Py_XNew Ref (Py Object*o) Part of the Stable ABI since version 3. 10. Similarto Py_New Ref(),buttheobject ocanbe NULL. Iftheobject ois NULL,thefunctionjust...
c-api.pdf
The Python/C API, Release 3. 12. 6 void Py_Dec Ref (Py Object*o) Part of the Stable ABI. Releasea strong reference toobject o. Afunctionversionof Py_XDECREF(). Itcan beusedforruntimedynamicembeddingof Python. Py_SETREF (dst,src ) Macrosafelyreleasinga strong reference toobject dstandsetting dsttosrc. Asincaseof Py_CLEA...
c-api.pdf
The Python/C API, Release 3. 12. 6 50 Chapter 4. Reference Counting
c-api.pdf
CHAPTER FIVE EXCEPTION HANDLING Thefunctionsdescribedinthischapterwillletyouhandleandraise Pythonexceptions. Itisimportanttounderstand some of the basics of Python exception handling. It works somewhat like the POSIX errnovariable: there is a globalindicator(perthread)ofthelasterrorthatoccurred. Most CAPIfunctionsdon't...
c-api.pdf
The Python/C API, Release 3. 12. 6 void Py Err_Write Unraisable (Py Object*obj) Part of the Stable ABI. Callsys. unraisablehook() usingthecurrentexceptionand objargument. This utility function prints a warning message to sys. stderr when an exception has been set but it is impossiblefortheinterpretertoactuallyraisethee...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object*Py Err_Set From Errno (Py Object*type) Return value: Always NULL. Part of the Stable ABI. Thisisaconveniencefunctiontoraiseanexceptionwhen a C library function has returned an error and set the C variable errno. It constructs a tuple object whose firstitemistheinteger errnov...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object*Py Err_Set Exc From Windows Err With Filename Objects (Py Object*type,intierr, Py Object *filename, Py Object*filename2 ) Return value: Always NULL. Part of the Stable ABI on Windows since version 3. 7. Similar to Py Err_Set Exc From Windows Err With Filename Object(),butacc...
c-api.pdf
The Python/C API, Release 3. 12. 6 5. 3Issuing warnings Usethesefunctionstoissuewarningsfrom Ccode. Theymirrorsimilarfunctionsexportedbythe Python warnings module. Theynormallyprintawarningmessageto sys. stderr;however,itisalsopossiblethattheuserhasspecified that warnings are to be turned into errors, and in that case ...
c-api.pdf
The Python/C API, Release 3. 12. 6 Note Donotcomparethereturnvaluetoaspecificexception;use Py Err_Exception Matches() instead, shownbelow. (Thecomparisoncouldeasilyfailsincetheexceptionmaybeaninstanceinsteadofaclass, inthecaseofaclassexception,oritmaybeasubclassoftheexpectedexception. ) int Py Err_Exception Matches (Py...
c-api.pdf
The Python/C API, Release 3. 12. 6 Note Thisfunctionisnormallyonlyusedbylegacycodethatneedstocatchexceptionsorsaveandrestorethe errorindicatortemporarily. Forexample: { Py Object *type, *value, *traceback; Py Err_Fetch( &type, &value, &traceback); /*... code that might produce other errors... */ Py Err_Restore(type, va...
c-api.pdf
The Python/C API, Release 3. 12. 6 Note Thisfunctionisnotnormallyusedbycodethatwantstohandleexceptions. Rather,itcanbeusedwhencode needs to save and restore the exception state temporarily. Use Py Err_Set Handled Exception() torestoreorcleartheexceptionstate. Addedinversion3. 11. void Py Err_Set Handled Exception (Py O...
c-api.pdf
The Python/C API, Release 3. 12. 6 5. 5Signal Handling int Py Err_Check Signals () Part of the Stable ABI. Thisfunctioninteractswith Python'ssignalhandling. Ifthefunctioniscalledfromthemainthreadandunderthemain Pythoninterpreter,itcheckswhetherasignal hasbeensenttotheprocessesandifso,invokesthecorrespondingsignalhandle...
c-api.pdf
The Python/C API, Release 3. 12. 6 Changedinversion3. 5: On Windows,thefunctionnowalsosupportssockethandles. 5. 6Exception Classes Py Object*Py Err_New Exception (constchar*name, Py Object*base, Py Object*dict) Return value: New reference. Part of the Stable ABI. This utility function creates and returns a new excep-ti...
c-api.pdf
The Python/C API, Release 3. 12. 6 void Py Exception_Set Args (Py Object*ex,Py Object*args) Part of the Stable ABI since version 3. 12. Setargsofexception extoargs. Py Object*Py Unstable_Exc_Prep Reraise Star (Py Object*orig, Py Object*excs) Thisis Unstable API. Itmaychangewithoutwarninginminorreleases. Implementpartof...
c-api.pdf
The Python/C API, Release 3. 12. 6 int Py Unicode Translate Error_Set End (Py Object*exc, Py_ssize_t end) Part of the Stable ABI. Setthe endattributeofthegivenexceptionobjectto end. Return 0onsuccess,-1on failure. Py Object*Py Unicode Decode Error_Get Reason (Py Object*exc) Py Object*Py Unicode Encode Error_Get Reason ...
c-api.pdf
The Python/C API, Release 3. 12. 6 5. 10Standard Exceptions Allstandard Pythonexceptionsareavailableasglobalvariableswhosenamesare Py Exc_followedbythe Python exception name. These have the type Py Object *; they are all class objects. For completeness, here are all the variables: CName Python Name Notes Py Exc_Base Ex...
c-api.pdf
The Python/C API, Release 3. 12. 6 Table 1-continuedfrompreviouspage CName Python Name Notes Py Exc_Unicode Encode Error Unicode Encode Error Py Exc_Unicode Error Unicode Error Py Exc_Unicode Translate Error Unicode Translate Error Py Exc_Value Error Value Error Py Exc_Zero Division Error Zero Division Error Added in v...
c-api.pdf
CHAPTER SIX UTILITIES The functions in this chapter perform various utility tasks, ranging from helping C code be more portable across platforms, using Python modules from C, and parsing function arguments and constructing Python values from C values. 6. 1Operating System Utilities Py Object*Py OS_FSPath (Py Object*pat...
c-api.pdf
The Python/C API, Release 3. 12. 6 Warning The C fork()callshouldonlybemadefromthe “main” thread (ofthe “main” interpreter ). Thesameis truefor Py OS_After Fork_Parent(). Addedinversion3. 7. void Py OS_After Fork_Child () Part of the Stable ABI on platforms with fork() since version 3. 7. Functiontoupdateinternalinterp...
c-api.pdf
The Python/C API, Release 3. 12. 6 Thisfunctionmustnotbecalledbefore Python is preinitialized andsothatthe LC_CTYPElocaleisproperly configured: seethe Py_Pre Initialize() function. Decodeabytestringfromthe filesystem encoding and error handler. Iftheerrorhandlerissurrogateescapeer-rorhandler,undecodablebytesaredecodeda...
c-api.pdf
The Python/C API, Release 3. 12. 6 Changedinversion3. 7: Thefunctionnowusesthe UTF-8encodinginthe Python UTF-8Mode. Changed in version 3. 8: The function now uses the UTF-8 encoding on Windows if Py Pre Config. legacy_windows_fs_encoding iszero. 6. 2System Functions These are utility functions that make functionality f...
c-api.pdf
The Python/C API, Release 3. 12. 6 void Py Sys_Write Stderr (constchar*format,... ) Part of the Stable ABI. As Py Sys_Write Stdout(),butwriteto sys. stderr orstderrinstead. void Py Sys_Format Stdout (constchar*format,... ) Part of the Stable ABI. Function similar to Py Sys_Write Stdout() but format the message using Py...
c-api.pdf
The Python/C API, Release 3. 12. 6 If the interpreter is initialized, this function raises an auditing event sys. addaudithook with no argu-ments. Ifanyexistinghooksraiseanexceptionderivedfrom Exception, thenewhookwillnotbeadded and the exception is cleared. As a result, callers cannot assume that their hook has been a...
c-api.pdf
The Python/C API, Release 3. 12. 6 Thereturnvalueisanewreferencetotheimportedmoduleortop-levelpackage,or NULLwithanexception setonfailure. Likefor __import__(),thereturnvaluewhenasubmoduleofapackagewasrequestedis normallythetop-levelpackage,unlessanon-empty fromlistwasgiven. Failingimportsremoveincompletemoduleobjects,...
c-api.pdf
The Python/C API, Release 3. 12. 6 sys. modules onentryto Py Import_Exec Code Module(). Leavingincompletelyinitializedmodules insys. modules isdangerous,asimportsofsuchmoduleshavenowaytoknowthatthemoduleobjectis anunknown(andprobablydamagedwithrespecttothemoduleauthor'sintents)state. Themodule's __spec__ and__loader__ ...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object*Py Import_Get Module Dict () Return value: Borrowed reference. Part of the Stable ABI. Returnthedictionaryusedforthemoduleadmin-istration(a. k. a. sys. modules ). Notethatthisisaper-interpretervariable. Py Object*Py Import_Get Module (Py Object*name ) Return value: New refer...
c-api.pdf
The Python/C API, Release 3. 12. 6 constchar* name Themodulename,asan ASCIIencodedstring. Py Object*(*initfunc )(void) Initializationfunctionforamodulebuiltintotheinterpreter. int Py Import_Extend Inittab (struct _inittab*newtab ) Addacollectionofmodulestothetableofbuilt-inmodules. The newtabarraymustendwithasentinelen...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object*Py Marshal_Read Last Object From File (FILE*file ) Return value: New reference. Return a Python object from the data stream in a FILE*opened for reading. Unlike Py Marshal_Read Object From File(),thisfunctionassumesthatnofurtherobjectswillberead fromthefile,allowingittoaggre...
c-api.pdf
The Python/C API, Release 3. 12. 6 Note For all #variants of formats ( s#,y#, etc. ), the macro PY_SSIZE_T_CLEAN must be defined before in-cluding Python. h. On Python 3. 9 and older, the type of the length argument is Py_ssize_t if the PY_SSIZE_T_CLEAN macroisdefined,orintotherwise. s(str) [const char *] Converta Unic...
c-api.pdf
The Python/C API, Release 3. 12. 6 U(str) [Py Object *] Requiresthatthe Pythonobjectisa Unicodeobject,withoutattemptinganyconversion. Raises Type Error iftheobjectisnota Unicodeobject. The Cvariablemayalsobedeclaredas Py Object *. w*(read-write bytes-like object ) [Py_buffer] This format accepts any object which implem...
c-api.pdf
The Python/C API, Release 3. 12. 6 Numbers b(int) [unsigned char] Convertanonnegative Pythonintegertoanunsignedtinyint,storedina C unsigned char. B(int) [unsigned char] Converta Pythonintegertoatinyintwithoutoverflowchecking,storedina C unsigned char. h(int) [short int] Converta Pythonintegertoa C short int. H(int) [un...
c-api.pdf
The Python/C API, Release 3. 12. 6 O&(object) [ converter,anything ] Convert a Python object to a C variable through a converterfunction. This takes two arguments: the first is afunction, thesecondistheaddressofa Cvariable(ofarbitrarytype), convertedto void*. The converter functioninturniscalledasfollows: status =conve...
c-api.pdf
The Python/C API, Release 3. 12. 6 the Py Arg_Parse* functionsfailduetoconversionfailureinoneoftheformatunits,thevariablesattheaddresses correspondingtothatandthefollowingformatunitsareleftuntouched. API Functions int Py Arg_Parse Tuple (Py Object*args,constchar*format,... ) Part of the Stable ABI. Parse the parameters...
c-api.pdf
The Python/C API, Release 3. 12. 6 (continuedfrompreviouspage) if(Py Arg_Unpack Tuple(args, "ref",1,2,&object, &callback)) { result =Py Weakref_New Ref(object, callback); } return result; } The call to Py Arg_Unpack Tuple() in this example is entirely equivalent to this call to Py Arg_Parse Tuple() : Py Arg_Parse Tuple...
c-api.pdf
The Python/C API, Release 3. 12. 6 u#(str) [const wchar_t *, Py_ssize_t ] Convert a Unicode (UTF-16 or UCS-4) data buffer and its length to a Python Unicode object. If the Unicodebufferpointeris NULL,thelengthisignoredand Noneisreturned. U(stror None ) [const char *] Sameas s. U#(stror None ) [const char *, Py_ssize_t ...
c-api.pdf
The Python/C API, Release 3. 12. 6 N(object) [Py Object *] Sameas O,exceptitdoesn'tcreateanew strong reference. Usefulwhentheobjectiscreatedbyacallto anobjectconstructorintheargumentlist. O&(object) [ converter,anything ] Convert anythingtoa Pythonobjectthrougha converterfunction. Thefunctioniscalledwith anything (whic...
c-api.pdf
The Python/C API, Release 3. 12. 6 Leadingwhitespaceandcaseofcharactersareignored. If baseiszeroitlooksforaleading 0b,0oor0xto tellwhichbase. Iftheseareabsentitdefaultsto 10. Basemustbe0orbetween2and36(inclusive). If ptr isnon-NULLitwillcontainapointertotheendofthescan. If the converted value falls out of range of corr...
c-api.pdf
The Python/C API, Release 3. 12. 6 Addedinversion3. 1. int Py OS_stricmp (constchar*s1,constchar*s2 ) Case insensitive comparison of strings. The function works almost identically to strcmp() except that it ignoresthecase. int Py OS_strnicmp (constchar*s1,constchar*s2, Py_ssize_t size) Caseinsensitivecomparisonofstring...
c-api.pdf
The Python/C API, Release 3. 12. 6 Py Object*Py Eval_Get Globals (void) Return value: Borrowed reference. Part of the Stable ABI. Return a dictionary of the global variables in the currentexecutionframe,or NULLifnoframeiscurrentlyexecuting. Py Frame Object *Py Eval_Get Frame (void) Return value: Borrowed reference. Par...
c-api.pdf
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
4