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 Write Better Python Cleaner Code Imports

Daniel Lounsbury
Daniel Lounsbury
1,744 Points

I can't find what I am getting wrong here on my import list

I'm not sure what i am missing but I think it has to do with the "import from re" they didn't cove that on the videos and instead of an error msg I just get "BUMMER: Try Again" which to be honest is the dumbest error msg as it doesn't point out whats wrong, or where to look. I need assistance not comments from a "surfer dude" It's a bummer this error msg is no help

starter.py
import os
import sys
import logging
import from re
import match
import search

Did you mean:

import re

The keyword 'from' always comes first and you would only use it like so:

from re import sub
Daniel Lounsbury
Daniel Lounsbury
1,744 Points

bellow is my latest attempt, when I checked it, the error msg was that there was 1 error about no line at the end, so I add one and now the error msg is just "Bummer" so frustrating.

import os
import sys
import logging
from re import match
import search

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

To the docs!

https://legacy.python.org/dev/peps/pep-0008/#imports

Should be pretty clear what you're doing wrong here. You're very close!

I recommend you reset the code, because you are no longer importing the same things as in the original example.

Daniel Lounsbury
Daniel Lounsbury
1,744 Points

I read through the doc attachment but still am at a loss. Can you please clarify. The "BUMMER" msg combined with no mention of this in the vid that I can remember seeing are not very helpful. I read through the doc and the example from the doc gives the example as "from myclass import MyClass" Please help me by directly pointing out the error because I can't fix what i don't know is wrong

Greg Kaleka
Greg Kaleka
39,021 Points

I agree the bummer message isn't helpful.

In the documentation I linked to, you only need to look at the first bullet of the imports section. I'm copy/pasting just that section for you:


Imports

  • Imports should usually be on separate lines, e.g.:
Yes: import os
     import sys

No:  import sys, os

It's okay to say this though:

from subprocess import Popen, PIPE

For the challenge, let's start over. Here's the initial code:

import os, sys, logging
from re import match, search

There are two lines of code here. Evaluate them separately based on the documentation.

Is the first line OK? If so, don't change it. If not, replace it with one or more lines that are correct.

Is the second line OK? If so, don't change it. If not, replace it with one or more lines that are correct.

Daniel Lounsbury
Daniel Lounsbury
1,744 Points

Thank you Greg. I appreciate your help. I finally got it with your help and patience. I don't feel that this topic was discussed in a way that the answer would be intuitive and that the error msg "BUMMER" needs to go away. If something is wrong, At least give me the line that is wrong

Greg Kaleka
Greg Kaleka
39,021 Points

Glad you figured it out!

Totally agree that Kenneth could have done some more work on error messages for this challenge. In a "real world" programming environment you would have gotten an error like Cannot import module search, which would have helped a bit.

Debugging code can be frustrating like this sometimes, though - you won't always have a clear error message. Doing things like going back to square one, breaking down the problem, and reading documentation will help get you through. Posting here, and (later in your learning) on sites like Stack Overflow can also help.

Stick with it, and keep posting here when you run into things like this :blush:.

here is my answer

from os import sys import logging from re import match from re import search