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 trialjames white
78,399 PointsUsing Databases in Python Meet PeeWee First Queries Challenge
Challenge link:
http://teamtreehouse.com/library/using-databases-in-python/meet-peewee/first-queries
Challenge Task 1 of 4
Import the Challenge class from models.py.
So I tried this 'from...import' line of code:
#!/usr/bin/env python3
from models.py import Challenge
Got this error:
Bummer! ImportError: No module named 'models.py'; 'models' is not a package
I also tried :
import models class Challenge
(based on some code I found inside Google Books for a Django book).
Of course it errored out as well. But I got a different error (making progress...)
Bummer! SyntaxError: import models class Challenge
Here's another try:
import models.py class Challenge
..gives error:
Bummer! SyntaxError: import models.py class Challenge
with output:
Variable Value
package None
doc None
loader <frozen_importlib.SourceFileLoader object at 0x7fce7ba71a58>
__cached_ None
name main
sys
spec None
warningregistry {("unclosed file <_io.TextIOWrapper name='queries.py' mode='r' encoding='UTF-8'>", , 17): True, ("unclosed file <_io.TextIOWrapper name='/srv/code_challenges/releases/20150127184100/lib/challenge_engine/templates/python.html.erb' mode='r' encoding='UTF-8'>", , 80): True}
Are we having fun, yet?
Oh, here's an interesting one:
#!/usr/bin/env python3
import models
..gives this error:
Bummer! name 'Challenge' is not defined
which means that the import statement is not giving an error,
but the challenge engine is seems to be saying that some code
involving 'Challenge' is missing
(at least that's my interpretation of the error message).
Hmmmm...more research needed...
Found this StackOverFlow thread; http://stackoverflow.com/questions/3842616/organizing-python-classes-in-modules-and-or-packages
So maybe the line of code should be:
from models import Challenge
Success!
The challenge engine like me again!
(..and of course being liked by the Treehouse Challenge engine
is the penultimate thing to strive for
beyond everything else in you life. )
2 Answers
Kenneth Love
Treehouse Guest TeacherYeah, that import is (structurally) exactly like the imports we did through a lot of Object Oriented Python. Glad you figured it out!
Chipo Makawa
5,919 Pointsfrom models import Challenge