νλ‘κ·Έλλ° μΈκ³λ₯Ό νꡬν©μλ€.
νμ΄μ¬μ νμ©νμ¬ txt ν
μ€νΈ νμΌμ μΆλ ₯ν μ μμ΅λλ€.
<μΆλ ₯ λ°©λ²>
1. μ€ννλ νλ‘κ·Έλ¨μ΄ μλ ν΄λμ ν μ€νΈ νμΌμ λ§λλλ€.
μ λ 04_example.txt νμΌκ³Ό 05_example.txt νμΌλ‘ μ΄λ¦μ μ€μ νμμ΅λλ€.
* μ°Έκ³
μμ κ³ λμ κ°μ ν μ€νΈλ μμ€ν€ μνΈλΌκ³ λΆλ¦ λλ€.
μμ€ν€μνΈλ μλμ κ°μ μ¬μ΄νΈμμ λ€μ΄λ‘λλ°κ±°λ λ³νν μ μμ΅λλ€.
https://snskeyboard.com/asciiart/
https://snskeyboard.com/asciitext/
https://wepplication.github.io/tools/asciiArtGen/
2. μ½λ μμ±
νμ΄μ¬μ μ½λλ₯Ό μμ±ν©λλ€.
### read_lines ν¨μ μμ±
def read_lines(file_path) :
### νμΌμ²λ¦¬ μ μ΄ν°λ μ΄ν°μ λ€λ₯΄κ², withλ¬Έμ μ¬μ©ν΄λ λ©λλ€.
with open(file_path, "r", encoding="utf-8") as file :
for line in file :
yield line.strip()
### μ λλ μ΄ν° ν¨μ μμ±νκΈ°
gen = read_lines("./04_example.txt")
for line in gen :
print(line)
<μ€ν νλ©΄>
<μμ± μ½λ>
### read_lines ν¨μ μμ±
def read_lines(file_path) :
### νμΌμ²λ¦¬ μ μ΄ν°λ μ΄ν°μ λ€λ₯΄κ², withλ¬Έμ μ¬μ©ν΄λ λ©λλ€.
with open(file_path, "r", encoding="utf-8") as file :
for line in file :
yield line.strip()
### μ λλ μ΄ν° ν¨μ μμ±νκΈ°
gen = read_lines("./05_example.txt")
for line in gen :
print(line)
<μ€ν νλ©΄>
μμ κ°μ λ°©μμΌλ‘ ν μ€νΈ .txt νμΌμ μ λ ₯ν μμ€ν€ μνΈλ₯Ό νμ΄μ¬μΌλ‘ μΆλ ₯ν μ μμ΅λλ€.