Not sure why it is not going inside the loop.
import csv
import pandas as pd
print('hi')
df = pd.DataFrame
df = pd.DataFrame(columns=['ProductID', 'SKU', 'ISBN', 'UPC','MasterProductID'])
with open(rb'E:\ETL\Python\Client\WORKCAT\shq_client.txt', encoding="utf8") as pf:
number_of_lines = len(pf.readlines())
print(number_of_lines)
csv_file = csv.DictReader(pf, delimiter = '|', skipinitialspace=True, lineterminator='\r\n')
print(csv_file)
line_limit = 3
line_cnt = 0
print(line_limit)
for row in csv_file:
print('before if')
if line_cnt < number_of_lines:
print('inside')
print(row['item_id'], row['short_description'])
#df.index = line_cnt
df['ProductID'] = row['item_id']
print(df)
else:
pf.close
line_cnt += 1
The output is shown as below:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Users\marunachalam> & C:/Users/marunachalam/AppData/Local/Programs/Python/Python37-32/python.exe c:/Users/marunachalam/Downloads/Extract-ProductFeed-Sams.py
hi
339
<csv.DictReader object at 0x0C9FB070>
3
PS C:\Users\marunachalam>
I am not sure why it does not go inside the for loop where it is supposed to read the csv file records as there are 339 records in the file.
Any help is appreciated. I am a very beginner in Python.
Thanks