<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>python on Two Tigers Engineering</title>
    <link>https://blog.twotigers.xyz/series/python/</link>
    <description>Recent content in python on Two Tigers Engineering</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 24 Nov 2021 14:10:25 +0800</lastBuildDate><atom:link href="https://blog.twotigers.xyz/series/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Python 枚举使用</title>
      <link>https://blog.twotigers.xyz/posts/python/enum/</link>
      <pubDate>Wed, 24 Nov 2021 14:10:25 +0800</pubDate>
      
      <guid>https://blog.twotigers.xyz/posts/python/enum/</guid>
      <description>from enum import Enum class Gender(Enum): male = 0 female = 1 print(Gender(0)) # Gender.male print(Gender(0).name) # female print(Gender(0).value) # 0 class EnumWithLabel(Enum): &amp;#34;&amp;#34;&amp;#34; 允许带 label 的枚举类型, 参考: https://docs.python.org/zh-cn/3/library/enum.html#when-to-use-new-vs-init &amp;#34;&amp;#34;&amp;#34; def __new__(cls, value, label): obj = object.__new__(cls) obj._value_ = value obj.label = label return obj class GenderWithLabel(EnumWithLabel): male = (0, &amp;#34;MAN&amp;#34;) female = (1, &amp;#34;WOMAN&amp;#34;) print(GenderWithLabel(0)) # GenderWithLabel.male print(GenderWithLabel(0).value) # 0 print(GenderWithLabel(0).label) # MAN class EnumWithDefault(Enum): &amp;#34;&amp;#34;&amp;#34; 允许返回默认值的枚举类型, 不存在枚举值时不会报错 如果需要修改默认值则需要覆盖 new_default_obj 函数 &amp;#34;&amp;#34;&amp;#34; @classmethod def _missing_(cls, value): new_member = cls.</description>
    </item>
    
    <item>
      <title>Mac 安装 mysqlclient</title>
      <link>https://blog.twotigers.xyz/posts/python/mysql/</link>
      <pubDate>Wed, 17 Nov 2021 11:17:25 +0800</pubDate>
      
      <guid>https://blog.twotigers.xyz/posts/python/mysql/</guid>
      <description>Python 版本 (venv) ➜ python --version Python 3.8.2 安装 brew install mysql export LDFLAGS=&amp;#34;-L/usr/local/opt/openssl/lib&amp;#34; export CPPFLAGS=&amp;#34;-I/usr/local/opt/openssl/include&amp;#34; pip install mysqlclient brew uninstall mysql </description>
    </item>
    
    <item>
      <title>Python 中的else</title>
      <link>https://blog.twotigers.xyz/posts/python/else/</link>
      <pubDate>Fri, 15 Oct 2021 14:00:08 +0800</pubDate>
      
      <guid>https://blog.twotigers.xyz/posts/python/else/</guid>
      <description>if&amp;hellip;else 最常见的 else if 1 &amp;gt; 0: pass else: pass for else for 循环中 只有 for 循环结束了才执行, 注意空循环也会执行 for i in range(3): print(i) else: print(&amp;#34;end&amp;#34;) # 0 # 1 # 2 # end for i in range(3): print(i) if i == 1: break else: print(&amp;#34;end&amp;#34;) # 0 # 1 try&amp;hellip; else 这个就很好理解了, else 只会在 try 未发生任何异常的时候执行 finally 在所有状态下都会执行 try: 1 except Exception as e: print(e) else: print(&amp;#34;else&amp;#34;) finally: print(&amp;#34;finally&amp;#34;) # else # finally try: 1/0 except Exception as e: print(e) else: print(&amp;#34;else&amp;#34;) finally: print(&amp;#34;finally&amp;#34;) # division by zero # finally </description>
    </item>
    
    <item>
      <title>python 异常处理</title>
      <link>https://blog.twotigers.xyz/posts/python/exception/</link>
      <pubDate>Sat, 09 Oct 2021 20:00:08 +0800</pubDate>
      
      <guid>https://blog.twotigers.xyz/posts/python/exception/</guid>
      <description>异常处理 def demo(): try: 1 / 0 except Exception as e: print(type(e)) #&amp;lt;class &amp;#39;ZeroDivisionError&amp;#39;&amp;gt; 自定义异常 class CustomError(Exception): pass 异常链 class CustomError(Exception): pass def demo(): try: 1 / 0 except Exception as e: print(type(e)) #&amp;lt;class &amp;#39;ZeroDivisionError&amp;#39;&amp;gt; raise CustomError() from e &amp;lt;class &amp;#39;ZeroDivisionError&amp;#39;&amp;gt; Traceback (most recent call last): File &amp;#34;/Users/tiger/work/customer/dd.py&amp;#34;, line 23, in demo 1 / 0 ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): File &amp;#34;/Users/tiger/work/customer/dd.</description>
    </item>
    
  </channel>
</rss>
