1

I like to read the source of src.contains(). As src is a python built-in class and it is open source I think it is available for inspection. I can see the definition in builtins.pyi. For the source I downloaded : git clone https://github.com/python/cpython/ and searched for "class src(", I found nothing. In cpython/Lib/string.py I see a reference to "import _string" but again I am unable to find _string.py. Can you explain to me the procedure I have to follow to find a class implementation? Thanks.

2 Answers 2

1

check out the python documentation:https://docs.python.org/3.10/ That's usually the first and best place to look up something related to a package or program.

This link https://docs.python.org/3.10/py-modindex.html redirects you to the bultin modules of python. When you click on one of them you will see a link to the source code beneath the header.

Hope that helped.

Sign up to request clarification or add additional context in comments.

Comments

0

Since you are digging the cpython source code, you must be familiar with python。

we can get the answer like this, in ipython:

In [1]: import _string

In [2]: dir(_string)

Out[2]: ['doc', 'loader', 'name', 'package', 'spec', 'formatter_field_name_split', 'formatter_parser']

In [3]: _string.package

Out[3]: ''

In [4]: _string.loader

Out[4]: _frozen_importlib.BuiltinImporter

At this time,we can see this _string module came from BuiltinImporter

And There is method called formatter_field_name_split, search this name in the project you will find that in Objects/unicodeobject.c

At the end of this file ,you `ll get all you want

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.