Red de conocimiento informático - Problemas con los teléfonos móviles - ¿Cómo funcionan los inicios y finales de Python? Encontré el archivo py pero lo que realmente dice es

¿Cómo funcionan los inicios y finales de Python? Encontré el archivo py pero lo que realmente dice es

Para responder a tu pregunta, descargué el código fuente de Python (github python/cpython) y busqué.

En primer lugar, puede estar seguro de que está implementado en lenguaje C, por lo que solo podrá ver la declaración en el entorno de desarrollo integrado.

Luego busque: busque .-type f?-name '*.c' |xargs grep -s 'startswith'

Puede ver

/. Objetos/bytesobject.c: bytes_startswith(PyBytesObject *self, PyObject *args)static?PyObject?*

bytes_startswith(PyBytesObject?*self, ?PyObject?*args)

{

return?_Py_bytes_startswith(PyBytes_AS_STRING(self),?PyBytes_GET_SIZE(self),? args);

}PyObject?*

_Py_bytes_startswith(const?char? * str,?Py_ssize_t?len,?PyObject?*args)

{

Devuelve _Py_ bytes_tailmatch(str,?len,? "startswith",?args,? -1 );

}

/*?Haga coincidir el final del búfer (dirección?gt;=?0) o el principio (dirección?lt;?Valor de retorno*?Regreso en caso de error - 1, devuelve 0 si no se encuentra, devuelve 1 si se encuentra.

*/

static int

tailmatch(const char *str, Py_ssize_t len, PyObject * substr, Py_ssize_t start, Py_ssize_t end, int dirección)

{

Py_buffer?sub_view?=?{NULL,?NULL};

const?char?*sub;

Py_ssize_t?slen;

if(PyBytes_Check(substr))?{

sub=PyBytes_AS_STRING(substr);

slen=PyBytes_GET_SIZE(substr);

}

¿else?{

if(PyObject_GetBuffer( substr,? amp; sub_view,?PyBUF_SIMPLE)? =?0)

retorno?

sub? =?sub_view.buf;

slen?=?sub_view.len;

}

ADJUST_INDICES(inicio,?fin,?len);

if.(dirección?lt;?0)?{

/*?startswith?*/

if ?(inicio? ?slen?gt;?len)

ir a?notfound;

} ¿más?

(end?-?slen?lt;?len)

si?( end?-?slen?gt;?start)

start?=?end?-?slen;

}

si?

if(memcmp(str? ?start, ?sub, ?slen)!=?0)

goto?notfound;

PyBuffer_Release(amp;sub_view);

¿regresar?;

no encontrado:

PyBuffer_Release(amp; sub_view);

PyBuffer_Release(amp; sub_view);

volver? vista);

regresar?0;

}