Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf5cdb9

Browse files
committed
Intermediate: Día 5
1 parent ca04fc1 commit cf5cdb9

File tree

6 files changed

+113
-6
lines changed

6 files changed

+113
-6
lines changed

Intermediate/02_challenges.py

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
- Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz".
1313
"""
1414

15-
from itertools import count
16-
from tokenize import String
17-
18-
1915
def fizzbuzz():
2016
for index in range(1, 101):
2117
if index % 3 == 0 and index % 5 == 0:

Intermediate/06_file_handling.py

+50
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,53 @@
2727

2828
#os.remove("Intermediate/my_file.txt")
2929

30+
# .json file
31+
32+
import json
33+
34+
json_file = open("Intermediate/my_file.json", "w+")
35+
36+
json_test = {
37+
"name":"Brais",
38+
"surname":"Moure",
39+
"age":35,
40+
"languages":["Python", "Swift", "Kotlin"],
41+
"website":"https://moure.dev"}
42+
43+
json.dump(json_test, json_file, indent = 2)
44+
45+
json_file.close()
46+
47+
with open("Intermediate/my_file.json") as my_other_file:
48+
for line in my_other_file.readlines():
49+
print(line)
50+
51+
json_dict = json.load(open("Intermediate/my_file.json"))
52+
print(json_dict)
53+
print(type(json_dict))
54+
print(json_dict["name"])
55+
56+
# .csv file
57+
58+
import csv
59+
60+
csv_file = open("Intermediate/my_file.csv", "w+")
61+
62+
csv_writer = csv.writer(csv_file)
63+
csv_writer.writerow(["name", "surname", "age", "language", "website"])
64+
csv_writer.writerow(["Brais", "Moure", 35, "Python", "https://moure.dev"])
65+
csv_writer.writerow(["Roswell", "", 2, "COBOL", ""])
66+
67+
csv_file.close()
68+
69+
with open("Intermediate/my_file.csv") as my_other_file:
70+
for line in my_other_file.readlines():
71+
print(line)
72+
73+
# .xlsx file
74+
# import xlrd # Debe instalarse el módulo
75+
76+
# .xml file
77+
78+
import xml
79+
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Clase en vídeo (03/11/22): https://www.twitch.tv/videos/1642512950
2+
3+
### Regular Expressions ###
4+
5+
import re
6+
7+
# match
8+
9+
my_string = "Esta es la lección número 7: Lección llamada Expresiones Regulares"
10+
my_other_string = "Esta no es la lección número 6: Manejo de ficheros"
11+
12+
match = re.match("Esta es la lección", my_string, re.I)
13+
print(match)
14+
start, end = match.span()
15+
print(my_string[start:end])
16+
17+
match = re.match("Esta no es la lección", my_other_string)
18+
#if not(match == None): # Otra forma de comprobar el None
19+
#if match != None: # Otra forma de comprobar el None
20+
if match is not None:
21+
print(match)
22+
start, end = match.span()
23+
print(my_other_string[start:end])
24+
25+
print(re.match("Expresiones Regulares", my_string))
26+
27+
# search
28+
29+
search = re.search("lección", my_string, re.I)
30+
print(search)
31+
start, end = search.span()
32+
print(my_string[start:end])
33+
34+
# findall
35+
36+
findall = re.findall("lección", my_string, re.I)
37+
print(findall)
38+
39+
# split
40+
41+
print(re.split(":", my_string))
42+
43+
# sub
44+
45+
print(re.sub("[l|L]ección", "LECCIÓN", my_string))
46+
print(re.sub("Expresiones Regulares", "RegEx", my_string))

Intermediate/my_file.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,surname,age,language,website
2+
Brais,Moure,35,Python,https://moure.dev
3+
Roswell,,2,COBOL,

Intermediate/my_file.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Brais",
3+
"surname": "Moure",
4+
"age": 35,
5+
"languages": [
6+
"Python",
7+
"Swift",
8+
"Kotlin"
9+
],
10+
"website": "https://moure.dev"
11+
}

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
##### Si consideras útil esta actividad, apóyala haciendo "★ Star" en el repositorio. ¡Gracias!
99

1010
> ---
11-
> **🔴 PRÓXIMA CLASE: Jueves 3 de Noviembre a las 20:00 (hora España)**
11+
> **🔴 PRÓXIMA CLASE: Miércoles 9 de Noviembre a las 20:00 (hora España)**
1212
>
1313
> Mientras, aprovecha para practicar unos [retos de programación](https://retosdeprogramacion.com/semanales2022) y así ir mejorando poco a poco.
1414
>
15-
> En [Discord](https://discord.gg/U3KjjfUfUJ?event=1034770962127790142) tienes creado un [evento](https://discord.gg/U3KjjfUfUJ?event=1034770962127790142) para que consultes la hora de tu país y añadas un recordatorio.
15+
> En [Discord](https://discord.gg/RemDcUaW?event=1038058766370877530) tienes creado un [evento](https://discord.gg/RemDcUaW?event=1038058766370877530) para que consultes la hora de tu país y añadas un recordatorio.
1616
>
1717
> *Finalizada la clase, se actualizará el repositorio con los nuevos recursos*
1818
>
@@ -57,6 +57,7 @@ Curso en el que continuamos aprendiendo Python desde sus bases, siguiendo la rut
5757
* [Clase 13/10/22 - Resolución retos de programación](https://www.twitch.tv/videos/1623225956)
5858
* [Clase 19/10/22 - Lambdas y Funciones de orden superior](https://www.twitch.tv/videos/1628654998)
5959
* [Clase 25/10/22 - Tipos de error y manejo de ficheros .txt](https://www.twitch.tv/videos/1634818287)
60+
* [Clase 03/11/22 - Manejo de ficheros .json/.cvs y Expresiones Regulares](https://www.twitch.tv/videos/1642512950)
6061

6162
## Información importante y preguntas frecuentes
6263

0 commit comments

Comments
 (0)