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

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

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

Hi guys, i need some help here, i don't know what to do, can someone submit the code? Thanks!

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

7 Answers

Michael Norman
PLUS
Michael Norman
Courses Plus Student 9,399 Points

You should format the code to comply with pep 8 recommendations. Please check out this link for reference PEP 8

Hello,

You're very close. When putting in your code, I obtain the bummer message, "Your file has 1 error(s) on line(s) 14: no newline at end of file." So if you follow that and add a newline at the end of the file, you should get closer to completing the Challenge, which further bummer messages should get you even closer if you get any.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Hi James, which file do you mean the line after "return self.args" ?

I tried lots of options but still need help.

Thanks in advance!

By file, the bummer message just means your actual code for the code challenge. Like how this Code Challenge has a tag for one file, starter.py. So all the bummer message is referring to is that you need a newline at the end of your code to comply with PEP 8.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

I am adding a new line at the end, but it alerts me as "trailing white space"

That bummer means that the newline needs to be empty. The code challenge by default will make it indent to the same as your previous line. So you'll have to delete the extra spaces to clear out that condition. I would also recommend reading through the PEP 8 conventions posted earlier.

Sean T. Unwin
Sean T. Unwin
28,690 Points

Ensure each newline is empty, i.e. no spaces or tabs, and also that there is an empty newline at the end. Definately check out the PEP 8 style guide that Michael Norman linked to.

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