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 Function and Class Whitespace

Blair Murphy
Blair Murphy
12,367 Points

Add the correct amount of whitespace between the functions/methods...

Not sure where I'm getting "5 error(s) on line(s) 8,10,4,12,14: no new line at end of file; blank line contains whitespace"

def first_function(arg1):
    return 'arg1 is {}'.format(arg1)


def second_function(arg1):
    return 'arg1 is {}'.format(arg1)


class MyClass:

    args = [1, 2, 3]

    def class_func(self):
        return self.args

[MOD: added ```python formating -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

It's not obvious but It's exactly like the error says: "5 error(s) on line(s) 8,10,4,12,14: no new line"

  • line(s) 8,10,4,12: The blank lines contains spaces which is the same as "trailing spaces"
  • 14: no new line: put the cursor after the last character and hit <Enter> so that the last line off code is followed by an End-of-Line character

Then you're good to go!

Blair Murphy
Blair Murphy
12,367 Points

Thanks! Completely overlooked the whitespace(s) in the blank lines.