0

edit:this is the whole code https://pastebin.com/Njp9AsP4

this is the code that gives me the error:

def save_file_as():
'''Save new file or save existing file with another name'''
filename = sg.popup_get_file('Save As', save_as=True, no_window=True)
try:
    if filename:
        file = pathlib.Path(filepath)
        file.write_text(values.get('_BODY_'))
        filename = filepath.split('/')
        window.TKroot.title(filename[-1] + '- memopad')
        return file
except:
    pass

and this is the error:

[Running] python -u "d:\python\memopad v1.py"
  File "d:\python\memopad v1.py", line 51
    def save_file_as():
    ^
IndentationError: unexpected unindent

i first tried googleing it but could only find people who left out the except: line witch is not my problem.

then i tried removing the try: and except: and to my surprise the error remains.

so its 2AM rn and i decided to make a stackoverflow account to see if anyone here could help.

other info: (im using python3.8.3)(im using windows 10)(im using vscode)(and im a nube to programing)

bruh nye
  • 39
  • 6
  • 1
    Show us the code that preceded that — lines 1-50 – Chris Johnson Jun 28 '20 at 01:41
  • Python cares about how you have code indented. White space matters. Where as a lot of other programs just use ( ) or { } to define subroutines. You probably just have a whole section indented too much (or not enough). I would suggest taking a quick python intro class, like on code academy to just learn those few basics. Good luck! – sniperd Jun 28 '20 at 01:47
  • @sniperd im 99% sure it is all indented correctly i have rewritten it over and over the 1% only comes from the fact the error says "IndentationError" – bruh nye Jun 28 '20 at 01:50
  • Have mixed tabs and spaces in your source file? That will trip you up. Try a global expansion of tabs into spaces.... – dawg Jun 28 '20 at 01:57
  • 1
    You think it's indented correctly. Python thinks it's not. I'm going to go with Python's judgment. – user2357112 Jun 28 '20 at 01:59
  • @user2357112supportsMonica ik thats whats tripping me up tho iv tried as much as i could to fix it but python wont agree – bruh nye Jun 28 '20 at 02:02
  • oh for - "i first tried googleing it but could only find people who left out the except: line witch is not my problem". Look at the previous function. Does it look like it's missing something? An `except`, perhaps? – user2357112 Jun 28 '20 at 02:03
  • As somebody else said, if you are mixing tabs and spaces, that will cause a problem. Or if you use 4 spaces, and sometimes 2 spaces, that will cause a problem. The indent problem probably isn't that code you posted, it is probably the section above. It is an indent problem, not a try/except issue, you'd get a different error. – sniperd Jun 28 '20 at 02:04
  • Just accept the answer below, make sure to upvote him – sniperd Jun 28 '20 at 02:09

1 Answers1

1

The reason for this error is that you didn't close the try statement in the previous code try this now

def save_file(file):
    '''Save file instantly if already open; otherwise use `save-as` popup'''
    try:
        if file:
            file.write_text(values.get('_BODY_'))
        else:
            save_file_as()
    except:
        pass  
 
def save_file_as():
    '''Save new file or save existing file with another name'''
    filename = sg.popup_get_file('Save As', save_as=True, no_window=True)
    try:
        if filename:
            file = pathlib.Path(filepath)
            file.write_text(values.get('_BODY_'))
            filename = filepath.split('/')
            window.TKroot.title(filename[-1] + '- memopad')
            return file
    except:
        pass            
A_K
  • 731
  • 3
  • 15
  • 40