如何解决“IndentationError:意外缩进”[重复]

问题描述 投票:0回答:1

我正在运行 Kali Linux,需要执行大量命令,但我正在编写一个脚本来真正加快速度。这是 .py 文件:

import os
 
if raw_input("Begin fake Access Point? (y/n): ")=="y":
 os.system(airmon-ng)

interface = input("Enter your Interface name: ")
 os.system(airmon-ng "interface" start)

我在尝试运行它时遇到此错误:

  File "WNS.py", line 7
    os.system(airmon-ng "interface" start)
    ^
IndentationError: unexpected indent

尝试删除开头的空格,但后来我收到此错误:

IndentationError:需要缩进块

python indentation
1个回答
3
投票

缩进在Python中非常重要。解释器使用它来了解如何分隔指令块。os.system() 调用的参数看起来也不太好。无论如何,这就是它应该的样子

import os

if raw_input("Begin fake Access Point? (y/n): ")=="y":
    os.system("airmon-ng")

interface = input("Enter your Interface name: ")
os.system("airmon-ng "+interface+" start")
© www.soinside.com 2019 - 2024. All rights reserved.