Skip to content

Commit 97e4271

Browse files
author
Roy, Debakar
committed
Update slides and requirements.txt file
1 parent b136733 commit 97e4271

10 files changed

+108
-58
lines changed

content/00_index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"name": "python",
5555
"nbconvert_exporter": "python",
5656
"pygments_lexer": "ipython3",
57-
"version": "3.11.4"
57+
"version": "3.8.18"
5858
}
5959
},
6060
"nbformat": 4,

content/01_python_basic_overview.ipynb

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
" PI = 3.14159\n",
175175
" ```\n",
176176
"<br />\n",
177+
"\n",
177178
"8. **Global Identifiers:**\n",
178179
" ```python\n",
179180
" global_variable = 10\n",
@@ -249,7 +250,7 @@
249250
"id": "f9271fdf-38aa-410f-b258-fc325e23b8c7",
250251
"metadata": {},
251252
"source": [
252-
"❗**Gotcha**: `isidentifier` is a bit misleading as it returns `True` for keywords which cannot be used as identifier. There is already [an issue for that](https://bugs.python.org/issue33014)."
253+
"❗**Gotcha**: `isidentifier` is a bit misleading as it returns `True` for keywords which cannot be used as identifier."
253254
]
254255
},
255256
{
@@ -297,6 +298,27 @@
297298
"with = 1"
298299
]
299300
},
301+
{
302+
"cell_type": "code",
303+
"execution_count": null,
304+
"id": "f07984dc-358c-4591-a2ef-0433ec3b91da",
305+
"metadata": {},
306+
"outputs": [],
307+
"source": [
308+
"from tabulate import tabulate\n",
309+
"\n",
310+
"\n",
311+
"table_data = []\n",
312+
"for possible_identifier in possible_identifiers:\n",
313+
" is_identifier = possible_identifier.isidentifier()\n",
314+
" is_keyword = possible_identifier in keyword.kwlist\n",
315+
" table_data.append([possible_identifier, is_identifier, is_keyword])\n",
316+
"\n",
317+
"headers = [\"Identifier\", \"isidentifier\", \"iskeyword\"]\n",
318+
"\n",
319+
"print(tabulate(table_data, headers=headers, tablefmt=\"grid\"))"
320+
]
321+
},
300322
{
301323
"cell_type": "markdown",
302324
"id": "479277ab-15f9-4261-a932-bb8e160e702c",
@@ -349,6 +371,10 @@
349371
"execution_count": null,
350372
"id": "13e74c8c-fc1a-4d3e-94c8-903359591e5c",
351373
"metadata": {
374+
"editable": true,
375+
"slideshow": {
376+
"slide_type": ""
377+
},
352378
"tags": [
353379
"raises-exception"
354380
]
@@ -1398,7 +1424,13 @@
13981424
"cell_type": "code",
13991425
"execution_count": null,
14001426
"id": "9843aace-0147-408a-ab0d-8643be6a0f0f",
1401-
"metadata": {},
1427+
"metadata": {
1428+
"editable": true,
1429+
"slideshow": {
1430+
"slide_type": ""
1431+
},
1432+
"tags": []
1433+
},
14021434
"outputs": [],
14031435
"source": [
14041436
"import sys\n",
@@ -1422,7 +1454,13 @@
14221454
"cell_type": "code",
14231455
"execution_count": null,
14241456
"id": "26f538bd-910d-442a-aece-54b3cd3c43b5",
1425-
"metadata": {},
1457+
"metadata": {
1458+
"editable": true,
1459+
"slideshow": {
1460+
"slide_type": ""
1461+
},
1462+
"tags": []
1463+
},
14261464
"outputs": [],
14271465
"source": [
14281466
"if \"pyodide\" in sys.modules:\n",
@@ -2302,7 +2340,15 @@
23022340
"cell_type": "code",
23032341
"execution_count": null,
23042342
"id": "ea01912c-c31d-4b67-89cf-b629b20aa8b0",
2305-
"metadata": {},
2343+
"metadata": {
2344+
"editable": true,
2345+
"slideshow": {
2346+
"slide_type": ""
2347+
},
2348+
"tags": [
2349+
"raises-exception"
2350+
]
2351+
},
23062352
"outputs": [],
23072353
"source": [
23082354
"dict3 = dict1 | dict2\n",
@@ -2894,7 +2940,13 @@
28942940
{
28952941
"cell_type": "markdown",
28962942
"id": "b46061df-1039-4abc-b9c2-e048621a482b",
2897-
"metadata": {},
2943+
"metadata": {
2944+
"editable": true,
2945+
"slideshow": {
2946+
"slide_type": ""
2947+
},
2948+
"tags": []
2949+
},
28982950
"source": [
28992951
"\\[<< []() | [Index](./00_index.ipynb) | [Memory Management in Python](./02_memory_management_in_python.ipynb) >>\\]"
29002952
]
@@ -2917,7 +2969,7 @@
29172969
"name": "python",
29182970
"nbconvert_exporter": "python",
29192971
"pygments_lexer": "ipython3",
2920-
"version": "3.11.4"
2972+
"version": "3.8.18"
29212973
}
29222974
},
29232975
"nbformat": 4,

content/02_memory_management_in_python.ipynb

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
{
44
"cell_type": "markdown",
55
"id": "abce30df-1482-44e4-9124-47a1c6d17713",
6-
"metadata": {},
6+
"metadata": {
7+
"editable": true,
8+
"slideshow": {
9+
"slide_type": ""
10+
},
11+
"tags": []
12+
},
713
"source": [
814
"\\[<< [Basic Overview](./01_python_basic_overview.ipynb) | [Index](./00_index.ipynb) | [Function parameters and arguments](./03_function_parameters_and_arguments.ipynb) >>\\]"
915
]
@@ -636,7 +642,13 @@
636642
"cell_type": "code",
637643
"execution_count": null,
638644
"id": "bb5ccdd4-9a9c-4618-983a-d04668367947",
639-
"metadata": {},
645+
"metadata": {
646+
"editable": true,
647+
"slideshow": {
648+
"slide_type": ""
649+
},
650+
"tags": []
651+
},
640652
"outputs": [],
641653
"source": [
642654
"from pympler import asizeof\n",
@@ -648,7 +660,13 @@
648660
"cell_type": "code",
649661
"execution_count": null,
650662
"id": "47d3f8ec-d600-4690-9586-96282fa7538e",
651-
"metadata": {},
663+
"metadata": {
664+
"editable": true,
665+
"slideshow": {
666+
"slide_type": ""
667+
},
668+
"tags": []
669+
},
652670
"outputs": [],
653671
"source": [
654672
"%pip install scalene"
@@ -730,18 +748,10 @@
730748
},
731749
{
732750
"cell_type": "code",
733-
"execution_count": 2,
751+
"execution_count": null,
734752
"id": "b35e7e4d-760d-4339-895c-209cff1fc317",
735753
"metadata": {},
736-
"outputs": [
737-
{
738-
"name": "stdout",
739-
"output_type": "stream",
740-
"text": [
741-
"Overwriting example/memory_profile.py\n"
742-
]
743-
}
744-
],
754+
"outputs": [],
745755
"source": [
746756
"%%writefile example/memory_profile.py\n",
747757
"@profile\n",
@@ -756,29 +766,10 @@
756766
},
757767
{
758768
"cell_type": "code",
759-
"execution_count": 4,
769+
"execution_count": null,
760770
"id": "0e3bc5c2-eb97-47f4-9fa2-060f46d64719",
761771
"metadata": {},
762-
"outputs": [
763-
{
764-
"name": "stdout",
765-
"output_type": "stream",
766-
"text": [
767-
"Filename: example/memory_profile.py\n",
768-
"\n",
769-
"Line # Mem usage Increment Occurrences Line Contents\n",
770-
"=============================================================\n",
771-
" 1 37.766 MiB 37.766 MiB 1 @profile\n",
772-
" 2 def my_func():\n",
773-
" 3 45.410 MiB 7.645 MiB 1 a = [1] * (10 ** 6)\n",
774-
" 4 198.000 MiB 152.590 MiB 1 b = [2] * (2 * 10 ** 7)\n",
775-
" 5 45.414 MiB -152.586 MiB 1 del b\n",
776-
" 6 45.414 MiB 0.000 MiB 1 return a\n",
777-
"\n",
778-
"\n"
779-
]
780-
}
781-
],
772+
"outputs": [],
782773
"source": [
783774
"!python -m memory_profiler example/memory_profile.py"
784775
]
@@ -1817,7 +1808,13 @@
18171808
{
18181809
"cell_type": "markdown",
18191810
"id": "b9b302c9-35a6-4646-9b5a-6bce8d5e9609",
1820-
"metadata": {},
1811+
"metadata": {
1812+
"editable": true,
1813+
"slideshow": {
1814+
"slide_type": ""
1815+
},
1816+
"tags": []
1817+
},
18211818
"source": [
18221819
"\\[<< [Basic Overview](./01_python_basic_overview.ipynb) | [Index](./00_index.ipynb) | [Function parameters and arguments](./03_function_parameters_and_arguments.ipynb) >>\\]"
18231820
]
@@ -1839,7 +1836,7 @@
18391836
"name": "python",
18401837
"nbconvert_exporter": "python",
18411838
"pygments_lexer": "ipython3",
1842-
"version": "3.10.12"
1839+
"version": "3.8.18"
18431840
}
18441841
},
18451842
"nbformat": 4,

content/03_function_parameters_and_arguments.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@
11931193
"name": "python",
11941194
"nbconvert_exporter": "python",
11951195
"pygments_lexer": "ipython3",
1196-
"version": "3.11.4"
1196+
"version": "3.8.18"
11971197
}
11981198
},
11991199
"nbformat": 4,

content/04_namespaces_scopes_and_closures.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
"name": "python",
797797
"nbconvert_exporter": "python",
798798
"pygments_lexer": "ipython3",
799-
"version": "3.11.4"
799+
"version": "3.8.18"
800800
}
801801
},
802802
"nbformat": 4,

content/example/concate_with_join.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
@profile
21
def add_string_with_join(iters):
32
l = []
43
for i in range(iters):
54
l.append("abc")
65
s = "".join(l)
7-
assert len(s) == 3 * iters
8-
9-
10-
add_string_with_join(50000)
6+
assert len(s) == 3*iters
7+
8+
add_string_with_join(500000)

content/example/concate_with_plus.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
@profile
21
def add_string_with_plus(iters):
32
s = ""
43
for i in range(iters):
54
s += "abc"
6-
assert len(s) == 3 * iters
7-
8-
9-
add_string_with_plus(50000)
5+
assert len(s) == 3*iters
6+
7+
add_string_with_plus(500000)

content/example/memory_profile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@profile
22
def my_func():
3-
a = [1] * (10**6)
4-
b = [2] * (2 * 10**7)
3+
a = [1] * (10 ** 6)
4+
b = [2] * (2 * 10 ** 7)
55
del b
66
return a
77

8-
98
my_func()

content/example/scope.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
val8 = "global scope"
23

34
breakpoint()

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ tabulate
5353

5454
# Black
5555
black[jupyter]
56+
57+
# Perf tools
58+
pympler
59+
scalene
60+
memory-profiler

0 commit comments

Comments
 (0)