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

I can't figure out why my Python code doesn't run

I tried to run this code but it doesn't work because of the

if __name__ == "__main__" 

statement.

def remember(thing):
    # open file
    with open('database.txt', "a") as file:
        # write thing to file
        file.write(thing+"\n")
        print(thing + ' added')


def show():
    # open file
    with open("database.txt", "r") as file:
        # print out each line of a file
        for line in file:
            print(line)
    pass

if __name__ == "__main___":
    if sys.argv[1].lower() == '--list':
        show()
    else:
        remember(' '.join(sys.argv[1:]))
else:
    print('Something wrong')

1 Answer

Your main has an extra underscore.

if __name__ == "__main___": #should be if __name__ == "__main__":

Thanks :))