본문 바로가기
공부,일/파이썬

txt 편집 하는 프로그램

by fromnothing1 2023. 2. 5.

# with as 위의 함수가 끝나면 자동으로 file을 close 해준다. ( 개발자가 실수로 close 하지 않도록 하는 구문)
# 한꺼 번에 가져오기
# with open("example.txt", "r") as f:
#     example = f.read()

# 1줄 씩 가져오기

name_list = []
cnt = 0;
with open("example.txt", "r") as f:
   for line in f:
      name_list.append([line.strip(),cnt]) # strip 줄바꿈 문자 제거
      cnt = cnt + 1
      
for item in name_list:
   print(item)

'공부,일 > 파이썬' 카테고리의 다른 글

판다스 사용해보기(엑셀 사용)  (0) 2023.02.05
파이썬 배포하기  (0) 2022.11.14
colab 환경설정  (0) 2021.11.29
파이썬 엑셀 사용  (0) 2021.11.23
원격으로 jupyter notebook 사용 colab  (0) 2021.11.17

댓글