Skip to content

Commit 510575b

Browse files
committed
docs: __main__ data protocol method
1 parent 60605e1 commit 510575b

9 files changed

Lines changed: 88 additions & 29 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def python_runtime_services:
2+
- formal: ???
3+
4+
- in words: ???
5+
6+
- plain english: modules to interact with the Python interpreter and its runtime environment.
7+
8+
- intuition: ???
9+
10+
- properties: ???
11+
12+
- examples: ???
13+
14+
- use cases: ???
15+
16+
- proof: ???
17+
18+
References: ???
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def __main__"
2+
- formal: ???
3+
4+
- in words:
5+
- name for two Python constructs:
6+
1. default name of the top-level environment.
7+
2. __main__.py in Python packages
8+
- plain english:
9+
1. default name of the entry-point of a Python program:
10+
- akin to Java's: public static void main, C's int main, etc
11+
- intuition: ???
12+
13+
- properties:
14+
15+
16+
- examples:
17+
see: 4_experiments/2_standard_library/29_python_runtime_services/5_top_level_code_environment
18+
19+
- use cases:
20+
- a module can use it to detect if it is the entry-point of the program, with the idom below:
21+
``` python
22+
if __name__ == __main__:
23+
# perform entry-point code
24+
```
25+
26+
- proof: ???
27+
28+
References: ???
29+
Python Software Foundation. 2025. Python Runtime Services, The Python Standard Library. https://docs.python.org/3/library/__main__.html#
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from foo import foo
2+
3+
4+
def bar():
5+
print("In bar function")
6+
print(f"top-level code module: {__name__}")
7+
foo()
8+
9+
10+
if __name__ == "__main__":
11+
print("In bar module, as top-level code environment")
12+
bar()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
top level code is also called the entry-point.
3+
"""
4+
5+
6+
def foo():
7+
print("In foo function")
8+
print(f"top-level code module: {__name__}")
9+
10+
11+
if __name__ == "__main__":
12+
print("In foo module, as top-level code environment")
13+
foo()

4_experiments/2_standard_library/29_python_runtime_services/top_level_environment_name.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

4_experiments/2_standard_library/29_python_runtime_services/top_level_environment_name_sub_routine.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM mcr.microsoft.com/devcontainers/python:3.11
1+
FROM mcr.microsoft.com/devcontainers/python:3
22

33
WORKDIR /python
44

55
COPY . .
66

77
RUN apt-get update \
88
&& apt-get install aspell -y
9-
9+
1010
RUN python -m pip install -r requirements.txt
1111

1212
RUN adduser -u 5678 --disabled-password --gecos "" python && chown -R python /python

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
- Python's design, implementation and ecosystem.
1313

1414
## Language Details
15-
- [Language Reference](https://docs.python.org/3.11/reference/index.html#reference*index)
15+
- [Language Reference](https://docs.python.org/3/reference/index.html)
1616
- [Interpreter](https://github.com/python/cpython)
1717
- [Bennett, J. 2019. See CPython run: Getting to know your Python interpreter. North Bay Python](https://www.youtube.com/watch?v=tzYhv61piNY)
1818
- [Modules Index](https://docs.python.org/3/py-modindex.html)
1919
- Memory Model:
2020
- [Computational Complexity Cost Model](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-fall-2011/pages/readings/python-cost-model/)
21-
- [Standard Library](https://docs.python.org/3.11/library/index.html)
21+
- [Standard Library](https://docs.python.org/3/library/index.html)
2222
- [Packaging and Distribution](https://packaging.python.org/en/latest/)
2323
- [Package Index](https://pypi.org)
2424
- [Python Packaging Authority](https://www.pypa.io/en/latest/)
@@ -29,10 +29,10 @@
2929
- [pipenv](https://pipenv.pypa.io/en/latest/)
3030
- Structuring Projects
3131
- ...
32-
- [Extending and Embedding](https://docs.python.org/3.11/extending/index.html)
32+
- [Extending and Embedding](https://docs.python.org/3/extending/index.html)
3333
- [PEP Index](https://www.python.org/dev/peps/)
3434
- [Developer Contribution Guide](https://devguide.python.org/)
35-
- [Glossary](https://docs.python.org/3.11/glossary.html)
35+
- [Glossary](https://docs.python.org/3/glossary.html)
3636
- [History](https://docs.python.org/3/license.html)
3737

3838
## Community

array_manipulation_algorithm.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
min_query_index
3+
max_query_index
4+
5+
applicable_indices_sums = generate indices from min_query_index to max_query_index+1
6+
save them in dictionary
7+
8+
for idx, in applicable_indices_sums:
9+
for all queries:
10+
increment idx sum, if its in the queries range(i.e. >= a and <=b)

0 commit comments

Comments
 (0)