본문 바로가기
Python

Python으로 파일 치환 및 업로드

by Rainbound-IT 2021. 5. 18.
반응형

치환

1
2
3
4
5
6
7
8
9
10
11
12
13
def replaceInFile(file_path, oldstr, newstr):
    fr = open(file_path, 'r')
    lines = fr.readlines()
    fr.close()
 
    fw = open(file_path, 'w')
    for line in lines:
        fw.write(line.replace(oldstr, newstr))
    fw.close()
 
 
# 호출: 123.txt 파일에서 comma(,) 없애기
replaceInFile("C:\\docker\\example\\123.txt""nbc""abc")
cs

 

 

업로드

requests 모듈을 설치를 따로 해줘야 하고

requests.post ( 주소 , 보낼형식)이런식이라고 생각하면된다.

파일복사

1
2
3
4
5
6
import shutil #기본적으로 제공되는듯
 
before = r'C:\\docker\\example\\123.txt'
after = r'C:\\docker\\example\\1234.txt'
 
shutil.copy(before, after)
cs

 

 

반응형

댓글