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 trialStephen Cole
Courses Plus Student 15,809 PointsWhy do I have to import the specific modules after importing openpyxl? Doesn't the initial import get all functions?
import openpyxl
from openpyxl import Workbook
from openpyxl.writer.excel import ExcelWriter
from openpyxl.cell import get_column_letter
In the above, are the other imports after the initial import even necessary?
I know you can import a function as a name to shorten it but this seems redundantly redundant.
1 Answer
Greg Kaleka
39,021 PointsIt really is to shorten your code later on. This way, you don't need to write openpyxl.writer.excel.ExcelWriter every time you need that class. I could be wrong, but I believe python compiler is smart enough to not import multiple copies of the same class files, so you're not losing anything by doing this other than having a couple extra import statements at the top of your file. It's just for convenience.