PYTHON

A quick look

Anshuman
3 min readDec 31, 2020

What do you get when you download “Python” from the official website?

NOTE:I do not want you to bookmark this page/save for future just because “It was too long and technical”,that is why,i will not go too deep into the subject matter.(graze would suffice)

Go to python.org and download the source code.This is the “language” you keep on referring in your conversations with friends.
Let us pick one ,I pick python 3.4.4

click on XZ compressed source tarball

you get a .tar file.If you don’t know how to mess around with tar balls,i will not suggest going too deep here,as our concern is not tar balls or how they work.

install 7-zip

Extract .xz and .tar with 7-zip

now you have a folder(of folders),with python source code distributed among various folders according to their functionality and uses.
Let us finish them one by one

1-DOC:
There are some .rst files.rst stands for restructured text.The reference python comes with its documentation and these .rst files are responsible for creating that.

For Example ,Inside the compound_stmts.rst, documentation for compound statements, you can see a simple example defining the with statement.

2-Grammar:

We discussed some thing briefly about “Grammar”,hows and whats in previous article .

See if you can make sense of these statements.(If you will open the file present in the Grammar folder,you will see something like this.)

single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE

stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (‘;’ small_stmt)* [‘;’] NEWLINE
small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt

compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated

Now do you see a connection between how you write your python code and these lines.Looks like a generalised version of your code right?

These are called Production Rules ,one of the four sets that define a Grammar.

This will be used by a Parser to check if the code we have written is syntactically right or not.

Note:We are leaving Tokens for now,if you are interested you can search more,full on geek mode.

3-Include:

Contains the C language header files.

These provide different different functionalities and are added to various C files when needed.

4-lib:

Standard library modules written in python itself(like venv,which is responsible for evnvironment management etc.)

Note:Some of the modules are scattered and are half in C and half in python,the C part is found in folder Modules

5-Mac:

Mac os specific support files.(containing OS specific IDLE Interpreter etc.)

6-Misc:

As the name suggests, Miscellaneous files(not our concern)

7-Modules:

Remaining Library modules

written in C.

8-Objects:

The reference implementation of python provides various object types(everything in python is an object).

You can see tuple,dict etc defined here.

9-Parser:

The python parser source code.This parser makes sense of our code.
Here “makes sense” means checking it against the Grammar.

10-PC:

Windows specific support files.

11-PCBuild:

For Older windows versions.

12-Python:

The Cpython Interpreter source code.This folder is the reason why it is called CPython.As you can see ,everything here seems to be written is C.

You might ask why C?Why can’t we write this in Python itself?
This reuires understanding types of compilers(We’ll see Later).

13-Tools:

For more functionality extension.

README File:

Everything about this version of Python,including contacts to approach for any suggestions or query,technical specifications etc.

--

--

Anshuman
0 Followers

CS undergrad into physics🚩Linguistics Economics