I am using argparse library to read the file to perform the comparison between two excel files. This is my code:
import pandas as pd
import numpy as np
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-FILE_1', '--file_1', type=str, required=True, action='append')
parser.add_argument('-FILE_2', '--file_2', type=str, required=True, action='append')
args = parser.parse_args()
def comparison():
df1=pd.read_excel(args.file_1)
df2=pd.read_excel(args.file_2)
comparison_values = df1.values == df2.values
rows,cols=np.where(comparison_values==False)
for item in zip(rows,cols):
df1.iloc[item[0], item[1]] = '{} --> {}'.format(df1.iloc[item[0], item[1]],df2.iloc[item[0], item[1]])
df1.to_excel('./Excel_diff.xlsx', 'Sheet2', index=False,header=True)
comparison()
When I input the command into the terminal,
PS C:\Users\Documents\Excel Comparison Proj> python .\excel_comparison.py -FILE_1 "Testing.xlsx" -FILE_2 "Testing - Copy.xlsx"
There is an error:
Traceback (most recent call last):
"C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\xlrd\__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Any suggestion to fix the issue so that the python can read the file from args.file_1 and args.file_2?