――I thought it was a python join, so I'll make a note of it.
--This is an image of converting the date into a character string. "2016/4" is the value you want.
>>> ym = [2016,4]
>>> "/".join(ym)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, int found
--An error has occurred. You should concatenate with a character string.
--Convert to a string with map.
>>> ym = [2016,4]
>>> "/".join(map(lambda x:str(x),ym))
'2016/4'
――It's in the shape you want.
--I want to fill the month part with 0. "2016/04" is the value you want.
>>> ym = [2016,4]
>>> "/".join(map(lambda x:(u"%02d"%x),ym))
'2016/04'
――Is it like this? If you don't fill 0, perl is easier.
% perl -le 'my @ym = (2016,4);print join("/",@ym)'
2016/4
% perl -le 'my @ym = (2016,4);print join("/",map {sprintf("%02d",$_)}@ym)'
2016/04
Recommended Posts