Oct-11-2018, 05:26 PM


I have almost completed my program, but I am not sure what to do next. Please stick with me as I try to explain.
Currently, I get a list from email and it is formatted with information that I want to print. However, everything is out of order.
I formate what I want to print using print statements and output to text files. But I can only do this for lists of 1 and only for the first item because I'm unsure of how to make my loop work right.
The list comes to me as a list of lists.
How can I iterate through my list building the correct results?
When I pull the email and process it I get:
['\ufeff73450', 'New Hope Electric Company of Washington, Inc.', 'CI-120 - West Port Hall Student Commons - AC-Aiphone-Intrusion-CCTV', 'Location', 'Part#', 'Description', 'Curr Qty', 'M2C2', '6702UE 888U1000', 'Cable - 4 Conductor-SSA-Plenum-Box-Unshielded-22AWG/4-Stranded-Natural', '1000', ''] ['\ufeff76805', 'JM Wentworth, Inc.', 'JMW - Westport - Buildout', 'Location', 'Part#', 'Description', 'Curr Qty', 'L1B2', '98756-U48', 'Patch Panel-Cat6-48 Port-2U-Loaded-Universal-Black', '1', 'L1B3', '65756-U24', 'Patch Panel-Cat6-24 Port-1U-Loaded-Universal-Black', '1', 'M3B4', '95-050-41-X', 'Fiber Connector-MM-Unicam-Ceramic-SC-50/125-OM3/OM4-High performance-Aqua', '24', 'M3B7', 'RIC-F-SC12-01', 'Fiber Bulkhead-SM/MM-6 Duplex-12 Adapters-SC-Black', '2', 'M3B9', 'RIC-F-BLNK-01', 'Fiber Bulkhead - Blank-Black', '4', 'M3C9', '852-L42-009', 'Fiber Patch Cord-MM-LC-SC-Duplex-50/125-Riser/CMR-3 M-Value Series-Aqua', '2', 'M2C88', '000-050', '"Fiber Ground- Connector-MC-.5"" NWT Metallic"', '2', 'M4C7', '566-000-005', 'Copper Patch Cord-Cat6-RJ45-RJ45-5 Ft-No boot-PVC-Stranded-Value Series-Blue', '37', 'M4C6', '2601-00000-015', 'Copper Patch Cord-Cat6A-RJ45-RJ45-15 Ft-Snagless-PVC-Shielded-Stranded-Gray', '2', '']Currently to get things to print how I want I use this:
print("_" * 45, file=open("output.txt", "a")) print("| Job Number: " + "73543", " " * (25 - len(attachment_all[0][7])) + "| ", file=open("output.txt", "a")) print("| Job Name: " + attachment_all[0][1], " " * (18 - len(attachment_all[0][7])) + "| ", file=open("output.txt", "a")) print("| Job Location: " + attachment_all[0][2], " " * (17 - len(attachment_all[0][7])) + "| ", file=open("output.txt", "a")) print("*" * 45, file=open("output.txt", "a")) print("| Loc | Part #", " " * (17) + "| Qty |", file=open("output.txt", "a")) print("| " + attachment_all[0][7], " " * (4 - len(attachment_all[0][7])) + "| " + attachment_all[0][8], " " * (23 - len(attachment_all[0][8])) + "| " + attachment_all[0][10], " " * (10 - len(attachment_all[0][10])) + "|", file=open("output.txt", "a")) print("| Description: " + attachment_all[0][9], file=open("output.txt", "a"))*Notice I put the job number if I don't I get an error, but I am worried about how I can iterate through my list to get things to print the right way. The heading will always be the same but when a list has more than 1 part it will not repeat the headline and just add a new line for the items.
I'm reading through some other posts and getting ideas.
I know for instance I want to grab items 0-6 inside any new list. This will be my header which is 1-12 in my print section.
Next, I want to grab any set of 4 items, 7-11, and make that my next line. Follow this line with any 4 more items until no items are left.
So far I don't know how to do this part.