Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":3528,"date":"2023-08-18T10:20:02","date_gmt":"2023-08-18T01:20:02","guid":{"rendered":"https:\/\/craft-gogo.com\/?p=3528"},"modified":"2023-08-18T10:20:04","modified_gmt":"2023-08-18T01:20:04","slug":"python-name_main","status":"publish","type":"post","link":"https:\/\/craft-gogo.com\/python-name_main\/","title":{"rendered":"\u3088\u304f\u898b\u308b\u300cif __name__ == \u2018__main__’\u300d\u3063\u3066\u4f55\uff1f\u610f\u5473\u3068\u7528\u9014\u3092\u89e3\u8aac"},"content":{"rendered":"\n

Python\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3044\u308b\u3068\u300cif __name__ == \u2018__main__’\u300d\u3068\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3088\u306d\uff1f<\/p>\n\n\n\n

\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u3044\u3068\u3001\u305d\u306e\u6642\u70b9\u3067\u30b3\u30fc\u30c9\u89e3\u8aad\u96e2\u8131\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\u672c\u8a18\u4e8b\u3067\u306f\u3001\u3053\u306e\u69cb\u6587\u304c\u4f55\u3092\u610f\u5473\u3057\u3001\u3069\u3093\u306a\u3068\u304d\u306b\u4f7f\u3046\u306e\u304b\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

\u3053\u3093\u306a\u4eba\u306b\u304a\u3059\u3059\u3081<\/span><\/div>
\n

Python\u5b66\u7fd2\u3092\u59cb\u3081\u305f\u3070\u304b\u308a\u306e\u4eba<\/p>\n<\/div><\/div>\n\n\n\n

if __name__ == \u2018__main__’\u306e\u610f\u5473\u3068\u7528\u9014<\/h2>\n\n\n\n

if __name__ == \u2018__main__’\u306e\u610f\u5473\u306f\u3001\u3082\u3057Python\u30b3\u30fc\u30c9\u304c\u76f4\u63a5\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306f\u4ee5\u964d\u306e\u30b3\u30fc\u30c9\u3092\u51e6\u7406\u3057\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u547c\u3073\u51fa\u3055\u308c\u305f\u3068\u304d\u306f\u51e6\u7406\u3057\u306a\u3044<\/span><\/strong>\u3067\u3059\u3002<\/p>\n\n\n\n

\u7528\u9014\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u306b\u3001\u52dd\u624b\u306b\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u3092\u9632\u3050<\/span><\/strong>\u3053\u3068\u3067\u3059\u3002\u307e\u305f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5358\u4f53\u30c6\u30b9\u30c8\u7528<\/span><\/strong>\u3068\u3057\u3066\u3082\u4f7f\u308f\u308c\u307e\u3059\u3002\u30b3\u30fc\u30c9\u3092\u76f4\u63a5\u5b9f\u884c\u3057\u305f\u3068\u304d\u3068\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u4ed6\u306e\u30b3\u30fc\u30c9\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u5206\u3051\u308b\u3053\u3068\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5358\u4f53\u30c6\u30b9\u30c8\u3092\u53ef\u80fd\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5358\u4f53\u30c6\u30b9\u30c8\u7528\u3067\u3059\u304b\u3089\u3001Python\u30b3\u30fc\u30c9\u304c1\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u306f\u3001\u3053\u306e\u69cb\u6587\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002<\/span><\/strong><\/p>\n\n\n\n

\u6b21\u9805\u3067\u306f\u3001Python\u30b3\u30fc\u30c9\u304c\u76f4\u63a5\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306e\u307f\u51e6\u7406\u3059\u308b\u4ed5\u7d44\u307f\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

__name__\u5909\u6570\u3068\u306f<\/h2>\n\n\n\n

__name__\u5909\u6570\u3068\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u3092\u8fd4\u3059\u7279\u5225\u306a\u5909\u6570<\/span><\/strong>\u3067\u3059\u3002import\u3067\u4ed6\u306e\u30b3\u30fc\u30c9\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u305f\u5834\u5408\u306f\u3001__name__\u306f\u30d5\u30a1\u30a4\u30eb\u540d\u3068\u306a\u308a\u307e\u3059\u3002\u4e00\u65b9\u3001\u30b3\u30fc\u30c9\u3092\u76f4\u63a5\u5b9f\u884c\u3057\u305f\u5834\u5408\u306f\u3001__name__\u306f\u30d5\u30a1\u30a4\u30eb\u540d\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n

\u30e2\u30b8\u30e5\u30fc\u30eb\u300cmodule.py\u300d\u3068\u30e1\u30a4\u30f3\u30b3\u30fc\u30c9\u300cmain.py\u300d\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n

def func():\n    return __name__\n\nif __name__ == '__main__':\n    print('__name__ = ' + func())<\/code><\/pre><\/div>\n\n\n\n
import module\n\nprint('__name__ = ' + module.func())<\/code><\/pre><\/div>\n\n\n\n

\u305d\u308c\u305e\u308c\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3068\u4e0b\u8868\u306e\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n

\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb<\/th>module.py<\/th>main.py<\/th><\/tr><\/thead>
__name__<\/td>__main__<\/td>module<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

main.py\u304b\u3089module.py\u3092import\u3057\u305f\u3068\u304d\u306f\u3001”if name == ‘main’:” \u4ee5\u964d\u306e\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u306a\u3044\u306e\u304c\u304a\u5206\u304b\u308a\u3067\u3059\u306d\u3002<\/p>\n\n\n\n

\u307e\u3068\u3081<\/h2>\n\n\n\n

Python\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u3088\u304f\u898b\u308b\u300cif __name__ == \u2018__main__’\u300d\u306e\u610f\u5473\u3068\u7528\u9014\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n

\n

\u610f\u5473<\/span><\/p>\n\n\n\n

    \n
  • \u3082\u3057Python\u30b3\u30fc\u30c9\u304c\u76f4\u63a5\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306f\u4ee5\u964d\u306e\u30b3\u30fc\u30c9\u3092\u51e6\u7406\u3057\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u547c\u3073\u51fa\u3055\u308c\u305f\u3068\u304d\u306f\u51e6\u7406\u3057\u306a\u3044<\/li>\n<\/ul>\n\n\n\n

    \u7528\u9014<\/span><\/p>\n\n\n\n

      \n
    • \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u306b\u3001\u52dd\u624b\u306b\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u3092\u9632\u3050<\/li>\n\n\n\n
    • \u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5358\u4f53\u30c6\u30b9\u30c8\u7528<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n
      <\/dl>\n\n\n\n

      \u4eca\u56de\u306e\u8a18\u4e8b\u304c\u7686\u3055\u3093\u306ePython\u5b66\u7fd2\u306b\u5f79\u7acb\u3064\u306a\u3089\u5e78\u3044\u3067\u3059\u3002<\/p>\n\n\n\n

      Python\u72ec\u5b66\u304c\u5927\u5909\u306a\u65b9\u306f\u3001\u66f8\u7c4d\u3084\u30b9\u30af\u30fc\u30eb\u3092\u6d3b\u7528<\/strong>\u3059\u308b\u306e\u3082\u624b\u3067\u3059\u3002<\/p>\n\n\n\n

      \n
      \n