Skip to content
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

csv.DictReader, skipinitialspace does not ignore tabs #79997

Closed
andrelehmann mannequin opened this issue Jan 24, 2019 · 4 comments
Closed

csv.DictReader, skipinitialspace does not ignore tabs #79997

andrelehmann mannequin opened this issue Jan 24, 2019 · 4 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@andrelehmann
Copy link
Mannequin

andrelehmann mannequin commented Jan 24, 2019

BPO 35816
Nosy @tirkarthi
Files
  • conf.csv
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2019-01-24.10:28:34.304>
    labels = ['type-bug', 'library', '3.10']
    title = 'csv.DictReader, skipinitialspace does not ignore tabs'
    updated_at = <Date 2021-03-25.22:59:07.428>
    user = 'https://bugs.python.org/andrelehmann'

    bugs.python.org fields:

    activity = <Date 2021-03-25.22:59:07.428>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-01-24.10:28:34.304>
    creator = 'andre.lehmann'
    dependencies = []
    files = ['48075']
    hgrepos = []
    issue_num = 35816
    keywords = []
    message_count = 3.0
    messages = ['334289', '334290', '334295']
    nosy_count = 2.0
    nosy_names = ['xtreak', 'andre.lehmann']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35816'
    versions = ['Python 3.10']

    @andrelehmann
    Copy link
    Mannequin Author

    andrelehmann mannequin commented Jan 24, 2019

    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.

    @andrelehmann andrelehmann mannequin added the type-bug An unexpected behavior, bug, or error label Jan 24, 2019
    @tirkarthi
    Copy link
    Member

    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 :

    else if (c == ' ' && dialect->skipinitialspace)

    @tirkarthi
    Copy link
    Member

    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.

    @iritkatriel iritkatriel added stdlib Python modules in the Lib dir 3.10 only security fixes labels Mar 25, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @serhiy-storchaka
    Copy link
    Member

    Well, this was fixed in other way in bpo-21297/gh-65496.

    @serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: Done
    Development

    No branches or pull requests

    3 participants