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

Python

Python import issues

I am at university and I have come into contact with a technology I would now consider myself quite familiar with, Flask. In the module however there is an issue it seems all students are encountering and I am of the mind that this is a mistake.

We are being told to import a file from a directory as such:

from app import app

With a directory named app and a file named app.

My understanding of imports in python was:

from file import Class

Am I wrong here? Or am I misunderstanding?

1 Answer

Hi Josh,

Python's imports can be confusing, not least because you can import various different entities using essentially the same syntax. You can import variables, functions, classes, modules and packages, and it's not always obvious just by looking at an import statement what level of entity is being imported.

In the specific case of Flask, the situation is that flask (lowercase) is a package, and Flask (titlecase) is a class. So you are importing the Flask class from the flask package. This is very similar to your experience, except that we are importing from a package (which in this case is a collection of a files) instead of from a single file.

Hope that clears things up,

Cheers

Alex