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


File "lis.py", line 10 f = open("test.txt", "w+") TabError: inconsistent use of tab

Can someone figure out what is wrong with my below code

I am trying to write the output directory + filename to the test.txt file and it shows Tab Error at f = open("test.txt", "w+") line.

import os import sys

def list(dir): filenames = os.listdir(dir) for filename in filenames: path = os.path.join(dir, filename) print(path) print(os.path.abspath(path)) f = open("test.txt", "w+") f.write(path) f.close()

def main(): list(sys.argv[1])

if name == 'main': main()

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! A TabError means that in some places your code you've indented with spaces and some other places you've indented with tabs. You may not have inconsistent whitespace for indentation as this is mission critical for Python determining what constitutes a block of code. My advice is to go back through your code and indent everything using the same method (either tabs or spaces). Either one will work, but it must be the same on every indentation.

Hope this helps! :sparkles: