|
|
|
|
|
by bvrmn
667 days ago
|
|
[Grumpy mode start] Some nitpicks, maybe someone finds it useful. Could we talk about a code design a little bit? class DSV:
@property
def delimiter(cls) -> bytes:
return b'\x1F'
@property
def record_separator(cls) -> bytes:
return b'\x1E'
@property
def encoding(cls) -> str:
return 'utf-8'
It's Python, do not make a premature properties for static values. class DSV:
delimiter = b'\x1F'
record_separator = b'\x1E'
encoding = 'utf-8'
Also it's a false inheritance relationship. Writer is not related to configuration. You can't make any other useful subclasses for DSV (ok maybe DSVReader, but that's it). At least it should be in the opposite way: an abstract Writer operating on instance configuration attributes and DSVWriter defining these attributes.Also `self._buffer += chunk` is O(N^2). It starts to bite even for buffers small as 100 bytes. It's ok for an example, but it's an issue for real code. Example at least buffers incomplete record not a whole read chunk (good!). But does only one split at a time (bad). [Grumpy mode end] Nevertheless article is very valuable and interesting to read. CSV gotchas are well described. |
|