[Application-profiles-ig] Python implementation(s)

Thomas Baker tbaker at tombaker.org
Sun Dec 6 09:54:33 GMT 2020


Hi Nishad, On 2020-12-05 04:23, Nishad Thalhath wrote: >A quick response on CSV reader for empty values : The>default behavior always depends on the>implementation/library/subclasses. If we assume that,>我们使用内置的CSV module to parse, in>'csv.DictReader', the default is 'None', and we can>override it with 'restval'.I do use csv.DictReader [1]. In my reading, the restval [2] default of None is used when one of the fields specified in the optional "fieldnames" argument is missing. Rather than enumerate fields in the "fieldnames" argument, however, I simply take the values in the first row as fieldnames. This seems to be clearly the better option given our flexibility about which fields to use and the order in which they are used. So the restval default would never apply because there would never be missing fields, just empty string values for existing fields. However, the use of None as a default for missing fields does seem like a good hint for using None as a default for the dataclass parameters (instead of a blank string) - even for elements intended to hold Boolean values, such as 'mandatory'. Do you agree? On the subject of DictReader, note that I open the file object with encoding="utf-8-sig" (instead of just "utf-8"). This means it will handle Excel files, which have a U+FEFF Byte Order Mark, but seems to work fine with CSV files created by other means, such as text editors. Do you see any reason not to use utf-8-sig? Tom [1]https://github.com/tombaker/csv2shex/blob/csvschema/csv2shex/csvreader.py#L22[2]https://docs.python.org/3/library/csv.html-- Tom Baker <tom at tombaker.org>


More information about the Application-profiles-ig mailing list