open file named with two digit year-Python
Question: I'm opening a file named in the following format :

    
    
    ex130626.log
    exYYMMDD.log
    

following code wants 4-digit year. How to get the two digit year like 13?

    
    
    today = datetime.date.today()
    filename = 'ex{0}{1:02d}{2:02d}.log'.format(today.year, today.month, today.day)
    


Answer: Just take the modulus of the year:

    
    
    >>> import datetime
    >>> today = datetime.date.today()
    >>> filename = 'ex{:02}{:02}{:02}.log'.format(today.year%100, today.month, today.day)
    >>> filename
    'ex130625.log'
    

But an easier way is `strftime`:

    
    
    >>> today.strftime('ex%y%m%d.log')
    'ex130625.log'
    

