简体   繁体   中英

Unexpected Unindent Error in Python

So I've been set the task to load a file for an encryption program I'm working on, but I'm getting an error stating that the console has came across an Unexpected unindent , yet I have no idea where it is! I've assumed it is a glitch, tried rewriting the code, yet still I've been getting the same error! I'm an amateur coder, can anyone please help me out?

This is part of the code I'm having trouble with:

def loadFile():
    try:
        aFile = input('Plese enter a filename: \n')
        myFile = open(aFile, 'r+')
        global myFile
        try:
            print('Gathering file information...')
            time.sleep(1)
            print('The string you have chosen to encrypt is:')
            print(myFile.read())
        finally:
            myFile.close()
    except IOError:
        print('The file does not exist \n')
        loadFile()

you can use this command -

 perl -i.bak -pe "s/\\t/' 'x(8-pos()%8)/eg" file.py 

here file.py is your file name. 8 is the tab indent which you would have configured in your editor. Basically this error comes up with mismatch between tabs and spaces. So this command will convert all tabs with spaces. Hope this works :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM