-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
csv.DictReader, skipinitialspace does not ignore tabs #79997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When using the csv.DictReader a dialect can be given to change the behavior of interpretation of the csv file. The Dialect has an option "skipinitialspace" which shall ignore the whitespace after the delimiter according to the documentation (https://docs.python.org/3/library/csv.html). Unfortunately this works only for spaces but not for tabs which are also whitespaces. See the following code snippet applied on the attached file: with open("conf-csv", "r") as csvfile:
csv.register_dialect("comma_and_ws", skipinitialspace=True)
csv_dict_reader = csv.DictReader(csvfile, dialect="comma_and_ws")
for line in csv_dict_reader:
print(line) The second line shall not contain "\t" chars. |
https://bugs.python.org/issue21297#msg216907 to be related and has a patch. It refers to whitespace as only space ('U+0020') with tabs being ignored. Current code where only space is taken into account : Line 621 in fd628cf
|
Sorry, I overlooked the patch. The issue reported is the same in bpo-21297 but the patch was about changing whitespace to space in the doc instead of changing the behavior as I can see from the discussion. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: