본문 바로가기
프로그램/Python 1000제

Python 317제] 두근두근 파이썬(개정판) CHAPTER 11 도전문제(2) p346

by 건티 2024. 10. 7.
728x90

출처 : 반크_독도2023

 

참고풀이]

import os
arr = os.listdir()
for f in arr:
    infile = open(f, "r", encoding="utf-8")
    L=[]
    for line in infile:
        e = line.rstrip() #오른쪽 줄바꿈을 삭제한다.
        L.append(line)
    infile.close()
    outfile= open(f, "w", encoding="utf-8")
    L.insert(0,"#define _CRT_SECURE_NO_WARNINGS\n")
    for line in L:
        outfile.write(line)
    outfile.close()
    

 

참고풀이 결과]

자료삽입전 내용)

abc.txt]

1
2
3
4
5
6
7
8
9
10
11
12
13

 

file.py]

import os
arr = os.listdir()
for f in arr:
    infile = open(f, "r", encoding="utf-8")
    L=[]
    for line in infile:
        e = line.rstrip() #오른쪽 줄바꿈을 삭제한다.
        L.append(line)
    infile.close()
    outfile= open(f, "w", encoding="utf-8")
    L.insert(0,"#define _CRT_SECURE_NO_WARNINGS\n")
    for line in L:
        outfile.write(line)
    outfile.close()
    

summary.txt]

All's well that ends well.
Bad news travels fast.
Well begun is half done.
Brrds of a feather flock together.
Thank you very mach.
The joy or doeint Python should be in seeing short
Python is executable pseudocode.

 

자료삽입후 내용)

abc.txt]

#define _CRT_SECURE_NO_WARNINGS
1
2
3
4
5
6
7
8
9
10
11
12
13

 

file.py]

#define _CRT_SECURE_NO_WARNINGS
import os
arr = os.listdir()
for f in arr:
    infile = open(f, "r", encoding="utf-8")
    L=[]
    for line in infile:
        e = line.rstrip() #오른쪽 줄바꿈을 삭제한다.
        L.append(line)
    infile.close()
    outfile= open(f, "w", encoding="utf-8")
    L.insert(0,"#define _CRT_SECURE_NO_WARNINGS\n")
    for line in L:
        outfile.write(line)
    outfile.close()
    

summary.txt]

#define _CRT_SECURE_NO_WARNINGS
All's well that ends well.
Bad news travels fast.
Well begun is half done.
Brrds of a feather flock together.
Thank you very mach.
The joy or doeint Python should be in seeing short
Python is executable pseudocode.

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 겨울

 

반응형

댓글