Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何仅验证扩展名为.xlsx的文件名?_Python_Excel_Validation_User Interface_Types - Fatal编程技术网

Python 如何仅验证扩展名为.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

我有一个基于Gooey的GUI,用户可以在其中输入在程序结束时创建的输出文件的名称。但是,我希望最后只能够添加扩展名为.xlsx的文件名

这是我的验证器:

 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!'
                                 }
                             })