[Python] How is import os.path possible?

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    Since os is a module instead of a package, import os.path should fail. For comparison:

    >>> import os.sys
    Traceback (most recent call last):
    File "<python-input-0>", line 1, in <module>
    import os.sys
    ModuleNotFoundError: No module named 'os.sys'; 'os' is not a package


    Note that os.sys is available:

    >>> import os
    >>> os.sys
    <module 'sys' (built-in)>


    So, how does import os.path work? Are there any other cases of something like this?

    Continue reading...

Compartilhe esta Página