1 join
定义
Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
用法
>>> test = ['i','love','you']
>>> ' '.join(test)
'i love you'
>>> '_'.join(test)
'i_love_you'
2 split
定义
Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串
用法
>>> test = 'you…are…so…beautiful'
>>>> test.split()
['you…are…so…beautiful']
>>> test.split('…')
['you', 'are', 'so', 'beautiful']
>>> test.split('…', 0)
['you…are…so…beautiful']
>>> test.split('…', 1)
['you', 'are…so…beautiful']
>>> test.split('…', -1)
['you', 'are', 'so', 'beautiful']
3 date
- fields.Date.to_date(string_value将字符串解析为一个date对象。
- fields.Date.to_string(date_value)将Date对象表示为字符串。
- fields.Date.today()以字符串格式返回当前日期。这适合用于默认值。
- fields.Date.context_today(record,
timestamp)根据记录(或记录集)上下文的时区以字符串格式返回时间戳的日期(或者在省略时间戳时返回当天)。
4 datetime
- fields.Datetime.to_datetime(string_value)将字符串解析为datetime对象。
- fields.Datetime.to_string(datetime_value)将datetime对象表示为字符串。
- fields.Datetime.now()以字符串格式返回当天及当前时间。它适合用作默认值。
- fields.Datetime.context_timestamp(record,
timestamp)将时间戳原生datetime按照记录上下文的时区转化为对应时区。它不适合用作默认值,但是在向外部系统发送数据等操作时可以使用。