Skip to content

Commit da72568

Browse files
committed
init
0 parents  commit da72568

File tree

162 files changed

+31432
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+31432
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

Contex_manager_samples/__init__.py

Whitespace-only changes.

Contex_manager_samples/sample_1_.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Yolo:
2+
def __init__(self):
3+
print('init')
4+
5+
def __enter__(self):
6+
print('entering')
7+
return self
8+
9+
def __exit__(self, exc_type, exc_val, exc_tb):
10+
if exc_type:
11+
print('exception')
12+
else:
13+
print('exiting')
14+
return True
15+
16+
17+
with Yolo() as y:
18+
print('normal code')
19+
raise Exception('oops')
20+
21+
print('Next code')

Contex_manager_samples/sample_2_.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Yolo:
2+
def __init__(self):
3+
print('init')
4+
5+
def __enter__(self):
6+
print('entering')
7+
return self
8+
9+
def __exit__(self, exc_type, exc_val, exc_tb):
10+
if exc_type:
11+
print('exception')
12+
else:
13+
print('exiting')
14+
return True
15+
16+
17+
# with Yolo() as y:
18+
# print('normal code')
19+
# raise Exception('oops')
20+
21+
# print('Next code')
22+
23+
# result = Yolo()
24+
25+
# with open('test.txt', 'w') as f:
26+
# f.write('test')
27+
28+
29+
try:
30+
file = open('test.txt', 'r')
31+
except FileNotFoundError as err:
32+
print("File not found")
33+
except PermissionError as err:
34+
print("Permission denied")
35+
else:
36+
print(file.read())
37+
file.close()

Contex_manager_samples/sample_3_.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from contextlib import contextmanager
2+
3+
4+
@contextmanager
5+
def yolo():
6+
# __enter__
7+
print("entering")
8+
try:
9+
yield "y"
10+
except Exception:
11+
print("error exiting")
12+
finally:
13+
print("exiting")
14+
15+
16+
with yolo() as y:
17+
print(y)
18+
raise ValueError()

Contex_manager_samples/sample_4_.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from contextlib import contextmanager
2+
3+
4+
@contextmanager
5+
def propagator(name, propagate=True):
6+
try:
7+
yield
8+
print(f"{name}: done")
9+
except Exception:
10+
print(f"{name}: received exception")
11+
if propagate:
12+
raise
13+
14+
15+
with propagator("outer", True), propagator("inner", True):
16+
raise Exception("yolo")

Functional_Programming/__init__.py

Whitespace-only changes.

Functional_Programming/app.ipynb

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {},
5+
"cell_type": "markdown",
6+
"source": [
7+
"### Interning \n",
8+
"\n",
9+
"- special feature in python to store value for references due to reusing values\n",
10+
"- only for immutable types and short strings without spaces\n",
11+
"- for number in range from -5 to 256"
12+
],
13+
"id": "c5aceec3ddf7ec8f"
14+
},
15+
{
16+
"metadata": {
17+
"ExecuteTime": {
18+
"end_time": "2024-11-18T15:01:13.855733Z",
19+
"start_time": "2024-11-18T15:01:13.848940Z"
20+
}
21+
},
22+
"cell_type": "code",
23+
"source": [
24+
"x = [[1, 2], [3, 4]]\n",
25+
"\n",
26+
"y = x\n",
27+
"print(x == y, x is y )"
28+
],
29+
"id": "96d804d0b04a667",
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"True True\n"
36+
]
37+
}
38+
],
39+
"execution_count": 2
40+
},
41+
{
42+
"metadata": {
43+
"ExecuteTime": {
44+
"end_time": "2024-11-18T15:01:46.205182Z",
45+
"start_time": "2024-11-18T15:01:46.199591Z"
46+
}
47+
},
48+
"cell_type": "code",
49+
"source": [
50+
"x[0][0] = 42\n",
51+
"print(x, y)"
52+
],
53+
"id": "7c65c216a371c326",
54+
"outputs": [
55+
{
56+
"name": "stdout",
57+
"output_type": "stream",
58+
"text": [
59+
"[[42, 2], [3, 4]] [[42, 2], [3, 4]]\n"
60+
]
61+
}
62+
],
63+
"execution_count": 3
64+
},
65+
{
66+
"metadata": {
67+
"ExecuteTime": {
68+
"end_time": "2024-11-18T15:25:56.883231Z",
69+
"start_time": "2024-11-18T15:25:56.866838Z"
70+
}
71+
},
72+
"cell_type": "code",
73+
"source": [
74+
"z = x.copy()\n",
75+
"print(z == x, z is x)\n",
76+
"z[0][0] = 1024\n",
77+
"print(x, y, z)\n",
78+
"z[0] = [42, 2]\n",
79+
"print(x, y, z)\n",
80+
"z[-1] = x[0]\n",
81+
"x[0][0] = 666\n",
82+
"print(x, y, z)"
83+
],
84+
"id": "f19b914781970f9d",
85+
"outputs": [
86+
{
87+
"name": "stdout",
88+
"output_type": "stream",
89+
"text": [
90+
"True False\n",
91+
"[[1024, 2], [3, 4]] [[1024, 2], [3, 4]] [[1024, 2], [3, 4]]\n",
92+
"[[1024, 2], [3, 4]] [[1024, 2], [3, 4]] [[42, 2], [3, 4]]\n",
93+
"[[666, 2], [3, 4]] [[666, 2], [3, 4]] [[42, 2], [666, 2]]\n"
94+
]
95+
}
96+
],
97+
"execution_count": 8
98+
},
99+
{
100+
"metadata": {},
101+
"cell_type": "markdown",
102+
"source": [
103+
"# functions parametrers order :\n",
104+
"- 1/positional\n",
105+
"- 2/*args -> tuple\n",
106+
"- 3/named\n",
107+
"- 4/optional / default\n",
108+
"- 5/**kwargs -> dictionary"
109+
],
110+
"id": "ffedd48e3587e947"
111+
},
112+
{
113+
"metadata": {},
114+
"cell_type": "code",
115+
"outputs": [],
116+
"execution_count": null,
117+
"source": "",
118+
"id": "beb32861c2e33d67"
119+
}
120+
],
121+
"metadata": {
122+
"kernelspec": {
123+
"display_name": "Python 3",
124+
"language": "python",
125+
"name": "python3"
126+
},
127+
"language_info": {
128+
"codemirror_mode": {
129+
"name": "ipython",
130+
"version": 2
131+
},
132+
"file_extension": ".py",
133+
"mimetype": "text/x-python",
134+
"name": "python",
135+
"nbconvert_exporter": "python",
136+
"pygments_lexer": "ipython2",
137+
"version": "2.7.6"
138+
}
139+
},
140+
"nbformat": 4,
141+
"nbformat_minor": 5
142+
}

