我有一个基于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(user_input)== .xlsx'
采用 str.endswith
例如:
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!'
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句