Skip to content
Advertisement

How to have an incomplete block in Python without error?

This is my code which logically throws error that needs indentation:

elif platform == ‘win32’:
IndentationError: expected an indented block

JavaScript

I need Python to check if OS is whether Linux or Windows, open the file in home of that user and do the same code (in this case for loop) after detecting the OS.

Is there a way to avoid the following way so that I won’t have repeated code?

JavaScript

Advertisement

Answer

Consider assigning a string in a judgment statement:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement