GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — csv.Sniffer does not detect lineterminator · Issue #75008 · python/cpython

csv.Sniffer does not detect lineterminator #75008

New issue
Copy link
New issue
Copy link
Closed
Closed
csv.Sniffer does not detect lineterminator#75008
Copy link
Assignees
serhiy-storchaka
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

vmax
mannequin
opened on Jul 1, 2017
Issue body actions
BPO 30825
Nosy @smontanaro, @nascheme, @terryjreedy, @vmax, @GjjvdBurg
PRs
  • bpo-30825: guess lineterminator in csv.Sniffer #2529
  • gh-75008: guess lineterminator in csv.Sniffer #18336
  • 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 2017-07-01.21:23:44.681>
    labels = ['3.8', 'type-feature', 'library']
    title = 'csv.Sniffer does not detect lineterminator'
    updated_at = <Date 2020-02-03.18:45:19.190>
    user = 'https://github.com/vmax'

    bugs.python.org fields:

    activity = <Date 2020-02-03.18:45:19.190>
    actor = 'vmax'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-07-01.21:23:44.681>
    creator = 'vmax'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30825
    keywords = ['patch']
    message_count = 7.0
    messages = ['297497', '311804', '311805', '311806', '327094', '329482', '329487']
    nosy_count = 5.0
    nosy_names = ['skip.montanaro', 'nascheme', 'terry.reedy', 'vmax', 'Gertjan van den Burg']
    pr_nums = ['2529', '18336']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30825'
    versions = ['Python 3.8']

    Linked PRs

    • gh-75008: Detect the lineterminator in csv.Sniffer.sniff() #155061

    Activity

    1. vmax commented on Jul 1, 2017

      @vmax
      vmaxmannequin
      on Jul 1, 2017
      MannequinAuthor
      More actions

      Line terminator defaults to '\r\n' while detecting dialect in csv.Sniffer

    2. vmax
      added
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Jul 1, 2017
    3. terryjreedy commented on Feb 7, 2018

      @terryjreedy
      terryjreedy
      on Feb 7, 2018
      Member
      More actions

      The csv expert listed in https://devguide.python.org/experts/ is marked as inactive, and I have never used the module. So you might need to ask for help on core-mentorship list.

      The csv doc for Sniffer.sniff says "Analyze the given sample and return a Dialect subclass reflecting the parameters found." It is not clear to me whether 'the parameters found' is meant to be all possible parameters or just those found. So, to be conservative, I will initially treat this an a feature addition for the the next version, rather than a bug to also be fixed in current versions. It does seem like a reasonable request.

    4. terryjreedy
      added
      3.8 (EOL)end of lifeend of life
      type-featureA feature request or enhancementA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Feb 7, 2018
    5. terryjreedy commented on Feb 7, 2018

      @terryjreedy
      terryjreedy
      on Feb 7, 2018
      Member
      More actions

      Looking at the code and docstring, lineterminator was intentionally (knowingly) not sniffed, making this a feature addition.

    6. terryjreedy commented on Feb 7, 2018

      @terryjreedy
      terryjreedy
      on Feb 7, 2018
      Member
      More actions

      While Sniffer *returns* a dialect with lineterminator = '\r\n', it *uses* '\n' for splitting. This is slightly odd, as it leaves lines terminated by '\r' while detecting within-line parameters, but it does not affect such detection.

      Are there csv files in the wild that use \r as line terminator. If so, they will not currently get split.

    7. nascheme commented on Oct 4, 2018

      @nascheme
      nascheme
      on Oct 4, 2018
      Member
      More actions

      There is another issue related to this. If you use codecs to get a reader, it uses str.splitlines() internally, which treats a bunch of different characters as line terminators. See issue bpo-18291 and:

      https://docs.python.org/3.8/library/stdtypes.html#str.splitlines

      I was thinking about different ways to fix this. First, the csv module suggests you pass newline='' to the file object. I suspect most people don't know to do that. So, I thought maybe the csv module should inspect the file object that gets passed in and then warn if newline='' has not been used or if the file is a codecs reader object.

      However, that seems fairly complicated. Would it be better if we changed the 'csv' module to do its own line splitting? I think that would be better although I'm not sure about backwards compatibly. Currently, the reader expects to call iter() on the input file. Would it be okay if it used the 'read' method of it in preference to using iter()? It could still fallback to iter() if there was no read method.

    8. GjjvdBurg commented on Nov 8, 2018

      @GjjvdBurg
      GjjvdBurgmannequin
      on Nov 8, 2018
      Mannequin
      More actions

      Note that the current CSV parser in _csv.c doesn't require the line terminator, it eats up \r and \n where necessary. See:

      cpython/Modules/_csv.c

      Line 752 in fd512d7

      case EAT_CRNL:

      This is why the line terminator isn't detected and doesn't need to be detected.

      Also, files that use the \r line terminator exist and are parsed correctly at the moment. See for example: https://raw.githubusercontent.com/hadley/data-fuel-economy/master/1998-2008/2008.csv

    9. smontanaro commented on Nov 8, 2018

      @smontanaro
      smontanaro
      on Nov 8, 2018
      Contributor
      More actions

      A couple comments.

      1. Terry Reedy wrote:

      The csv expert listed in https://devguide.python.org/experts/ is marked as inactive

      That would be me. I am indeed inactive w.r.t. fixing broken stuff, and
      don't want to feel obligated to jump in with both feet when a CSV
      ticket is raised. Still, I keep half an eye on things. If people are
      actually interested in my opinion on such stuff, drop me a line.

      1. Regarding the csv.Sniffer class... I've personally never found it
        useful, and would be happy to see it deprecated. I occasionally define
        a delimiter other than comma, and never specify the quotechar. (I've
        never seen anything other than quotation marks used anyway.) As others
        have indicated, the line terminator is kind of unnecessary with Python
        3 (unless you need something really weird). If you actually need to
        specify a delimiter, I think giving a set of candidate delimiters
        would be sufficient. The first one encountered wins.

      Maybe I'm just getting old and cranky, but deprecation is the fork in
      the road I'd take, given the choice. Second choice would be to
      simplify the delimiter sniffing logic and get rid of anything to do
      with line terminators.

      Skip

    10. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    11. serhiy-storchaka
      added this to CSV issues 📊on May 19, 2022
    12. serhiy-storchaka
      self-assigned this
      on Jan 9, 2024
    13. serhiy-storchaka
      added
      3.16new features, bugs and security fixesnew features, bugs and security fixes
      and removed
      3.8 (EOL)end of lifeend of life
      on Jul 21, 2026
    14. serhiy-storchaka
      added a commit that references this issue on Aug 13, 2026

      gh-75008: Detect the lineterminator in csv.Sniffer.sniff() (GH-155061)

      3157786
    15. serhiy-storchaka
      closed this as completedon Aug 13, 2026
    16. github-project-automation
      moved this to Done in CSV issues 📊on Aug 13, 2026
    17. mbeijen
      added a commit that references this issue on Aug 14, 2026

      pythongh-75008: Detect the lineterminator in csv.Sniffer.sniff() (pyt…

      e13d86d
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @serhiy-storchaka
      serhiy-storchaka

    Labels

    3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    • CSV issues 📊
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.