join_mark

 

python format自定义格式化

# #自定义格式化
# format_dic={
# 'ymd':'{0.year}{0.mon}{0.day}',
# 'm-d-y':'{0.mon}-{0.day}-{0.year}',
# 'y:m:d':'{0.year}:{0.mon}:{0.day}'
#
# }
#
# class Date:
# def __init__(self,year,mon,day):
# self.year=year
# self.mon=mon
# self.day=day
#
# def __format__(self, format_spec):
# print('执行了')
# print('-->',format_spec)
# if not format_spec or format_spec not in format_dic:
# format_spec='ymd'
# fm=format_dic[format_spec]
# return fm.format(self)
# d1=Date(2018,7,26)
# # format(d1)
# print(format(d1,'m-d-y'))
# print(format(d1,'y:m:d'))
# print(format(d1,'m-d--y'))
# print(format(d1))

posted on 2018-07-26 22:37  join_mark  阅读(604)  评论(0)    收藏  举报

导航