import codecs
unique = set()
any(unique.update(line) for line in codecs.open(filename, encoding='UTF-8'))
unique.difference_update('!@#.')
unique_char_count = len(unique)
How to count the number of unique characters in a file?