파이썬

파일의 각 라인을 리스트로 변환

잡T 2020. 1. 10. 05:08

with open(“filename.txt”, ‘r’) as f:
    content = f.readlines()
 
# strip() 함수를 이용해 공백 및 줄바꿈 문자를 제거한다.
content = [x.strip() for x in content] 
print(content)