Skip to content

csv.Sniffer().has_header() Returns False for a CSV with a Header #131043

@mouchen626

Description

@mouchen626

Bug report

Bug description:

I encountered an issue while using csv.Sniffer().has_header() in Python's built-in csv module. Despite providing a CSV file with a clear header, the function returns False, whereas the expected result is True.

import csv

with open('1.csv', mode='r', encoding='utf-8') as file:
    sample = file.read(1024)
    has_header = csv.Sniffer().has_header(sample)  
    print(f"Has header: {has_header}")

1.csv

filename,path
c.txt,/tmp/c.txt
python.txt,/tmp/python.txt

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions