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

Update 30-modules-and-imports.md #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Let's put our function in a file called `__init__.py` and place it in a folder c

### Best Practices

There a few different ways to import modules or even just specific objects from modules. You can import *everything* from a module into the local namespace using `*`:
There are a few different ways to import modules or even just specific objects from modules. You can import *everything* from a module into the local namespace using `*`:

```python
>>> from my_math_functions import *
Expand Down Expand Up @@ -68,4 +68,4 @@ You can use the `as` keyword to make things a little easier on yourself.

### PYTHONPATH

What is the `PYTHONPATH` we mentioned earlier? This is a list of paths on your system where Python will look for packages. Python will always look first in the working directory (the folder you're in when you start the REPL or run your program), so if your module folder is there, you can import it. You can also install your modules just like any other external modules, using a `setup.py` file. It's also possible to change or add paths to your `PYTHONPATH` list if you need to store modules elsewhere, but this isn't a very portable solution.
What is the `PYTHONPATH` we mentioned earlier? This is a list of paths on your system where Python will look for packages. Python will always look first in the working directory (the folder you're in when you start the REPL or run your program), so if your module folder is there, you can import it. You can also install your modules just like any other external modules, using a `setup.py` file. It's also possible to change or add paths to your `PYTHONPATH` list if you need to store modules elsewhere, but this isn't a very portable solution.