i have a csv file and a text file. is it possible to compare the values in both files? or should i have the values of both in a csv file to make it easier?
Yes, you can compare values from any N sources. You have to extract the values from each and then compare them. If you make your question more specific (the format of the text file for instance), we might be able to help you more.
csv itself is of course text as well. And that's basically the problem when "comparing", there's no "text file standard". Even csv isn't that strictly defined, and there's no normal form. For exmaple, should a header be included? Is column ordering relevant?
How are fields separated in the textfile? Fixed width records? Newlines? Special markers (like csv)? , If you know the format of the textfile, you can read/parse it and compare the result with the csv file (which you will also need to read/parse of course), or generate csv from the textfile and compare that using diff.
is it possible to compare the values in both files?
Yes. You can open them both in binary mode an compare the bytes, or in text mode and compare the characters. Neither will be particularly useful, though.
or should i have the values of both in a csv file to make it easier?
Convert them both to list-of-lists format. For the CSV file, use a csv.reader
. For the text file, use [line.split('\t') for line in open('filename.txt')]
or whatever the equivalent is for your file format.