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 trialLuke Tate
Courses Plus Student 2,256 PointsWhat does the from mean for functions?
"""
This is importing a function named `tweet` from a file
that we unfortunately don't have access to change.
You use it like so:
>>> tweet("Hello this is my tweet")
If the function cannot connect to Twitter,
the function will raise a `CommunicationError`
If the message is too long,
the function will raise a `MessageTooLongError`
"""
from twitter import (
tweet,
MessageTooLongError,
CommunicationError,
)
message = input("What would you like to tweet? ")
# Your code here
4 Answers
Rick Gleitz
47,878 PointsYou are importing the tweet, MessageTooLongError, and CommunicationError functions from the twitter library. There are LOTS of libraries in python from which you can import either the whole library, or just specific functions like these. I heard in an older podcast that there are over 90,000 libraries available! The purpose is that these libraries let you access code that someone else has written so you don't have to recreate the wheel. Hope this helps!
Luke Tate
Courses Plus Student 2,256 Pointsso is "from" a module?
Rick Gleitz
47,878 PointsTyping in the "from twitter import" statement, "from ... import" allows you to import specific elements such as functions or attributes of a library, module, or API (like twitter). The word from is a keyword in python used for this purpose, as is import. I hope this makes it more clear. There are a lot of jargony terms, some of which aren't obvious. They have specific meanings, but they often tend to be muddled together (at least in my mind). I hope I've done them justice.
Check these links for further info (they helped me clarify my thoughts here): https://www.programiz.com/python-programming/modules https://www.programiz.com/python-programming/keyword-list#from_import
Luke Tate
Courses Plus Student 2,256 PointsThanks for clearing this up!
Rick Gleitz
47,878 PointsYou're welcome!