줄 단위로 파일을 읽고 계산을 한 후 결과를 다른 파일에 저장하는 간단한 함수를 작성했습니다. 그러나 출력 할 때 count
대신 0, 1, 2, 3; 6.21263888889e-05, 0.000141933611111 등이됩니다. 이유가 무엇인지 궁금합니다. 출력의파이썬에서 증분 정수
def CumulativePerSecond(input_file):
# Record cumulative battery per second
freq = 1000 # number of samples per second
output_file = os.path.splitext(input_file)[0] + "_1s" + ".txt"
output = open(output_file, 'a+')
count = 0
for line2 in fileinput.input(input_file):
count = count + 1
print count
if count == freq:
output.write(str(line2))
count = 0
output.close()
부품 :
이1.87317876361
1.87321708889
1.87325520083
1.87329356889
1.87333199389
1.87337076056
1.87340823167
1.87344365278
1.87347473167
1.87351439528
1.87354390806
1.87362505778
typecasting을 int로 시도 했습니까 (즉,'count = int (count + 1)')? –
또한 생성하는 시리즈에 더 많은 숫자를 게시 할 수 있으며 오류를 생성하는 것에 대한 정보를 조금 더 제공 할 수 있습니다. –
또한 입력에서 1000 번째 데이터 포인트마다 파일을 출력하는 것을 주요 목표로합니다. 그것은 훨씬 더 간단하게 쓰여질 수 있으며 카운트가 전혀 필요하지 않을 수도 있습니다. –