方便的数据输入和验证。
easyentr的Python项目详细描述
概述
easyentry将数据输入程序并轻松检查它们是否有效。
使用字典定义数据的属性:
- type:str、int、float、date、time、email、passwd和menu。
- default:按回车键设置默认值
- options:定义允许值的列表:['a','b',…] <值:设置一个值的最小和最大限制:[ 0, 100 ] < >
- required:定义是否引入值的义务:true或false
- 以及其他(参见属性列表)。
示例:
import easyentry as ee ee.global_required = True person = {} person['name'] = {'type':'str'} person['city'] = {'type':'str', 'default':'Seville'} person['age'] = {'type':'int', 'minmax': [0,100]} person['height'] = {'type':'float'} person['bicycle'] = {'type':'str', 'options': ['y','n']} person['datetrip'] = {'type':'date', 'default': 'now'} person['email'] = {'type':'email', 'required': False} name = ee.entry('What is your name?', (person, 'name')) city = ee.entry('What city you live?', (person, 'city')) age = ee.entry('How old are you?', (person, 'age')) height = ee.entry('Height?', (person, 'height')) bicycle = ee.entry('Do you have a bicycle?', (person, 'bicycle')) datetrip = ee.entry('Date of trip?', (person, 'datetrip')) email = ee.entry('Your email address', (person, 'email'))
密码
输入密码:
person['passwd'] = {'type':'passwd'} passwd = ee.entry('Enter password', (person, 'passwd')) repeat = ee.entry('Repeat password', (person, 'passwd')) if passwd == repeat: print(passwd)
属性列表
可用数据类型的属性:
- str:必需,options或minmax和default
- int:必需,options或minmax和default
- float:必需,options或minmax和default
- date:必需,选项或mixmax,默认值:date或now
- time:必需,选项或mixmax,默认值:time或now
- 密码:必需的
- email:必需的
- menu:必需,标题,选项,默认值,排序和索引
常数
常数用于设置定义easyentry的一般行为的值:
# Message to be displayed when data is not valid: # - You can type the message in your language # - If the value is omitted, the default is the current (in English) ee.error_message = 'Invalid input, please try again' # Set format 'date' and 'time': # - Date format: '%Y-%m-%d' -> YYYY-MM-DD (default) # - Hour format: '%H:%M:%S' -> HH:MM:SS (default) ee.date_format = '%d-%m-%Y' ee.time_format = '%H:%M' # Set the type of numerical data (int and float): # - True and value = '' : var int -> return 0 # var float -> return 0.0 # - False (default) and value = '': return '' ee.strict_return = False # Establish whether it is mandatory to enter a valid value or # an empty entry (press return) is allowed # - True -> You must enter a valid value in all fields # - False -> The field can be empty (default) # The value of the 'required' property of a field overrides # the global value ee.global_required = True