Neat way of making urllib work with python 2 and 3
Question: I'm looking for suggestions on how to combine the two code snippets so that
they work with both python 2 and 3. The goal is to make it "neat", ideally
keeping it to one line and limiting any if/else/try/except constructs.

For python 3.x

    
    
       import xml.etree.ElementTree as ET, urllib.request, gzip, io
       url = "https://github.com/OpenExoplanetCatalogue/oec_gzip/raw/master/systems.xml.gz"
       oec = ET.parse(gzip.GzipFile(fileobj=io.BytesIO(urllib.request.urlopen(url).read())))
    

For python 2.x

    
    
      import xml.etree.ElementTree as ET, urllib, gzip, io
      url = "https://github.com/OpenExoplanetCatalogue/oec_gzip/raw/master/systems.xml.gz"
      oec = ET.parse(gzip.GzipFile(fileobj=io.BytesIO(urllib.urlopen(url).read())))
    


Answer: This is exactly what [`six`](https://pythonhosted.org/six/) was created for.
It's a library designed to allow your code to work with both Python 2 and 3.
(Don't let "library" scare you, it's intentionally just a single .py file to
make it very easy to integrate/package.)

Instead of using the built-in `urllib` module, you'd use six's version which
automatically redirects to the built-in module in both Python 2 and 3.

Here's what your code would look like:

    
    
    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())))
    

See: <https://pythonhosted.org/six/#module-six.moves.urllib.request>

