// Open the file for reading
input_file = open(filename, "r")
// If the provided has a read attribute, we can use it as a file handleelif hasattr(filename, "read"):
input_file = filename// Raise error otherwiseelse:
raise ValueError("filename must be a string or file handle")// Note: we do io manually here for two reasons.// 1. The csv module has difficulties with unicode, which may lead// to failures on certain annotation strings