Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to process csv file for preparation for printing stickers.
Date: 2018/08/15
Author: Pieter du Plesses
Version: 3
Last Modify:2018/08/22
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]
# 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.
# Write the new rows to the files
# Close the files
Input row:
<PartNumber>, <BinLocation>
Output rows:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment