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 Using Databases in Python Meet Peewee Create Table

Welby Obeng
Welby Obeng
20,340 Points

difference between import peewee and from peewee import *?

what is the difference between import peewee and from peewee import *?

tables.py
from

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

If you import mymodule, you get the whole module, and have to make all references to it by typing like

mymodule.myfunction()

If you use from mymodule import myfunction you can call it directly in your script

myfunction()

It's a namespace thing, really. Plus in one example you're only importing the function you need, instead of the entire module, which you might not want.

Gavin Ralston
Gavin Ralston
28,770 Points

So in the example

from module import *

You're saying "give me everything, and don't worry about functions in this module clashing with anything I've written or imported from elsewhere. Then you can type the function names without using the namespace.