반응형
따라서 Ruby에서 다음을 수행 할 수 있습니다.
testsite_array = Array.new
y=0
File.open('topsites.txt').each do |line|
testsite_array[y] = line
y=y+1
end
파이썬에서 어떻게할까요?
해결 방법
testsite_array = []
with open('topsites.txt') as my_file:
for line in my_file:
testsite_array.append(line)
이는 Python을 사용하여 파일을 직접 반복 할 수 있기 때문에 가능합니다.
with open('topsites.txt') as my_file:
testsite_array = my_file.readlines()
참조 페이지 https://stackoverflow.com/questions/16222956
반응형
'파이썬' 카테고리의 다른 글
파이썬 TypeError : <lambda> ()는 인수를받지 않습니다 (1 개 제공됨). (0) | 2021.01.19 |
---|---|
파이썬 Python으로 월요일 날짜 찾기 (0) | 2021.01.19 |
파이썬 Gunicorn을 포트 80에서 실행하기 (0) | 2021.01.19 |
파이썬 dict에서 값 목록을 어떻게 얻을 수 있습니까? (0) | 2021.01.19 |
파이썬 xlrd 셀의 원래 값 (0) | 2021.01.18 |
댓글