Skip to content

Commit 714bba5

Browse files
committed
Args Kwargs
1 parent d52fadd commit 714bba5

File tree

3 files changed

+254
-2
lines changed

3 files changed

+254
-2
lines changed

Data_Validation_TDD_and_APIS/main.ipynb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 3,
12+
"execution_count": 2,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16-
"from pydantic import BaseModel, validator, ValidationError"
16+
"from pydantic import BaseModel, validator, ValidationError\n",
17+
"import logging as logger\n",
18+
"\n"
1719
]
1820
},
1921
{
@@ -23,6 +25,15 @@
2325
"# 2 - Class Building "
2426
]
2527
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 3,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"logger.info('it works and is fully configured')"
35+
]
36+
},
2637
{
2738
"cell_type": "code",
2839
"execution_count": 4,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import sys\n"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"1 2 [3, 4]\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"x, y , *resto = 1 ,2 ,3 ,4\n",
27+
"print(x, y, resto)"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 15,
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"var dados 15\n",
40+
"total de kbytes em memoria 0.75KB\n"
41+
]
42+
}
43+
],
44+
"source": [
45+
"def soma(*args):\n",
46+
" total = 0\n",
47+
" for numero in args:\n",
48+
" total += numero\n",
49+
" return total\n",
50+
"dados = soma(1,2,3,4,5)\n",
51+
"print(f\"var dados {dados}\")\n",
52+
"\n",
53+
"#É necessário realizar o desempacotamento após empacotar os argumentos em *args\n",
54+
"\n",
55+
"numeros = 1,2,3,4,5,6,7,8,9,10\n",
56+
"lista_de_numeros = [1,2,3,4,5]\n",
57+
"\n",
58+
"#enviando valores * para serem desempacotados\n",
59+
"soma(*numeros)\n",
60+
"#desempacotando valores de uma lista\n",
61+
"soma(*lista_de_numeros)\n",
62+
"#calcular valor de kbytes das variáveis em memoria\n",
63+
"variaveis = locals().copy()\n",
64+
"total = 0\n",
65+
"for nome, valor in variaveis.items():\n",
66+
" if nome != 'total':\n",
67+
" total = sys.getsizeof(valor)\n",
68+
"print(f\"total de kbytes em memoria {total/1024}KB\")"
69+
]
70+
}
71+
],
72+
"metadata": {
73+
"kernelspec": {
74+
"display_name": "base",
75+
"language": "python",
76+
"name": "python3"
77+
},
78+
"language_info": {
79+
"codemirror_mode": {
80+
"name": "ipython",
81+
"version": 3
82+
},
83+
"file_extension": ".py",
84+
"mimetype": "text/x-python",
85+
"name": "python",
86+
"nbconvert_exporter": "python",
87+
"pygments_lexer": "ipython3",
88+
"version": "3.11.4"
89+
}
90+
},
91+
"nbformat": 4,
92+
"nbformat_minor": 2
93+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### 1 - Imports"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import json\n",
17+
"import pandas as pd\n"
18+
]
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": [
24+
"### 2 - variables declarations"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"dados_dict = {\n",
34+
" 'nome': 'Guilherme',\n",
35+
" 'sobrenome': 'Borges',\n",
36+
" 'idade': 20\n",
37+
"}\n",
38+
"\n",
39+
"x, y , *resto = 1 ,2 ,3 ,4\n",
40+
"numeros = 1,2,3,4,5,6,7,8,9,10\n",
41+
"lista_de_numeros = [1,2,3,4,5]"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"dados_dict['nome']"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"def soma(*args):\n",
60+
" total = 0\n",
61+
" for numero in args:\n",
62+
" total += numero\n",
63+
" return total\n",
64+
"dados = soma(1,2,3,4,5)\n",
65+
"print(f\"var dados {dados}\")"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"json_data = json.dumps(dados_dict)\n",
75+
"print(json_data)"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"df = pd.DataFrame(dados_dict, index=[0]);df"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"dados_dict"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"#KWARGS\n",
103+
"def dados_pessoais(**kwargs):\n",
104+
" print(kwargs)\n",
105+
"\n",
106+
" #transformar dict em df\n",
107+
" df = pd.DataFrame(kwargs)\n",
108+
" return df\n",
109+
" \n",
110+
"\n",
111+
"#transformar df em dict\n",
112+
"df_dict = df.to_dict()\n",
113+
"dados_pessoais(**df.to_dict())\n",
114+
"\n"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"dados_pessoais(**dados_dict)\n"
124+
]
125+
}
126+
],
127+
"metadata": {
128+
"kernelspec": {
129+
"display_name": "base",
130+
"language": "python",
131+
"name": "python3"
132+
},
133+
"language_info": {
134+
"codemirror_mode": {
135+
"name": "ipython",
136+
"version": 3
137+
},
138+
"file_extension": ".py",
139+
"mimetype": "text/x-python",
140+
"name": "python",
141+
"nbconvert_exporter": "python",
142+
"pygments_lexer": "ipython3",
143+
"version": "3.11.4"
144+
}
145+
},
146+
"nbformat": 4,
147+
"nbformat_minor": 2
148+
}

0 commit comments

Comments
 (0)