How to check if a file has a CSV format

1142605 pts.
Tags:
CSV file
Python
Would anyone happen to know if there's a way I could check if a file has the CSV format in Python? Would the CSV.sniffer work for something like this?
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Are you looking to verify the format is a true CSV and not trust the file extension?
    132,660 pointsBadges:
    report
  • carlosdl
    I'm not sure I understand the question.

    The "csv format" is pretty simple. The columns, or fields, are separated by commas, so if you check any file in which there is at least one comma per record, you have a CSV file, even if the internal format is not what you expect it to be.

    Even if you don't have any commas, you could say it is a CSV file with only one column/field.

    The answer would really depend on the specific validation you have in mind. For example, you might want to check if there are pipes or some other separator, and assume that they should be commas instead, but without specific details, I don't think we can offer an accurate suggestion.
    84,745 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: