看python写的源码,很多不知道类型到底是什么,亦不知道该调用什么方法,常用方法的返回值也不知道是什么类型,中文处理相当不好,乱码十分严重,为什么还有人推荐?
<code class="language-python"><span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">foo</span><span class="p">:</span> <span class="n">Foo</span><span class="p">)</span> <span class="o">-></span> <span class="n">Bar</span><span class="p">:</span> <span class="n">Bar</span><span class="p">(</span><span class="n">foo</span><span class="p">)</span> </code>
<code class="language-python"><span class="c"># 尝试将字符串转成utf-8的,如果失败转为gbk的</span> <span class="k">try</span><span class="p">:</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span> <span class="k">except</span> <span class="ne">UnicodeEncodeError</span><span class="p">:</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'gbk'</span><span class="p">,</span> <span class="s">'ignore'</span><span class="p">)</span> </code>
<code class="language-python"><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="k">print</span> <span class="p">(</span><span class="n">g</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span> </code>