3
현재 파이썬에서 CSV 파일에 쓰려고하는데, 60 회 반복마다 'CurrentInv'만 인쇄하고 싶습니다. 예를 들어'for'루프를 사용하여 파이썬 CSV 파일에 쓰기
outfile = open("Pension.csv", 'w')
for k in range(1,Iterations+1):
outfile.write(str(str(k) + ','))
outfile.write(str(CurrentInv[k][0])+',')
outfile.write(str(CurrentInv[k][60])+',')
outfile.write(str(CurrentInv[k][120])+',')
outfile.write(str(CurrentInv[k][180])+',')
outfile.write(str(CurrentInv[k][240])+',')
outfile.write(str(CurrentInv[k][300])+',')
outfile.write(str(CurrentInv[k][360])+',')
outfile.write(str('\n'))
outfile.close()
하지만 루프에서 이것을 얻고 싶습니다. 시도 했음
그러나이 방법은 매 60 회 반복되는 대신 CurrentInv에 대한 모든 값을 0에서 개월로 계속 인쇄합니다. 어떤 도움을 주시면 감사하겠습니다!
가능한 중복 https://stackoverflow.com/questions/17944235/for-loop-with -custom-steps-in-python) –
이것은 실제로 복제본입니다. 'range (0, Months + 1,60)'을 사용하십시오. – kabanus
그는 수정하고 싶은 범위가 다른 것 같다고 생각합니다. @ kabanus – Adirio