Functions for number conversion and formatted string output.
Output not more thansize bytes tostr according to the format stringformat and the extra arguments. See the Unix man pagesnprintf(2).
Output not more thansize bytes tostr according to the format stringformat and the variable argument listva. Unix man pagevsnprintf(2).
PyOS_snprintf() andPyOS_vsnprintf() wrap the Standard C libraryfunctionssnprintf() andvsnprintf(). Their purpose is toguarantee consistent behavior in corner cases, which the Standard C functions donot.
The wrappers ensure thatstr*[*size-1] is always'\0' upon return. Theynever write more thansize bytes (including the trailing'\0') into str.Both functions require thatstr!=NULL,size>0 andformat!=NULL.
If the platform doesn’t havevsnprintf() and the buffer size needed toavoid truncation exceedssize by more than 512 bytes, Python aborts with aPy_FatalError.
The return value (rv) for these functions should be interpreted as follows:
The following functions provide locale-independent string to number conversions.
Convert a strings to adouble, raising a Pythonexception on failure. The set of accepted strings corresponds tothe set of strings accepted by Python’sfloat() constructor,except thats must not have leading or trailing whitespace.The conversion is independent of the current locale.
Ifendptr isNULL, convert the whole string. RaiseValueError and return-1.0 if the string is not a validrepresentation of a floating-point number.
If endptr is notNULL, convert as much of the string aspossible and set*endptr to point to the first unconvertedcharacter. If no initial segment of the string is the validrepresentation of a floating-point number, set*endptr to pointto the beginning of the string, raise ValueError, and return-1.0.
Ifs represents a value that is too large to store in a float(for example,"1e500" is such a string on many platforms) thenifoverflow_exception isNULL returnPy_HUGE_VAL (withan appropriate sign) and don’t set any exception. Otherwise,overflow_exception must point to a Python exception object;raise that exception and return-1.0. In both cases, set*endptr to point to the first character after the converted value.
If any other error occurs during the conversion (for example anout-of-memory error), set the appropriate Python exception andreturn-1.0.
New in version 3.1.
Convert adoubleval to a string using suppliedformat_code,precision, andflags.
format_code must be one of'e','E','f','F','g','G' or'r'. For'r', the suppliedprecisionmust be 0 and is ignored. The'r' format code specifies thestandardrepr() format.
flags can be zero or more of the valuesPy_DTSF_SIGN,Py_DTSF_ADD_DOT_0, orPy_DTSF_ALT, or-ed together:
Ifptype is non-NULL, then the value it points to will be set to one ofPy_DTST_FINITE,Py_DTST_INFINITE, orPy_DTST_NAN, signifying thatval is a finite number, an infinite number, or not a number, respectively.
The return value is a pointer tobuffer with the converted string orNULL if the conversion failed. The caller is responsible for freeing thereturned string by callingPyMem_Free().
New in version 3.1.
Case insensitive comparison of strings. The function works almostidentically tostrcmp() except that it ignores the case.
Case insensitive comparison of strings. The function works almostidentically tostrncmp() except that it ignores the case.
Parsing arguments and building values
Enter search terms or a module, class or function name.