
WikiDocs : 초보자를 위한 파이썬 300제 풀면서 학습한 내용 정리 (참고 : https://wikidocs.net/book/922)
# datetime 모듈
import datetime
dir(datetime)
help(datetime.timedelta) | A timedelta object represents a duration, the difference between two dates or times.
날짜나 시간과 관련해 계산을 해야할때 유용함
now = datetime.datetime.now()
delta = datetime.timedelta(days=5)
# timedelta로 5일 duration을 만들고,
day_before_5 = now - delta
# 이렇게 datetime을 이용해 연산계산을 해서 특정 날짜나 시간 값을 얻어낼때 사용함
print(now, "/", day_before_5)
#... 2023-10-12 22:34:06.821551 / 2023-10-07 22:34:06.821551
now() function, when called without any arguments, returns a datetime object with the local time zone information.import datetime
now = datetime.datetime.now()
print(now.strftime("%Y-%b-%d-%a %H:%M:%S"))
#... 2023-Oct-13-Fri 09:12:42datetime.strptime(date_string, format)
import datetime
strptime = datetime.datetime.strptime("2023-10-13", "%Y-%m-%d")
print(strptime, type(strptime))
#... 2023-10-13 00:00:00 <class 'datetime.datetime'>
```
time.**sleep**(secs)import time
# Delay for 5 seconds
time.sleep(5)
# Display a message after the delay
print("Delayed message after 5 seconds") # import the entire module
import time
# import with an alias
import time as t
# import specific itemes : can use specific fuctinos or variable
from time import sleep
sleep(10)
print("Hello")
# import everything(not recommended)
# : can use them directly without the module name prefix
# : may lead to naming conflicts if multiple modules have the same names
from time import *
# 만약 파일경로를 바꿔서 새로운 이름으로 저장하고 싶으면
import os
import shutil
source_file = "/Users/seul/Desktop/test.txt"
destination_directory = os.getcwd() # Current working directory
new_filename = "after.txt"
# Combine the destination directory and new filename
destination_path = os.path.join(destination_directory, new_filename)
# Move the file to the new directory and rename it
shutil.move(source_file, destination_path)