0

Not really sure why this keeps happening, I always use tabs, never use spaces ever. This probably happens about 10 times a day, somehow I manage to get it to work by literally indenting everything 0 then starting through the whole code again. Why does python do this?

Other questions say I'm mixing tabs and spaces but I'm not. I always use tabs, 4 space tabs.

Error:

root@home-linux:~/Desktop# python course.py
  File "course.py", line 48
    print(course_info)
    ^
IndentationError: expected an indented block

Code:

def involved(courses, person):
    involved = []
    for hexamester in courses:
        for course in hexamester:
            for course_info in course:
                print(course_info)
    return involved
Adam G
  • 585
  • 2
  • 7
  • 22
  • Even if it uses spaces then it should run, if you're telling me every indentation line is using spaces? The problem is its saying im mixing them when al I've entered in VS code is tabs. – Adam G Mar 31 '19 at 22:11
  • How does one even check if space is spaces or tabs? Out of curiosity. I'm pretty sure I used tabs, does SO convert to spaces or something? – Adam G Mar 31 '19 at 22:13
  • 1
    You can also [show whitespace right in Visual Studio Code](https://stackoverflow.com/q/30140595/354577) – ChrisGPT was on strike Mar 31 '19 at 22:16
  • 2
    The `print(course_info)` line is indented with spaces, all others with tabs. You should follow PEP 8's guidelines and only use spaces to avoid such problems! – Thierry Lathuille Mar 31 '19 at 22:16
  • @ThierryLathuille, every line in the snippet shared here is indented with spaces. **Edit:** Oh, wait. You're right. Apparently it doesn't preserve tabs when it renders code. That's crazy... – ChrisGPT was on strike Mar 31 '19 at 22:17
  • @Chris No, check it with the [edit](https://stackoverflow.com/posts/55445904/edit) view and try to select the whitespace at the beginning of the line, the difference appears clearly then. – Thierry Lathuille Mar 31 '19 at 22:19
  • @AdamG, apparently I was wrong. If you [edit] your code you can see the tabs. Use the arrow keys. – ChrisGPT was on strike Mar 31 '19 at 22:19
  • I've tried redoing line 48 with tabs and spaces, neither agree to run. – Adam G Mar 31 '19 at 22:21
  • @AdamG, it doesn't really matter what you use but you must be _consistent_. Is your editor converting one to the other on you? (You should configure it to use the correct format. It should be helping you with this, not hindering.) – ChrisGPT was on strike Mar 31 '19 at 22:22
  • I've even tired formatting the document with autopep8 or some other package and it still refuses to run, I'm not sure what else to do. – Adam G Mar 31 '19 at 22:25
  • @ThierryLathuille, Adam, if you haven't already please consider voting on the [bug report discussing tabs rendering as spaces](https://meta.stackoverflow.com/q/319326/354577). It's very misleading for SO to render tabs as spaces. – ChrisGPT was on strike Mar 31 '19 at 22:29

0 Answers0