Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
James Ball2,074 Points
Import from characters vs. import from characters.py
Why does "from characters import Thief" work but not "from characters.py import Thief"? Why do you not have to specify the filename extension when importing?
Here is a detailed explanation of importing in Python.
Importing uses dotted paths to navigate directories so
characters.py would specify a file named
py.py in a
characters directory. I put together a workspace to demonstrate. To use enter
python test.py in the console. There are comments for each of 4 tests in test.py.
I'm still testing myself (like what happens with a file named characters.py.py, or if there is directory and file with the same name in the same directory) so I may add more later.