擅长:python、mysql、java
<p>这正是创建<a href="https://pypi.org/project/six/" rel="nofollow noreferrer">^{<cd1>}</a>的目的。它是一个允许代码同时使用Python2和3的库。(不要让“library”吓到你,它故意只是一个.py文件,以便非常容易地集成/打包。)</p>
<p>不使用内置的<code>urllib</code>模块,而是使用six的版本,它会自动重定向到python2和3中的内置模块。在</p>
<p>您的代码如下所示:</p>
<pre><code>import xml.etree.ElementTree as ET, gzip, io
from six.moves.urllib.request import urlopen
url = "https://github.com/OpenExoplanetCatalogue/oec_gzip/raw/master/systems.xml.gz"
oec = ET.parse(gzip.GzipFile(fileobj=io.BytesIO(urlopen(url).read())))
</code></pre>
<p>请参见:<a href="https://six.readthedocs.io/#module-six.moves.urllib.request" rel="nofollow noreferrer">https://six.readthedocs.io/#module-six.moves.urllib.request</a></p>