I have a script that an argument is being passed from the automation program so I know there are no issues with the wrong file being passed. I am running into an issue that if the argument matches a filename it needs to add a suffix but it looks like it is not adding the suffix because all files default to the else of the if statement and I cant figure out why.
import sys
# Constants
WF = "C:\USERS\bob\Desktop\paymentfiles\bob.txt"
SUFFIX = 'N'
DESIRED_LENGTH_WF = 87
DESIRED_LENGTH_OTHER = 88
# Get the filename from command line argument
filename = sys.argv[1]
def reformat_file(filename):
# Determine the desired length based on the filename
desired_length = DESIRED_LENGTH_WF if filename == WF else DESIRED_LENGTH_OTHER
# Read the file
with open(filename, 'r') as file:
lines = file.readlines()
# Reformat each line
with open(filename, 'w') as file:
for line in lines:
line = line.strip()
if filename == WF:
# Add suffix 'N' for WF file
line = line.ljust(desired_length - 1) + SUFFIX
else:
# No suffix for other files
line = line.ljust(desired_length)
file.write(line + 'n')
if __name__ == "__main__":
reformat_file(filename)
if the filename is equal it is not adding the suffix. Any help you can provide would be great. I have manually passed the argument to ensure it is not being sent incorrectly with same results.
passing correct argument