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 Python Collections (2016, retired 2019) Lists Shopping List Take Three

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

How do you safely copy and paste python to avoid whitespace problems?

I took the code out of the Project Files downloads, opened up shopping_list_3.py in Sublime, then pasted it into Workspaces. I did some more coding in Workspaces, and then I tried running to code in the workspaces terminal and got this error:

IndentationError: unindent does not match any outer indentation level 

I fixed it by copying my workspaces code back into Sublime and then back again, but this is a weird hack and I don't understand the problem. In Sublime I have "Spaces: 4", and in Workspaces I have "Tab Size: 4". Is that the same thing? It seems like it's telling me I'm not being consistent but I don't understand how I'm not.

1 Answer

Steven Parker
Steven Parker
229,788 Points

:point_right: You should not mix spaces and tabs in Python.

Python will work with either spaces or tabs, but to avoid problems you should be consistent about which you use. I find spaces are the most portable and prefer them for that reason. I also set the indent to 4, partly as a personal preference but it also seems to be a very popular setting.