1
2
3
4
5
6
7
8
9
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
import sys
if sys.version < '3':
import codecs
def u(x):
return codecs.unicode_escape_decode(x)[0]
else:
def u(x):
return x

Still search for the documentation for the function unicode_escape_decode() in codecs.

Docs first:
https://docs.python.org/3/library/glob.html

1
2
import glob
glob.glob('./[0-9].*') # ['./1.gif', './2.txt']

The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order.

glob.glob(pathname, *, recursive=False)

Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pathname can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (like ../../Tools//.gif), and can contain shell-style wildcards. Broken symlinks are included in the results (as in the shell).

If recursive is true, the pattern “**” will match any files and zero or more directories and subdirectories. If the pattern is followed by an os.sep, only directories and subdirectories match.

The topic today is datetime which makes me think of life. Maybe, music is a mataphor of life.

1
2
3
4
5
6
7
import datetime

t = datetime.date(2017, 4, 4)
t.isoweekday() # 2
t.isoformat() # '2017-04-04'

one_day = datetime.timedelta(days=1)

Other things useless (maybe not) you could find on
https://docs.python.org/3/library/datetime.html

1
2
3
4
5
6
7
8
9
10
11
12
import time
from datetime import date

today = date.today()
today == date.fromtimestamp(time.time()) # True
my_birthday = date(today.year, 6, 24) # Fake birthday

if my_birthday < today:
my_birthday = my_birthday.replace(year=today.year + 1)

time_to_birthday = abs(my_birthday - today) # why we need abs that makes previous IF statement meaningless
time_to_birthday.days

You could always find the manual. That’s enough for today.

0%