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 trialRoutine Poutine
26,050 PointsDo Python and JavaScript reverse the order of syntax when importing modules?
Hi,
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.
Thanks,
Matt
1 Answer
Michael Hulet
47,913 PointsYou can import
things in 2 ways with Python. First of all, let's say we have this file:
def one():
print("This")
def two():
print("That")
Now, if we have another Python file, we can use the code in that file like this:
import module
module.one()
module.two()
Alternatively, we could use it like this:
from module import one
from module import two
one()
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