缩进错误 python 2.7

indentation Error python 2.7

您好,我在 python 2.7
上遇到缩进错误 我的程序看起来像这样: 导入:
import sys, os import subprocess from threading import Thread from re import split

实际代码:
def GetProcesses(Clean=True): # if Clean == True: # # x = subprocess.Popen(["sudo", "ps", "aux"], stdout=subprocess.PIPE, shell=True) (out, err) = x.communicate() print(out) print(out.split("\n")) print("--------------") Processes = out.split("\n") print(Processes) print("------") print(Processes[0]) print("----------") Header = Processes[0] Process_list = Processes.remove(Processes[0]) return((Header, Process_list)) # else: # # if Clean == True: #added problem so future SE users can see it x = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE, shell=True) (out, err) = x.communicate() return(out)

我不理解这个错误,我已经尝试去除每一行 1 space 的凹痕,缩进到原来的位置,然后添加 1 space 但它总是说它要么需要一个缩进, 或意外的缩进。 P.S 我只使用 spaces.

实际错误:
File "MemoryHandling.py", line 31 x = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE, shell=True) ^ IndentationError: expected an indented block


在问这个问题期间和之前,我已经在线检查了几个 questions/sources(主要是 SE)是否存在此错误(如下),我发现它们是针对具体情况的,否决/未回答,或者没有用:
-- Python Indentation Error # 我正在使用 spaces
-- Python 2.7 Indentation error # 我已经多次手动检查缩进,并尝试使用 tab 键
-- # 再次不使用制表符和 spaces
-- Code Indent Error, code is indented? # 未回答(错误?)
-- # 再次不使用制表符和 spaces

import sys, os
import subprocess
from threading import Thread
from re import split

#Actual Code:
def GetProcesses(Clean):
    #
    if Clean == True:
        #
        #
        x = subprocess.Popen(["sudo", "ps", "aux"], stdout=subprocess.PIPE, shell=True)
        (out, err) = x.communicate()
        print(out)
        print(out.split("\n"))
        print("--------------")
        Processes = out.split("\n")
        print(Processes)
        print("------")
        print(Processes[0])
        print("----------")
        Header = Processes[0]
        Process_list = Processes.remove(Processes[0])
        return((Header, Process_list))
    #
    else:
        #
        #
        x = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE, shell=True)
        (out, err) = x.communicate()
        return(out)

问题就在这里。在 if 部分之后,没有提供缩进。

else:
    if Clean == True: #added problem so future SE users can see it
        x = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE, shell=True)
        (out, err) = x.communicate()
        return(out)