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

Charles Harpke
Charles Harpke
33,986 Points

Add the correct amount of whitespace between the functions, between the functions and the class, and before the class me

ERROR: Your file has 4 error(s) on line(s) 8, 10, 12, 14: blank line contains whitespace; no newline at end of file.

What is the relevance of 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
starter.py
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
Tomer Inbar
Tomer Inbar
2,248 Points

I am getting "Bummer! Your file has 1 error(s) on line(s) 13: no newline at end of file."

but I don't have any(at least none that I could find). I made sure that the s of .args is the last char, nothing more to delete. any ideas? Kenneth Love

9 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You shouldn't have whitespace (spaces, tabs, etc) on blank lines. They should be nothing but the newline control character. Since Python uses whitespace to determine scope/namespacing, having whitespace on blank lines can confuse the interpreter.

Charles Harpke
Charles Harpke
33,986 Points

Thank you.....took me a few seconds to wrap my head around that. :)

the below code works if you get this "no newline at end of file." just click on the enter button and add one new line at the end of the code.

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

Why am I so slow at these damned challenges!

Bummer! Your file has 2 error(s) on line(s) 11, 14: blank line contains whitespace; trailing whitespace.: on the same challenge am facing this problem am falling to understand what it is?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Blank lines should be completely blank, this means no tabs or spaces on them. And you shouldn't have extra spaces/tabs on the end of lines.

This code passed but doesn't show up correct when I paste it. Instructions:

**be careful to erase all white space from any new lines**

After the first function 2 blank lines After the second function 2 blank lines One blank line after MyClass One blank line after args One blank line after the return statement of class_func(self)

Properly indent all returns by just pressing enter after each function.

Indent args & the function class_func(self) by pressing tab once

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

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

I'm much too slow at this!!!! 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

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

def second_function(args1): return 'args is{}'.format(args1) class MyClass:

    args =[1, 2, 3]

  def class_func(self):
      return self.args

Still I get bummer what's wrong with this code.

This was the toughest one yet. Make sure to delete the tab in your new line at the end.