에서 값을 추가 할 때 배열의 길이가 폭발하면 CSV 파일을 여는 코드가 작성됩니다. 그 값은 다음과 같이 저장됩니다아래 CSV
03/05/2017 09:40:19,21.2,35.0
03/05/2017 09:40:27,21.2,35.0
03/05/2017 09:40:38,21.1,35.0
03/05/2017 09:40:48,21.1,35.0
이 내가 완전히 배열이 너무 커서 점점 것은 부정 사실을 제외한 작동 프로그램을 플로팅 실시간으로 사용하는 코드 스 니펫입니다. 프로그램이 실행 중이고 배열의 길이가 매우 길 때 일반적으로 새 값이 CSV에 추가됩니다. 이처럼 폭발하는 배열을 가지지 않는 방법이 있습니까? 그냥 프로그램을 실행하면 해당 값으로 CSV를 만들어야하며 내 문제가 나타납니다. 어떤 도움에 감사드립니다
[[21.1]]
[[21.1, 21.1]]
[[21.1, 21.1, 21.1]]
[[21.1, 21.1, 21.1, 21.1]]
[[21.1, 21.1, 21.1, 21.1, 21.1]]
:
from datetime import datetime
import time
y = [] #temperature
t = [] #time object
h = [] #humidity
def readfile():
readFile = open('document.csv', 'r')
sepFile = readFile.read().split('\n')
readFile.close()
for idx, plotPair in enumerate(sepFile):
if plotPair in '. ':
# skip. or space
continue
if idx > 1: # to skip the first line
xAndY = plotPair.split(',')
time_string = xAndY[0]
time_string1 = datetime.strptime(time_string, '%d/%m/%Y %H:%M:%S')
t.append(time_string1)
y.append(float(xAndY[1]))
h.append(float(xAndY[2]))
print([y])
while True:
readfile()
time.sleep(2)
이
내가 얻을 출력됩니다.
maxs.length와 함께 collections.deque를 사용하여 데이터를 추가 할 수 있습니다. – Hackaholic
잠시만 기다려주세요. readFile 메서드 내에서 목록을 선언하거나 추가 대신 insert를 사용할 수 있습니다. – papey