Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Machine Learning Machine Learning Basics Writing a Classifier Loading a Dataset

Routine Poutine
Routine Poutine
26,038 Points

Do Python and JavaScript reverse the order of syntax when importing modules?


This video seems to indicate that Python's syntax is: from x import y

This is different from what I'm used to in JavaScript, where: import X from 'y'

Am I write about the same words, but different order here? Python and ECMA2015.



1 Answer

Michael Hulet
Michael Hulet
47,843 Points

You can import things in 2 ways with Python. First of all, let's say we have this file:

def one():

def two():

Now, if we have another Python file, we can use the code in that file like this:

import module


Alternatively, we could use it like this:

from module import one
from module import two


Notice that when we do it the first way, with just the import statement, it imports everything in that file, and we can access individual things in that file by writing filename.some_symbol. In the 2nd way, it pulls the individual things into your current namespace, as if you wrote them in that file itself. This style is the only way you can do it in ES2015 JavaScript, so that's probably what you're more used to from that world