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 :)