def read(source):
"""Read palette from `source`
source: file handle, file name or iterable of strings
Returns list of string lines.
Raises TypeError or OSError.
"""
if hasattr(source, 'readlines') and callable(source.readlines):
lines = source.readlines()
elif isinstance(source, str):
try:
with open(source, mode='r') as f:
lines = f.readlines()
except OSError as e:
raise ThemeError('Unable to read {!r}: {}'.format(source, e.strerror))
elif isinstance(source, abc.Iterable):
lines = source
else:
raise TypeError('Invalid source: {!r}'.format(source))
return [l.rstrip('\n') for l in lines]
评论列表
文章目录