Python script to process csv file for preparation for printing stickers.
""" | |
Date: 2018/08/15 | |
Author: Pieter du Plesses | |
Website: pieter-duplessis.co.za | |
Version: 3 | |
Last Modify:2018/08/22 | |
Description: | |
Processing CSV sheet to get the file ready for printing stickers for the | |
shelf for identification. Process part number and bin location to have bin | |
location in row above part number in one single column. The bin location to | |
be processed with the '-' between the different section of the bin location | |
number for easier identification. | |
""" | |
# String for file location with the data and the file for the processed data | |
fileToProcess = 'C:\location\of\file\AA.csv' | |
fileProcessed = open('C:\location\of\file\AAProcessed.csv', 'w') | |
# Open file in a loop | |
with open(fileToProcess) as f: | |
# While the file is open process all the lines (Until End of File) | |
for line in f: | |
# Split the row into an array | |
s2p = line.split(',') | |
# Initialize variable to hold modified bin location for | |
s1a = "" | |
# Processing the bin location number for the different lengths | |
# Not to add additional lines that will print blank sticker. | |
if len(s2p[1]) == 8 : | |
# For 3 Digit of Position | |
s1a = s2p[1][:2]+"-"+s2p[1][2:4]+"-"+s2p[1][4:7] | |
elif len(s2p[1]) == 9 : | |
# For 4 Digit of Position | |
s1a = s2p[1][:2]+"-"+s2p[1][2:4]+"-"+s2p[1][4:8] | |
else: | |
# Print error if the length of the bin location is not 8 or 9 characters | |
# long. Just as precaution if it happens or error in CSV file. | |
print("ERRROR") | |
# Write the new rows to the files | |
fileProcessed.write(s1a+'\n') | |
fileProcessed.write(s2p[0]+'\n') | |
# Close the files | |
f.close() | |
fileProcessed.close() | |
""" | |
Input row: | |
<PartNumber>, <BinLocation> | |
Output rows: | |
<BinLocation> | |
<PartNumber> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment