[Python] How to approach: csv objects specified on command line or in a file

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I would like to accept 2d points provided on the command line or read from a file. Example command line input:

    ( 4,-1),(0, 0) , (3,3)


    example CSV file

    4, -1
    0,0

    3 ,3


    I.e. "comma outside braces" and "newline" are the two possible separators. I can see 3 roads ahead:

    • re(not sure if even possible if number of provided points is unknown)
    • some magic from python's legendary "batteries"(module csv seems a bit overengineered for such a simple use case, is that true?)
    • the C way - feed the string to a state machine
    • entirely separate handling for the two formats.

    It's mostly a conceptual question so any criticism a la "this is a dumb question" or "this is an AB question" is welcome more than code.

    Continue reading...

Compartilhe esta Página