๐ ๋ชจ๋ ๋ง๋ค๊ธฐ
.ipynb ํ์ผ์ ๋ชจ๋ ํ์ผ์ธ .py ํ์ฅ์๋ฅผ ๊ฐ์ง ํ์ด์ฌ ์คํฌ๋ฆฝํธ ํ์ผ๋ก ๋ณํ ๋ฐฉ๋ฒ
1. cmd ์ฐฝ์์ ๋ช
๋ น์ด ์คํ
test.ipynb ํ์ผ์ด test.py ํ์ผ์ด ์์ฑ๋๋ค.
jupyter nbconvert --to script test.ipynb
2. ๋งค์ง ๋ช
๋ น์ด ์ฌ์ฉ
jupyter cell์ ์ฒซ ์ค์ ํด๋น ๋ช
๋ น์ด๋ฅผ ์์ฑ ํ ์ฝ๋๋ฅผ ์์ฑํด์ฃผ๊ณ ์คํ. -> test.py ํ์ผ์ด ์์ฑ๋๋ค.
%%writefile test.py
๋งค์ง ๋ช ๋ น์ด๋ "%" ํ๋์ธ ๊ฒฝ์ฐ ํ์ค๋ง ์คํ๋๊ณ , "%%" ๋๊ฐ๋ฅผ ์ฌ์ฉํด์ผ ์ฝ๋ ์ ์ ์ฒด์ ๋ํด์ ์คํ๋๋ค.
๐ ๋ชจ๋ ์ฌ์ฉํ๊ธฐ
1. ๋จ์ผ ๋ชจ๋ ๋ถ๋ฌ์ค๊ธฐ
import test
2. ๋ชจ๋์ ๋ณ๋ช ์ง์ ํ๊ธฐ
import test as tt
3. ํน์ ํจ์ ๋๋ ๋ณ์๋ง ๋ถ๋ฌ์ค๊ธฐ
from math import sqrt, pi
4. ๋ชจ๋์ ๋ชจ๋ ์์ ๋ถ๋ฌ์ค๊ธฐ
from math import *
๐ ๋ด์ฅ๋ชจ๋
import datetime
- ํ์ฌ ์๊ฐ ์ถ์ถ
- ์ํ๋ ์๊ฐ ๋ง๋ค๊ธฐ
- date-time ๋ฐ์ดํฐ ์ถ์ถ
now = datetime.datetime.now()
print(now.isoformat())
#2025-09-04T16:20:44.379572
print(now.strftime("%d/%m/%y"))
#04/09/25
print(now.strftime("%A %d. %B %Y"))
#Thursday 04. September 2025
print(now.ctime())
#Thu Sep 4 16:20:44 2025
print("The {1} is {0:%d}, the {2} is {0:%B}.".format(now, "day", "month"))
#The day is 04, the month is September.
print(now.strftime("%A, %d. %B %Y %I:%M%p"))
#Thursday, 04. September 2025 04:20PM
print(now.strftime("%H:%M:%S %Z"))
#16:20:44
print("The {} is {:%H:%M}.".format("time", now))
#The time is 16:20.
datetime — ๊ธฐ๋ณธ ๋ ์ง์ ์๊ฐ ํ — Python 3.8.20 ๋ฌธ์
datetime — ๊ธฐ๋ณธ ๋ ์ง์ ์๊ฐ ํ ์์ค ์ฝ๋: Lib/datetime.py datetime ๋ชจ๋์ ๋ ์ง์ ์๊ฐ์ ์กฐ์ํ๋ ํด๋์ค๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ ์ง์ ์๊ฐ ์ฐ์ ์ด ์ง์๋์ง๋ง, ๊ตฌํ์ ์ด์ ์ ์ถ๋ ฅ ํฌ๋งคํ ๊ณผ ์กฐ์์ ์ํ
docs.python.org
'AI' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ascii code <-> string ๋ณํ ๋ฐฉ๋ฒ (0) | 2025.09.10 |
---|---|
[Python] ์ ๋ ฅ๋ฐฉ๋ฒ input(), sys.stdin.readline(), strip() (0) | 2025.09.09 |
[Python] NumPy list์ Python list ์ฐจ์ด (0) | 2025.09.04 |
[Python] ์ง์ ํ๊ธฐ ๋ฐฉ๋ฒ + 2์ง์, 8์ง์, 16์ง์ ๋ณํ (0) | 2025.09.03 |
[AI] ์๋์ฝ๋ค ํจํค์ง ๋ชฉ๋ก ์ค ๋ง์ด ์ฌ์ฉํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (0) | 2025.09.02 |