Functional_Programming/bye.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Document</title>
9+
<style>
10+
@keyframes flicker {
11+
0% {
12+
text-shadow: 0 0 5px rgba(255,69,0,0.8), 0 0 10px rgba(255,140,0,0.8), 0 0 15px rgba(255,69,0,0.6), 0 0 20px rgba(255,0,0,0.8);
13+
}
14+
50% {
15+
text-shadow: 0 0 15px rgba(255,69,0,1), 0 0 25px rgba(255,140,0,1), 0 0 35px rgba(255,69,0,1), 0 0 45px rgba(255,0,0,1);
16+
}
17+
100% {
18+
text-shadow: 0 0 5px rgba(255,69,0,0.8), 0 0 10px rgba(255,140,0,0.8), 0 0 15px rgba(255,69,0,0.6), 0 0 20px rgba(255,0,0,0.8);
19+
}
20+
}
21+
@keyframes wave {
22+
0% {
23+
transform: translateY(0);
24+
}
25+
25% {
26+
transform: translateY(-5px);
27+
}
28+
50% {
29+
transform: translateY(0);
30+
}
31+
75% {
32+
transform: translateY(5px);
33+
}
34+
100% {
35+
transform: translateY(0);
36+
}
37+
}
38+
39+
@keyframes shimmer {
40+
0% {
41+
background-position: 0% 50%;
42+
}
43+
100% {
44+
background-position: 100% 50%;
45+
}
46+
}
47+
48+
</style>
49+
</head>
50+
<body>
51+
<h2 style="color: transparent; background: linear-gradient(to right, #00bfff, #1e90ff, #4682b4, #00bfff); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 2rem; animation: wave 4s infinite linear, shimmer 2s infinite alternate; text-shadow: 0 2px 5px rgba(0, 191, 255, 0.5), 0 -2px 10px rgba(30, 144, 255, 0.7); font-family: 'Arial', sans-serif; ">Bye <C style="">Lech<C/></h2>
52+
</body>
53+
</html>

Functional_Programming/closure_.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def outer_fn():
2+
x = 42
3+
az = 1024
4+
5+
# def z():
6+
# return 1024
7+
8+
def inner_fn():
9+
nonlocal x
10+
# return f'Answer for all questions : {x}'
11+
y = az * 2 + x
12+
x += 1
13+
# y = x * 2 + z()
14+
return y
15+
16+
return inner_fn
17+
18+
19+
result_fn = outer_fn()
20+
# dunder -> double underscores
21+
print(result_fn.__closure__[0].cell_contents)
22+
print(result_fn.__closure__[1].cell_contents)
23+
24+
result = result_fn()
25+
print(result_fn.__closure__[0].cell_contents)
26+
print(result_fn.__closure__[1].cell_contents)
27+
print(result)
28+
29+
30+
31+

0 commit comments

Comments
 (0)