홈>
파이썬에서 명령 행을 사용하지 않고 프로그램 출력을 인쇄하는 대신 파일로 보내는 명령은 무엇입니까? 또한 파일 이름이 매일 지정되는 경우 (2019-03-11) (오늘 날짜 일 필요는 없음) 파일 이름을 어떻게 늘리나요?
-
답변 # 1
-
답변 # 2
#First create a blank txt file in the directory as your code file. and name it filename.txt. If you want to add to the file add a 'a' mode to the open. def save(): filename = '2019-01-01.txt' output = 'Your own output' file = open(filename, 'w') file.write(output) file.close() import os os.rename(filename, '2019-01-02.txt') file = open('file.txt', 'r') reader = file.read() print(reader) file.close()
코드를 실행하는 동안 날짜는 어떻게 바뀌나요?
데이터 세트에서 날짜를 가져 오면 코드는 다음과 같이 나타납니다.
특정 기간 (예 : 격일)에 걸쳐 증분해야하는 경우 위와 동일한 아이디어를 사용하지만이 코드를 사용하여 날짜를 생성합니다.
이것이 당신이 찾고 있었던 것이기를 바랍니다.