{"id":268,"date":"2020-03-25T12:48:08","date_gmt":"2020-03-25T03:48:08","guid":{"rendered":"http:\/\/batmask.dothome.co.kr\/?p=268"},"modified":"2025-09-11T18:38:08","modified_gmt":"2025-09-11T09:38:08","slug":"python-metaclass","status":"publish","type":"post","link":"http:\/\/batmask.net\/index.php\/2020\/03\/25\/268\/","title":{"rendered":"Python : metaclass"},"content":{"rendered":"\n<p>metaclass\ub294 \uc77c\ubc18\uc801\uc778 \ud30c\uc774\uc36c \uc0ac\uc6a9\uc5d0\ub294 \ud544\uc694\uc5c6\ub294 \uc870\uae08\uc740 \uae4a\uc774 \ub4e4\uc5b4\uac00\ub294 \ub0b4\uc6a9\uc774\uc9c0\ub9cc, OOP\uc801 \uc811\uadfc\uc744 \uc704\ud574 \uc54c \ud544\uc694\uac00 \uc788\uc5b4\ubcf4\uc778\ub2e4.  <a href=\"https:\/\/stackoverflow.com\/questions\/100003\/what-are-metaclasses-in-python\">stackoverflow\uc5d0 \ub2ec\ub9b0 \uc124\uba85 \ucc38\uc870.<\/a><\/p>\n\n\n\n<p>\ud30c\uc774\uc36c\uc5d0\uc11c\ub294 \ubaa8\ub4e0\uac8c object\uc774\ub2e4. \ud074\ub798\uc2a4\ub3c4 object\ub85c \uc0dd\uc131\uc774 \ub418\uace0 instance\ud654 \uc2dc\ud0ac \ub54c, \uc774 object\uac00 \ubcf5\uc0ac\ub418\uba74\uc11c __init__ \ub8e8\ud2f4\uc744 \ud0c0\uac8c\ub41c\ub2e4. \uc77c\ubc18\uc801\uc778 \uc778\uc2a4\ud134\uc2a4\uc5d0 \ub300\ud574 \uc5b4\ub5a4 \ud074\ub798\uc2a4\ub85c\ubd80\ud130 \uc654\ub294\uc9c0 \uc54c\uc544\ubcf4\ub294 \ud568\uc218\uc5d0 type()\uc744 \uc4f8 \uc218 \uc788\ub294\ub370, \uadf8\ub807\ub2e4\uba74 \ud074\ub798\uc2a4\ub294 \uc5b4\ub5a4 \ud0c0\uc785\uc77c\uae4c?<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class Foo:\n    pass\n\nx = Foo()\n\nprint(type(x))\nprint(type(Foo))<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F69D50\">Foo<\/span><span style=\"color: #ADBAC7\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #F47067\">pass<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">x <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> Foo()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(x))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(Foo))<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>&lt;class '__main__.Foo'>\n&lt;class 'type'><\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;__main__.Foo&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\uc778\uc2a4\ud134\uc2a4 x\uc758 type\uc740 Foo\uc778\ub370, Foo\uc758 type\uc740 &#8216;type&#8217;\uc774\ub2e4. type\uc5d0 \ub300\ud574 \uc880 \ub354 \uc54c\uc544\ubcf4\uc790.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>for tp in int, float, dict, list, tuple:\n    print(type(tp))\n\nprint(type(type))<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">for<\/span><span style=\"color: #ADBAC7\"> tp <\/span><span style=\"color: #F47067\">in<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">int<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">float<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">dict<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">list<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">tuple<\/span><span style=\"color: #ADBAC7\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(tp))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">))<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>&lt;class 'type'>\n&lt;class 'type'>\n&lt;class 'type'>\n&lt;class 'type'>\n&lt;class 'type'>\n&lt;class 'type'><\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">&lt;class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&#39;type&#39;<\/span><span style=\"color: #F47067\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\uc704\uc5d0\uc11c \ubcf4\ub4ef\uc774 \uae30\ubcf8 \uc790\ub8cc\ud615\ub4e4\uc758 type\uc740 \ubaa8\ub450 &#8216;type&#8217;\uc774\ub2e4. \uc2ec\uc9c0\uc5b4 type\uc758 type\ub3c4 type\uc774\ub2e4. \uc774 \ubaa8\ub4e0 \ud074\ub798\uc2a4\ub4e4\uc758 \uc6d0\ud615\uc774 \ub418\ub294 \ud074\ub798\uc2a4\uc774\uc790 \uc778\uc2a4\ud134\uc2a4\uc778 \ub140\uc11d\uc744 metaclass\ub77c\uace0 \ubd80\ub978\ub2e4.  metaclass\uc758 \ub73b\uc740 \ud074\ub798\uc2a4\ub97c \ub9cc\ub4dc\ub294\ub370 \uc0ac\uc6a9\ub418\ub294 \ud074\ub798\uc2a4\ub97c \uc758\ubbf8\ud55c\ub2e4.<\/p>\n\n\n\n<p>\uc7a0\uae50 type\uc758 \ub2e4\ub978\uc6a9\ub3c4\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uc790. type\uc740 \uc778\uc790\ub97c \ub354 \uc0ac\uc6a9\ud558\uba74, \ud074\ub798\uc2a4\ub97c \ub9cc\ub4e4 \uc218 \uc788\ub2e4. <a href=\"https:\/\/docs.python.org\/3.8\/library\/functions.html#type\">\uba54\ub274\uc5bc type\ud56d\ubaa9 \ucc38\uc870<\/a><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class type(name, bases, dict)\n# name : name of the class\n# bases : tuple of the parent class(can be empty)\n# attrs : dictionary containing attributes names and values<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">name<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">bases<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #6CB6FF\">dict<\/span><span style=\"color: #ADBAC7\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\"># <\/span><span style=\"color: #F69D50\">name<\/span><span style=\"color: #ADBAC7\"> : name of the <\/span><span style=\"color: #F47067\">class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #768390\"># bases : tuple of the parent class(can be empty)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #768390\"># attrs : dictionary containing attributes names and values<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\uc774\ub294 \ucf54\ub4dc\uc0c1\uc5d0\uc11c &#8216;class&#8217;\ud0a4\uc6cc\ub4dc\ub97c \ub9cc\ub0ac\uc744 \ub54c \ud558\ub294 \uac83\uacfc \ub3d9\uc77c\ud558\uba70, \ub2e4\uc74c\uc758 \ub450 \ucf54\ub4dc\ub294 \uac19\uc740\uc77c\uc744 \ud55c\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class MyClass():\n    pass<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F69D50\">MyClass<\/span><span style=\"color: #ADBAC7\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #F47067\">pass<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>MyClass = type(\"MyClass\", (), {})<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">MyClass <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&quot;MyClass&quot;<\/span><span style=\"color: #ADBAC7\">, (), {})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\ub2e4\uc2dc metaclass\ub85c \ub3cc\uc544\uac00 custom metaclass\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uc790. <\/p>\n\n\n\n<p>\uac1d\uccb4\ub97c \uc0dd\uc131\ud558\ub294 \ucf54\ub4dc\ub97c \ubcf4\uba74,<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class Foo:\n    pass\n\nf = Foo()<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F69D50\">Foo<\/span><span style=\"color: #ADBAC7\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #F47067\">pass<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">f <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> Foo()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Foo()\ub97c \ub9cc\ub0ac\uc744 \ub54c, Foo\uc758 parent class\uc758 __call__()\uc774 \ubd88\ub9b0\ub2e4. super class\ub77c\ub294\uac78 \uc8fc\uc758\ud558\uc790. Foo\uc5d0\uc11c __call__\uc744 \uc815\uc758\ud574\ub3c4 \ubd88\ub9ac\uc9c0 \uc54a\ub294\ub2e4. \ub530\ub77c \uc62c\ub77c\uac00\uba74, type\uc774 \ub098\uc624\uac8c \ub418\uace0, type\uc5d0\uc11c __call__()\uc740 \ub2e4\uc74c \ub450 __new__(), __init__()\ud568\uc218\ub97c \uc21c\uc11c\ub300\ub85c \ud638\ucd9c\ud55c\ub2e4. \uc774 \ub450 \ud568\uc218\ub294 overriding\ud558\uba74 \uadf8\uac83\uc774 \ud638\ucd9c\ub41c\ub2e4. <\/p>\n\n\n\n<p>\ub9cc\uc57d metaclass\uc778 type\uc744 \uc0c1\uc18d\ubc1b\uc544 \ud074\ub798\uc2a4\ub97c \ub9cc\ub4e4\uac8c \ub418\uba74,<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class MyType(type):\n    def __new__(cls, name, bases, dct):\n        x = super().__new__(cls, name, bases, dct)\n        x.attr = 100\n        return x<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F69D50\">MyType<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">type<\/span><span style=\"color: #ADBAC7\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #F47067\">def<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">__new__<\/span><span style=\"color: #ADBAC7\">(cls, name, bases, dct):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">        x <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">super<\/span><span style=\"color: #ADBAC7\">().<\/span><span style=\"color: #6CB6FF\">__new__<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">cls<\/span><span style=\"color: #ADBAC7\">, name, bases, dct)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">        x.attr <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">100<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">        <\/span><span style=\"color: #F47067\">return<\/span><span style=\"color: #ADBAC7\"> x<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>metaclass\ub97c \uc0c1\uc18d\ubc1b\uc558\uc73c\ubbc0\ub85c, MyType\ub3c4 type\uc758 __new__\ub97c \ubcc0\ud615\ud55c metaclass\uac00 \ub41c\ub2e4. \uadf8\ub807\ub2e4\uba74, \uc774\ub807\uac8c \uc0ac\uc6a9\uc790\uac00 \ub9cc\ub4e0 metaclass\ub294 \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc744\uae4c? \ud074\ub798\uc2a4 \uc815\uc758\uc2dc, &#8216;metaclass&#8217; \ud0a4\uc6cc\ub4dc\ub97c \uc774\uc6a9\ud55c\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class Bar(metaclass=MyType):\n    pass\n\nprint(Bar.attr)<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">class<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F69D50\">Bar<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #6CB6FF\">metaclass<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #6CB6FF\">MyType<\/span><span style=\"color: #ADBAC7\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #F47067\">pass<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(Bar.attr)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>100<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6CB6FF\">100<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\uc2dc\uc791\uc740 design pattern\uc758 singleton \uad6c\ud604 \ub54c\ubb38\uc774\uc5c8\ub294\ub370, \uc790\ub8cc\ub97c \ucc3e\uc544\ubcf4\ub294 \uacfc\uc815\uc5d0\uc11c custom metaclass\uac00 \uaf2d \ud544\uc694\ud55c\uac74 \uc544\ub2c8\ub77c\uace0 \ub290\uaf08\ub2e4. decorator\ub97c \uc774\uc6a9\ud574\uc11c \ube44\uc2b7\ud55c \uc5ed\ud560\uc774 \uac00\ub2a5\ud558\uae30\ub3c4 \ud558\uace0. <a href=\"https:\/\/stackoverflow.com\/questions\/6760685\/creating-a-singleton-in-python\">stack overflow\uc758 singleton \uad6c\ud604 \ub2f5\ubcc0 \ucc38\uc870<\/a>. \uc5b4\uca0c\ub4e0, metaclass\ub97c \uc774\uc6a9\ud558\uba74 \uaf64 \uae54\ub054\ud558\uac8c \uad6c\ud604\uc774 \ub418\ub294\ub4ef.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>metaclass\ub294 \uc77c\ubc18\uc801\uc778 \ud30c\uc774\uc36c \uc0ac\uc6a9\uc5d0\ub294 \ud544\uc694\uc5c6\ub294 \uc870\uae08\uc740 \uae4a\uc774 \ub4e4\uc5b4\uac00\ub294 \ub0b4\uc6a9\uc774\uc9c0\ub9cc, OOP\uc801 \uc811\uadfc\uc744 \uc704\ud574 \uc54c \ud544\uc694\uac00 \uc788\uc5b4\ubcf4\uc778\ub2e4. stackoverflow\uc5d0 \ub2ec\ub9b0 \uc124\uba85 \ucc38\uc870. \ud30c\uc774\uc36c\uc5d0\uc11c\ub294 \ubaa8\ub4e0\uac8c object\uc774\ub2e4. \ud074\ub798\uc2a4\ub3c4 object\ub85c \uc0dd\uc131\uc774 \ub418\uace0 instance\ud654 \uc2dc\ud0ac \ub54c, \uc774 object\uac00 \ubcf5\uc0ac\ub418\uba74\uc11c __init__ \ub8e8\ud2f4\uc744 \ud0c0\uac8c\ub41c\ub2e4. \uc77c\ubc18\uc801\uc778 \uc778\uc2a4\ud134\uc2a4\uc5d0 \ub300\ud574 \uc5b4\ub5a4 \ud074\ub798\uc2a4\ub85c\ubd80\ud130 \uc654\ub294\uc9c0 \uc54c\uc544\ubcf4\ub294 \ud568\uc218\uc5d0 type()\uc744 \uc4f8 \uc218 \uc788\ub294\ub370, \uadf8\ub807\ub2e4\uba74 \ud074\ub798\uc2a4\ub294 \uc5b4\ub5a4 \ud0c0\uc785\uc77c\uae4c? \uc778\uc2a4\ud134\uc2a4 x\uc758 type\uc740 Foo\uc778\ub370, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,33],"tags":[99,35,124,55],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-etc","category-python","tag-metaclass","tag-python","tag-metaclass-kr","tag-python-kr"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":3,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":3447,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions\/3447"}],"wp:attachment":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}