Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>import lxml.html as LH doc = LH.parse('http://somesite') </code></pre> <p><code>lxml.html</code> is a module. When you <code>import lxml</code>, the <code>html</code> module is not imported into the <code>lxml</code> namespace. This is a developer's decision. Some packages automatically import some modules, some don't. In this case, you have to do it yourself with <code>import lxml.html</code>.</p> <p><code>import lxml.html as LH</code> imports the <code>html</code> module and binds it to the name <code>LH</code> in the current module's namespace. So you can access the parse function with <code>LH.parse</code>.</p> <hr> <p>If you want to delve deeper into when a package (like <code>lxml</code>) imports modules (like <code>lxml.html</code>) automatically, open a terminal and type</p> <pre><code>In [16]: import lxml In [17]: lxml Out[17]: &lt;module 'lxml' from '/usr/lib/python2.7/dist-packages/lxml/__init__.pyc'&gt; </code></pre> <p>Here is you see the path to the <code>lxml</code> package's <code>__init__.py</code> file. If you look at the contents you find it is empty. So no submodules are imported. If you look in numpy's <code>__init__.py</code>, you see lots of code, amongst which is </p> <pre><code>import linalg import fft import polynomial import random import ctypeslib import ma </code></pre> <p>These are all submodules which are imported into the <code>numpy</code> namespace. So from a user's perspective, <code>import numpy</code> automatically gives you access to <code>numpy.linalg</code>, <code>numpy.fft</code>, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload