Python SyntaxError: invalid syntax elif statement
Question: So I am pretty new to python, I am familiar with Java, C and Ruby.

I tried compiling a script for Kali to fix the RFkill issue for wifi devices
since Kali does not have an RFKill.

    
    
    #!/usr/bin/python
    # replacement for rfkill util, which is missing in kali
    # By: Geist
    
    from sys import argv
    
    if(argv[1] == "unblock"):
        x = open("/sys/class/rfkill/rfkill%s/soft" % argv[2], "w")
    x.seek(0)
    x.write('0')
    
    elif(argv[1] == "block"):
        x = open("/sys/class/rfkill/rfkill%s/soft" % argv[2], "w")
    x.seek(0)
    x.write('1')
    
    
    print("interface %s %sed" % (argv[2], argv[1]))
    

I did not write this but I am trying to run it and I keep getting a
SyntaxError: invalid syntax under elif(argv[1] == "block"):

I am assuming this has something to do with improper indentation, if anyone
could be as kind to let me know what I am doing wrong and why that would be
great!


Answer: **Indentation matters in Python**. You have unindented lines between your `if`
block and your `elif` block. These will cause a SyntaxError because you've
effectively got an `elif` block _without an`if` block._

Either indent your lines so they match the `if` block, or use a second `if`
statement rather than `elif`. Looking at your code, I'd imagine you'll want to
indent them otherwise you would get NameErrors. In this case it becomes:

    
    
    #!/usr/bin/python
    # replacement for rfkill util, which is missing in kali
    # By: Geist
    
    from sys import argv
    
    if(argv[1] == "unblock"):
        x = open("/sys/class/rfkill/rfkill%s/soft" % argv[2], "w")
        x.seek(0)
        x.write('0')
    
    elif(argv[1] == "block"):
        x = open("/sys/class/rfkill/rfkill%s/soft" % argv[2], "w")
        x.seek(0)
        x.write('1')
    
    
    print("interface %s %sed" % (argv[2], argv[1]))
    

