<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>基础 on Anttu&#39;s Blog</title>
		<link>https://anTtutu.github.io/tags/%E5%9F%BA%E7%A1%80/</link>
		<description>Recent content in 基础 on Anttu&#39;s Blog</description>
		<generator>Hugo</generator>
		<language>zh-CN</language>
		
		
		
		
			<lastBuildDate>Fri, 15 Sep 2023 08:00:00 +0800</lastBuildDate>
		
			<atom:link href="https://anTtutu.github.io/tags/%E5%9F%BA%E7%A1%80/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Python双下划线详解：__name__与魔术方法/属性全面整理（含版本限制）</title>
				<link>https://anTtutu.github.io/post/2023-09-15-python-dunder-magic-methods/</link>
				<pubDate>Fri, 15 Sep 2023 08:00:00 +0800</pubDate>
				<guid>https://anTtutu.github.io/post/2023-09-15-python-dunder-magic-methods/</guid>
				<description>&lt;h2 id=&#34;前言&#34;&gt;前言&lt;/h2&gt;&#xA;&lt;p&gt;Python 里到处都是双下划线：&lt;code&gt;__name__&lt;/code&gt;、&lt;code&gt;__init__&lt;/code&gt;、&lt;code&gt;__all__&lt;/code&gt;、&lt;code&gt;__getattr__&lt;/code&gt;……刚学的时候只知道 &lt;code&gt;if __name__ == &#39;__main__&#39;&lt;/code&gt; 这么抄，不清楚背后的整套设计。这篇把双下划线家族（俗称 dunder，double underscore 的缩写）按用途全面整理一遍，每个都带小样例，有版本要求的标明版本。&lt;/p&gt;&#xA;&lt;p&gt;先给个总原则（PEP 8 的原话）：&lt;strong&gt;&lt;code&gt;__xxx__&lt;/code&gt; 这种前后双下划线的命名权属于 Python 解释器，自己写类不要发明这种名字&lt;/strong&gt;，想表达内部属性用单下划线 &lt;code&gt;_foo&lt;/code&gt; 或者双下划线前缀 &lt;code&gt;__foo&lt;/code&gt;（后面讲它的改写机制）。&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
