Search
Duplicate

Dataclasses์™€ Argparse

Created
5/31/2021, 6:59:00 AM
Tags
Empty

Dataclasses

Python 3.7๋ฒ„์ „๋ถ€ํ„ฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค๋กœ, argument๋ฅผ ์ €์žฅํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๊ธฐ์— ๋งค์šฐ ์šฉ์ดํ•œ ํด๋ž˜์Šค์ด๋‹ค.
[ํŒŒ์ด์ฌ] ๋ฐ์ดํ„ฐ ํด๋ž˜์Šค ์‚ฌ์šฉ๋ฒ• (dataclasses ๋ชจ๋“ˆ)
์šฐ๋ฆฌ๋Š” ํŒŒ์ด์ฌ์œผ๋กœ ์ฝ”๋”ฉ์„ ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์•„๋‘๊ธฐ ์œ„ํ•ด์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ(list), ํŠœํ”Œ(tuple), ์‚ฌ์ „(dictoinary), ๋„ค์ž„๋“œ ํŠœํ”Œ(namedtuple), ์„ธํŠธ(set), ํ”„๋กœ์ฆŒ ์„ธํŠธ(frozen set)์™€ ๊ฐ™์€ ๋‚ด์žฅ ์ž๋ฃŒ ๊ตฌ์กฐ๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ๊ฐ„ํŽธํ•˜๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด์— ํด๋ž˜์Šค(class)๋ฅผ ์ด์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์•„๋‘๋ฉด type-safeํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์ค‘์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ํ™•๋ฅ ์ด ์ ์–ด์ง„๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ 3.7์—์„œ dataclasses๋ผ๋Š” ๋งค์šฐ ๋งค๋ ฅ์ ์ธ ๋ชจ๋“ˆ์ด ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์ถ”๊ฐ€๋˜์—ˆ๋Š”๋ฐ์š”.
TOP