{"id":1676,"date":"2022-01-29T13:32:44","date_gmt":"2022-01-29T04:32:44","guid":{"rendered":"https:\/\/aiacademy.jp\/media\/?p=1676"},"modified":"2025-06-12T15:33:47","modified_gmt":"2025-06-12T06:33:47","slug":"python-__name__-%e3%81%a8%e3%81%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=1676","title":{"rendered":"Python __name__ \u3068\u306f\uff1f"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"i-0\">__name__ \u3068\u306f<\/h1>\n\n\n\n<p>__name__\u306f\u3001Python\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306b\u81ea\u52d5\u7684\u306b\u4f5c\u3089\u308c\u308b\u5909\u6570\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u5909\u6570\u306b\u306f\u3001\u5b9f\u884c\u3057\u3066\u3044\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u304c\u81ea\u52d5\u7684\u306b\u4ee3\u5165\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001<code>sample.py<\/code>\u3068\u3044\u3046\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u304c\u66f8\u304b\u308c\u305fPython\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u3042\u308b\u5834\u5408\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def sample_func():\n    print(\"sample func\")\n    print(__name__)    \nsample_func()<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u300c<meta charset=\"utf-8\">sample.py\u300d\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u3001<code>&nbsp;import sample&nbsp;<\/code>\u3068\u3057\u3066\u8aad\u307f\u8fbc\u3080\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sample func\n__sample__<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u6642\u3001<code>import sample&nbsp;<\/code>\u3068\u3057\u3066\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u8aad\u307f\u8fbc\u307e\u308c\u305f\u300csample.py\u300d\u306e<code>print(__name__)\u306e<\/code>\u51fa\u529b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u540d\uff08\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\uff09\u306e\u300c<strong>__sample__<\/strong>\u300d\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u8aad\u307f\u8fbc\u307e\u308c\u305f\u5834\u5408\u3001<strong><code>__name__<\/code><\/strong>&nbsp;\u306b\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u304c\u683c\u7d0d\u3055\u308c\u308b\u305f\u3081\u3001\u4eca\u56de\u306f\u300csample.py\u300d\u306a\u306e\u3067\u3001__sample__\u3068\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u304c\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\uff08\u30d5\u30a1\u30a4\u30eb\u540d\uff09\u304c\u4f8b\u3048\u3070\u3001\u300ctest.py\u300d\u3067\u3042\u308c\u3070\u3001\u51fa\u529b\u306f__test__ \u3068\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>\u3053\u306e\u3088\u3046\u306b\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u8aad\u307f\u8fbc\u307e\u308c\u305f<\/strong>\u5834\u5408\u306b\u3001<strong><code>__name__<\/code>&nbsp;\u306b\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u304c\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3053\u3068\u3092\u7406\u89e3\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-1\"><a href=\"https:\/\/aiacademy.jp\/media\/?p=1669\">if __<strong>name__<\/strong>&nbsp;== \u2018__<strong>main<\/strong>__\u2019: \u3068\u306f<\/a><\/h1>\n\n\n\n<p><span class=\"keiko_green\">\u3053\u306e\u30b5\u30a4\u30c8\u306f\u3001Python\u3084\u751f\u6210AI\u306a\u3069\u3092\u5b66\u3079\u308b\u30aa\u30f3\u30e9\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb AI Academy Bootcamp\u304c\u904b\u55b6\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">__name__ \u3068\u306f<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-1\">if __name__\u00a0== \u2018__main__\u2019: \u3068\u306f<\/a>    <ul class=\"menu_level_1\">      <li class=\"first last\">        <a href=\"#i-2\">\u3010\u7121\u6599\u52d5\u753b\uff1a\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 class=\"wp-block-heading\" id=\"i-2\">\u3010\u7121\u6599\u52d5\u753b\uff1a<strong>\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/strong><\/h2>\n\n\n\n<p>\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u3066\u52b9\u7387\u7684\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u5b66\u3076\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002\u751f\u6210AI\u306e\u57fa\u672c\u7684\u306a\u4ed5\u7d44\u307f\u3084\u52b9\u679c\u7684\u306a\u6d3b\u7528\u6cd5\u3001\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u3082\u8a73\u3057\u304f\u8aac\u660e\u3002\u52c9\u5f37\u6cd5\u3068\u3068\u3082\u306b\u751f\u6210AI\u305d\u306e\u3082\u306e\u306b\u3064\u3044\u3066\u3082\u5b66\u3079\u308b\u5185\u5bb9\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u305c\u3072\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-vimeo wp-block-embed-vimeo wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/1069835048?h=e43b17d6de&amp;dnt=1&amp;app_id=122963\" width=\"880\" height=\"495\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>\u5168\u7de8\u306f\u3001AI Academy\u516c\u5f0fLINE\u3067\u914d\u4fe1\u4e2d\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/lin.ee\/3E4GzWk\" target=\"_blank\" rel=\" noreferrer noopener nofollow\"><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"517\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png\" alt=\"\" class=\"wp-image-6799\" style=\"width:158px;height:auto\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png 910w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-300x170.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-768x436.png 768w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>__name__ \u3068\u306f __name__\u306f\u3001Python\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306b\u81ea\u52d5\u7684\u306b\u4f5c\u3089\u308c\u308b\u5909\u6570\u3067\u3059\u3002 \u3053\u306e\u5909\u6570\u306b\u306f\u3001\u5b9f\u884c\u3057\u3066\u3044\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u304c\u81ea\u52d5\u7684\u306b\u4ee3\u5165\u3055\u308c\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001sample.py\u3068\u3044\u3046\u4ee5\u4e0b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1678,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"class_list":{"0":"post-1676","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1676"}],"version-history":[{"count":12,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1676\/revisions"}],"predecessor-version":[{"id":7574,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1676\/revisions\/7574"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/1678"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}