https://securityspecialist.tistory.com/90

1. 파일 열기 모드 종류

cnt = 1
page = 3
for i in range(10):
    cnt +=1
    print(f'/opt/project/DATA-WORK/datateam_for_beginner/k3_result_{cnt:02d}_p%04d.json' % (page))

https://stackoverflow.com/questions/6648493/how-to-open-a-file-for-both-reading-and-writing

https://stackoverflow.com/questions/6648493/how-to-open-a-file-for-both-reading-and-writing

2. readline VS readlines

3. with open 과 띄어쓰기

print('label path', label_path)
    for i in label_path:
        # print('temp')
        print(i)

label path ['/nas/Dataset/LEA18A/scenes/planetscope/PlanetScope/1.\\\\ Beijing\\\\ Int\\\\ Airport/20190117_023644_0f28/20190117_023644_0f28_3B_AnalyticMS.label']
/nas/Dataset/LEA18A/scenes/planetscope/PlanetScope/1.\\ Beijing\\ Int\\ Airport/20190117_023644_0f28/20190117_023644_0f28_3B_AnalyticMS.label
def spacing_change(list_path):
    path = [ label.replace(' ','\\ ') for label in list_path ]
    return path

1. with open() 은 \\ 가 없고 띄어쓰기만 있어야 열림

2. shell에서는 \\ 가 별도로 필요

3. (미해결)rename의 경우는 ?

4. 특정 파일 읽어서 내용 변경하기

with open(test_path, 'r') as f:
    while f:
        
        line = f.readline()
        
        line = line.split('.')[0]
        print(line)
        
        with open('/nas/workspace/kbae/tool/file_list/test.txt', 'a+') as ff:
            
	        ff.write(line)
        
        if line == "":
            break

5. 특정 파일 읽어서 한글만 남기기

import re

with open('/nas/workspace/kbae/tool/test/usernoun_korean.txt', 'a+') as f:
    with open('/nas/workspace/kbae/tool/test/usernoun.txt', 'r', encoding='euc-kr') as f1:
        while f1:
            
            line = f1.readline()
            
            if line == '':
                break
            
            try:
                f.write(re.compile('[가-힣]+').findall(line)[0]+'\\n')
            except:
                print(line)
                pass