Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[newbie] Why is a module imported twice? #228

Open
Shohreh opened this issue Apr 1, 2021 · 1 comment
Open

[newbie] Why is a module imported twice? #228

Shohreh opened this issue Apr 1, 2021 · 1 comment

Comments

@Shohreh
Copy link

Shohreh commented Apr 1, 2021

Hello,

It's a newbie question: Why is the module imported twice?

import gpxpy
import gpxpy.gpx

https://pypi.org/project/gpxpy/

Thank you.

@MinchinWeb
Copy link
Contributor

Hi @Shohreh!

This has to do with the way Python importing works. When you import a module (such as gpxpy), it does not provide access to submodules (such as gpxpy.gpx) unless they are explicitly imported by the main module (which they aren't here).

One way to see this is to start the Python REPL at the command line (if you run just python, you'll probably be there), and try the following:

> import gpxpy
> dir(gpxpy)

The dir command will list everything in the supplied namespace. You'll see lots of things listed, but not gpx (the submodule).

Perhaps part of the confusion is that many library authors will import the submodules into the main module (or at least the ones meant to be public) as a convince, but as shown here, it isn't a requirement.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants