<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>lazy_skunk</author_name>
  <author_url>https://blog.hatena.ne.jp/lazy_skunk/</author_url>
  <blog_title>ちんぱんの雑記</blog_title>
  <blog_url>https://lazy-skunk.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>知っている人には当たり前かもしれないけど、属性名を文字列で指定できる getattr が便利だったという話。 属性ごとの分岐をまとめる まずはクラス内のメソッドの例。getattr を使わず、引数に応じて属性を返すと、こんな書き方になる。 def get_something(self, keyword: str) -&gt; float: if keyword == &quot;A&quot;: return self.a elif keyword == &quot;B&quot;: return self.b elif keyword == &quot;C&quot;: return self.c elif keyword == &quot;D&quot;: return s…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Flazy-skunk.hatenablog.com%2Fentry%2F2024%2F12%2F03%2F221440&quot; title=&quot;getattr や setattr の使いどころ - ちんぱんの雑記&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2024-12-03 22:14:40</published>
  <title>getattr や setattr の使いどころ</title>
  <type>rich</type>
  <url>https://lazy-skunk.hatenablog.com/entry/2024/12/03/221440</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
