why am i getting this error --> ( IndentationError: unexpected unindent )?
why am i getting this error --> ( IndentationError: unexpected unindent )?
编辑:这是全部代码https://pastebin.com/Njp9AsP4
这是给我错误的代码:
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
这是错误:
[Running] python -u "d:\python\memopad v1.py"
File "d:\python\memopad v1.py", line 51
def save_file_as():
^
IndentationError: unexpected unindent
我首先尝试用谷歌搜索它,但只能找到遗漏例外的人:第 行不是我的问题。
然后我尝试删除 try: 和 except: 令我惊讶的是错误仍然存在。
现在是凌晨 2 点,我决定创建一个 Whosebug 帐户,看看这里是否有人可以提供帮助。
其他信息:(我正在使用 python3.8.3)(我正在使用 windows 10)(我正在使用 vscode)(我对编程很感兴趣)
出现这个错误的原因是你没有关闭前面代码中的try语句 现在试试这个
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
编辑:这是全部代码https://pastebin.com/Njp9AsP4
这是给我错误的代码:
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
这是错误:
[Running] python -u "d:\python\memopad v1.py"
File "d:\python\memopad v1.py", line 51
def save_file_as():
^
IndentationError: unexpected unindent
我首先尝试用谷歌搜索它,但只能找到遗漏例外的人:第 行不是我的问题。
然后我尝试删除 try: 和 except: 令我惊讶的是错误仍然存在。
现在是凌晨 2 点,我决定创建一个 Whosebug 帐户,看看这里是否有人可以提供帮助。
其他信息:(我正在使用 python3.8.3)(我正在使用 windows 10)(我正在使用 vscode)(我对编程很感兴趣)
出现这个错误的原因是你没有关闭前面代码中的try语句 现在试试这个
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