1
periodsList = []
su = '0:'
Su = []
sun = []
SUN = ''
我通过转换Python函数返回错误值
extendedPeriods = ['0: 1200 - 1500',
'0: 1800 - 2330',
'2: 1200 - 1500',
'2: 1800 - 2330',
'3: 1200 - 1500',
'3: 1800 - 2330',
'4: 1200 - 1500',
'4: 1800 - 2330',
'5: 1200 - 1500',
'5: 1800 - 2330',
'6: 1200 - 1500',
'6: 1800 - 2330']
为'1200 - 1500/1800 - 2330'
- 苏在格式化时间表是一天标识
- 苏,阳光店的一些值
SUN存储转换时间表
for line in extendedPeriods: if su in line: Su.append(line) for item in Su: sun.append(item.replace(su, '', 1).strip()) SUN = '/'.join([str(x) for x in sun])
然后我试着写为也套用我的 “转换器” 给其他日期的功能..
def formatPeriods(id, store1, store2, periodsDay):
for line in extendedPeriods:
if id in line:
store1.append(line)
for item in store1:
store2.append(item.replace(id, '', 1).strip())
periodsDay = '/'.join([str(x) for x in store2])
return periodsDay
但该函数返回12个misformatted串...
'1200 - 1500', '1200 - 1500/1200 - 1500/1800 - 2330',
你应该给你的变量不同的名字,你一定会混淆他们与这些名字。 – Dahaka
您提供的输入是为了获取这些格式错误的字符串而准确输入的? – Th3Cuber
formatPeriods(su,Su,sun,SUN) – user2560609