<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>hayataka2049</author_name>
  <author_url>https://blog.hatena.ne.jp/hayataka2049/</author_url>
  <blog_title>静かなる名辞</blog_title>
  <blog_url>https://hayataka2049.hatenablog.jp/</blog_url>
  <categories>
    <anon>python</anon>
    <anon>Tips</anon>
    <anon>エラー対処法</anon>
  </categories>
  <description>pythonでクラスを書くとき、一番多用するのは（恐らく）インスタンス変数ですが、クラス変数もたまに使います。 しかし、pythonのクラス変数にはちょっと「クセ」があります。リスト内包表記と組み合わせたときに問題になることが多いようです。 問題の例 リスト内包表記と組み合わせ、他のクラス変数を使いまわしてクラス変数を定義しようとした例です。 class Hoge: x = 5 y = [x for i in range(10)] なんと以下のエラーを吐きます。 NameError: name 'x' is not defined こんな人畜無害そうなコードなのに、どうしてなのでしょう。 原因…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fhayataka2049.hatenablog.jp%2Fentry%2F2018%2F04%2F07%2F145324&quot; title=&quot;【python】クラス変数のスコープには注意が必要 - 静かなる名辞&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>2018-04-07 14:53:24</published>
  <title>【python】クラス変数のスコープには注意が必要</title>
  <type>rich</type>
  <url>https://hayataka2049.hatenablog.jp/entry/2018/04/07/145324</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
