How to show newly added column to csv - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to show newly added column to csv (/thread-23567.html) |
How to show newly added column to csv - johnson54937 - Jan-06-2020 I am trying to make a 'inventory' type app... i have it working like i want it to work, adding name of item and serial number of item, but i am trying to add an item and keep getting errors... if you can look at this and tell me how to change it to view the added item def list_items(items): for i in range(0, len(items)): item = items[i] print(str(i+1) + ". " + item[0] + " (" + str(item[1]) + ")")Thanks in advance I now have it where it will input the added information in the csv file, but now i can't view it... i can change the 'item[]' or even add an 'item[]' but it states out of range. i think i should simply be able to change the line 'for i in range(0, len(items)): but can't seem to make it work... thanks for the help RE: How to show newly added column to csv - Larz60+ - Jan-06-2020 use difflib: https://docs.python.org/3/library/difflib.html (or you can use Linux diff from command line) RE: How to show newly added column to csv - hinay - Jan-06-2020 Hi, Larz60 thanks for the link to it, I was finding the same. Regards, H. Smith RE: How to show newly added column to csv - Larz60+ - Jan-07-2020 forget my first post, I misunderstood your intent, is this what you're looking for? (change csv filename to your file, and change delimiter as required) import os import csv os.chdir(os.path.abspath(os.path.dirname(__file__))) def list_items(row): for item in row: for element in item: print(f"{element} ", end ='') print(" | ", end="") print() with open('health-no-head-sample.csv') as fp: crdr = csv.reader(fp, delimiter= ',') for n, row in enumerate(crdr): if n < 10: list_items(row) else: breakresults with my csv file:
|