{"id":1430,"date":"2018-01-15T23:27:39","date_gmt":"2018-01-15T14:27:39","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1430"},"modified":"2018-01-15T23:27:39","modified_gmt":"2018-01-15T14:27:39","slug":"hasattr-%e6%8c%87%e5%ae%9a%e3%81%ae%e5%b1%9e%e6%80%a7%e3%82%92%e6%8c%81%e3%81%a4%e3%81%8b%e3%81%a9%e3%81%86%e3%81%8b%e3%82%92%e6%a4%9c%e6%9f%bb%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1430","title":{"rendered":"hasattr \u6307\u5b9a\u306e\u5c5e\u6027\u3092\u6301\u3064\u304b\u3069\u3046\u304b\u3092\u691c\u67fb\u3059\u308b"},"content":{"rendered":"<h2>hasattr<\/h2>\n<p>Python\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u52d5\u7684\u306b\u5c5e\u6027\u3092\u8ffd\u52a0\u3057\u305f\u308a\u524a\u9664\u3067\u304d\u308b\u305f\u3081\u3001\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5c5e\u6027\u3092\u6301\u3064\u304b\u3069\u3046\u304b\u306f(\u578b\u306b\u4f9d\u5b58\u305b\u305a)\u72b6\u6cc1\u6b21\u7b2c\u300d\u3068\u3044\u3046\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3042\u308b\u7a0b\u5ea6\u898f\u6a21\u306e\u5927\u304d\u306a\u958b\u767a\u306e\u5834\u5408\u3001\u30c7\u30fc\u30bf\u306e\u9023\u643a\u6642\u306b\u671f\u5f85\u3057\u305f\u5c5e\u6027\u3092\u6301\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u305f\u304f\u306a\u308b\u3053\u3068\u304c\u591a\u3005\u51fa\u3066\u304d\u307e\u3059\u304c\u3001\u3053\u3046\u3044\u3063\u305f\u5834\u5408hasattr\u3068\u3044\u3046\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3067\u4e8b\u524d\u306b\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002hasattr\u95a2\u6570\u306f\u3001\u7b2c1\u5f15\u6570\u306b\u691c\u67fb\u5bfe\u8c61\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001\u7b2c2\u5f15\u6570\u306b\u5c5e\u6027\u540d\u306e\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass User():\r\n    &quot;&quot;&quot;\r\n    \u30e6\u30fc\u30b6\u30fc\u30af\u30e9\u30b9\r\n    &quot;&quot;&quot;\r\n\r\n    def __init__(self, name=&quot;&quot;):\r\n        self.name = name\r\n\r\n    def say_hello(self):\r\n        print(&quot;Hello, my name is &quot; + self.name)\r\n\r\n    def __str__(self):\r\n        return &quot;name:&quot; + self.name\r\n\r\n\r\n# \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3059\u308b\r\nuser = User(&quot;Kuro&quot;)\r\n\r\n# age\u3068\u3044\u3046\u5c5e\u6027\u3092\u6301\u3064\u304b\u3069\u3046\u304b\u3092\u691c\u7d22\u3059\u308b\r\nprint(hasattr(user, &quot;age&quot;))\r\n# False\r\n\r\n# age\u3068\u3044\u3046\u5c5e\u6027\u3092\u8ffd\u52a0\u3059\u308b\r\nuser.age = 30\r\n\r\n# \u518d\u5ea6\u691c\u67fb\u3059\u308b\r\nprint(hasattr(user, &quot;age&quot;))\r\n# True\r\n\r\n<\/pre>\n<p>user\u3068\u3044\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u6700\u521dage\u3068\u3044\u3046\u5c5e\u6027\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u305f\u3081\u3001False\u3068\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u5c5e\u6027\u8ffd\u52a0\u5f8c\u306fTrue\u3068\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>hasattr Python\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u52d5\u7684\u306b\u5c5e\u6027\u3092\u8ffd\u52a0\u3057\u305f\u308a\u524a\u9664\u3067\u304d\u308b\u305f\u3081\u3001\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5c5e\u6027\u3092\u6301\u3064\u304b\u3069\u3046\u304b\u306f(\u578b\u306b\u4f9d\u5b58\u305b\u305a)\u72b6\u6cc1\u6b21\u7b2c\u300d\u3068\u3044\u3046\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002 \u3042\u308b\u7a0b\u5ea6\u898f\u6a21\u306e\u5927\u304d\u306a\u958b\u767a\u306e\u5834\u5408\u3001\u30c7\u30fc\u30bf\u306e\u9023\u643a\u6642\u306b\u671f\u5f85...<\/p>\n","protected":false},"author":1,"featured_media":3623,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[103,136],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1430"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1430"}],"version-history":[{"count":4,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1430\/revisions"}],"predecessor-version":[{"id":3624,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1430\/revisions\/3624"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3623"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}