-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error prevention, comments and style
- Loading branch information
1 parent
8a23013
commit f7cf52e
Showing
4 changed files
with
33 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
# PUNTO 3 | ||
import os | ||
|
||
with open('w_names.txt', 'r') as file: | ||
w_lines = file.readlines() | ||
first_path = 'w_names.txt' | ||
second_path = 'm_names.txt' | ||
|
||
with open('m_names.txt', 'r') as file: | ||
m_lines = file.readlines() | ||
if os.path.exists(first_path): # reviso si el primer archivo existe antes de leerlo | ||
with open(first_path, 'r') as file: # abro el primer archivo en modo lectura | ||
w_lines = file.readlines() # leo y guardo una lista con las lineas del primer archivo | ||
else: | ||
print("El archivo " + first_path + " no existe") | ||
|
||
with open('m_names.txt', 'w') as file: | ||
for i in range(len(m_lines)): | ||
file.write(m_lines[i].strip() + " " + w_lines[i]) | ||
if os.path.exists(second_path): # reviso si el segundo archivo existe antes de leerlo | ||
with open(second_path, 'r') as file: # abro el segundo archivo en modo lectura | ||
m_lines = file.readlines() # leo y guardo una lista con las lineas del segundo archivo | ||
with open(second_path, 'w') as file: # abro el segundo archivo en modo escritura | ||
for i in range(len(m_lines)): # Itero a partir de la cantidad de líneas del segundo archivo | ||
file.write(m_lines[i].strip() + " " + w_lines[i]) # escribo cada linea de cada archivo concatenandolas (sacandoles el enter y el espacio) | ||
else: | ||
print("El archivo " + second_path + " no existe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
# PUNTO 2 | ||
import os | ||
|
||
with open('w_names.txt', 'r') as file: | ||
content = file.read() | ||
path = 'w_names.txt' | ||
|
||
with open('empty.txt', 'w') as file: | ||
file.write(content) | ||
if os.path.exists(path): # reviso si el archivo existe antes de leerlo | ||
with open(path, 'r') as file: # abro el archivo en modo lectura | ||
content = file.read() # leo y guardo el contenido del archivo | ||
with open('empty.txt', 'w') as file: # creo un archivo vacío y lo abro en modo escritura | ||
file.write(content) # escribo en el nuevo archivo el contenido del archivo anterior | ||
else: | ||
print("El archivo " + path + " no existe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# PUNTO 1 | ||
import os | ||
|
||
with open('w_names.txt', 'r') as file: | ||
lines = file.readlines() | ||
path = 'w_names.txt' | ||
|
||
print("Hay " + str(len(lines)) + " lineas en el archivos") | ||
if os.path.exists(path): # reviso si el archivo existe antes de leerlo | ||
with open(path, 'r') as file: # abro el archivo en modo lectura | ||
lines = file.readlines() # leo y guardo una lista con las lineas del archivo | ||
print("Hay " + str(len(lines)) + " lineas en el archivos") | ||
else: | ||
print("El archivo " + path + " no existe") |