Python 如何仅验证扩展名为.xlsx的文件名?
我有一个基于Gooey的GUI,用户可以在其中输入在程序结束时创建的输出文件的名称。但是,我希望最后只能够添加扩展名为.xlsx的文件名 这是我的验证器:Python 如何仅验证扩展名为.xlsx的文件名?,python,excel,validation,user-interface,types,Python,Excel,Validation,User Interface,Types,我有一个基于Gooey的GUI,用户可以在其中输入在程序结束时创建的输出文件的名称。但是,我希望最后只能够添加扩展名为.xlsx的文件名 这是我的验证器: parser.add_argument('-Choose_File_Name', action='store', help="Output File Name with .xlsx", gooey
parser.add_argument('-Choose_File_Name',
action='store',
help="Output File Name with .xlsx",
gooey_options={
'validator': {
'test': 'str(user_input) == .xlsx',
'message': 'Must contain .xlsx at the end!'
}
})
但是,它为“test”行提供了一个无效的语法错误:“str(用户输入)==.xlsx”Use
str.endswith
Ex:
parser.add_argument('-Choose_File_Name',
action='store',
help="Output File Name with .xlsx",
gooey_options={
'validator': {
'test': 'user_input.endswith(".xlsx") == True',
'message': 'Must contain .xlsx at the end!'
}
})
使用
str.endswith
Ex:
parser.add_argument('-Choose_File_Name',
action='store',
help="Output File Name with .xlsx",
gooey_options={
'validator': {
'test': 'user_input.endswith(".xlsx") == True',
'message': 'Must contain .xlsx at the end!'
}
})