<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Ops运维 | Mr`kang Blog｜小豆子]]></title> 
<link>https://www.cnmysql.com/index.php</link> 
<description><![CDATA[关注服务器运维技术、DB优化、Docker虚拟化、自动化运维、工作积累]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Ops运维 | Mr`kang Blog｜小豆子]]></copyright>
<item>
<link>https://www.cnmysql.com/post//</link>
<title><![CDATA[Python name、main 的使用]]></title> 
<author>kangyang &lt;kangyang315@qq.com&gt;</author>
<category><![CDATA[Python]]></category>
<pubDate>Wed, 13 Aug 2014 10:03:34 +0000</pubDate> 
<guid>https://www.cnmysql.com/post//</guid> 
<description>
<![CDATA[ 
	<span style="font-size: 12px;"><span style="font-family: 宋体;">在python中，Main可以说是程序执行的起点，但也不全是，Python 使用缩进组织整个代码结构，所有没有缩进的代码（非函数定义和类定义），都会在载入时自动执行，这些代码，可以认为是Python的main函数。<br/>如下:<br/>###这段代码的主要作用主要是让该python文件既可以独立运行，也可以当做模块导入到其他文件###<br/>###当导入到其他的脚本文件的时候，此时__name__的名字其实是导入模块的名字，不是'__main__', main代码里面的就不执行了###<br/>if __name__ == '__main__':<br/>&nbsp;&nbsp;&nbsp;&nbsp;print "test __name__"<br/>示例：<br/>>>> def test():<br/>... print("Test function.")<br/>... print("main")<br/>...<br/>>>> if __name__ == '__main__':<br/>... test()<br/><br/>输出如下：<br/>...<br/>Test function.<br/>main<br/><br/>当作为模块被导入时：<br/><br/>##当你直接执行.py时，__name__是__main__，当作为模块被导入时，则是模块的名字....##<br/>>>> import example<br/>>>> example.test<br/>>>> example.test()<br/>Test function.<br/>>>> example.__name__<br/>'example'</span></span><br/>Tags - <a href="https://www.cnmysql.com/tags/python/" rel="tag">python</a> , <a href="https://www.cnmysql.com/tags/name/" rel="tag">name</a> , <a href="https://www.cnmysql.com/tags/main/" rel="tag">main</a>
]]>
</description>
</item><item>
<link>https://www.cnmysql.com/post//#blogcomment</link>
<title><![CDATA[[评论] Python name、main 的使用]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.cnmysql.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>