Something like this would be easier to comment on if you include a couple records of sample data.
I think you might want to change the line fields['S&E'] = str2 to be out1['S&E'] = str2
If you don't expect an array then I probably wouldn't personally use "in". I don't think its doing what you expect here.
I think you actually want something like this: (check for minor typos etc)
if in1['S&E']:
out1['S&E']=in1['S&E'].replace(' ','')
The "if" is is only needed if some data is not defined, you might need stronger null checking. Also replace will actually remove multiple occurrences
If you really do have a list then the first tweak should work.
------------------------------
Peter Sykes
Vontobel Holding AG
ZUERICH
------------------------------
Original Message:
Sent: 03-27-2023 09:25
From: Shawn Pelletier
Subject: Removing spaces from string in column
The data source I'm connecting to is always pulling back a 5 character string, however, the actual data is not always 5 characters. It could be 3, 4, or 5. The data with less than 5 characters is padding with spaces to bring it to 5. Below is the script I created, however, it's not replacing the spaces, and I'm currently accounting for only 1 space character. It's also not kicking back any errors. Is there an easier to remove the spaces and\or what's wrong with my script?
out1 += in1
if ' ' in fields['S&E']:
str1 = fields['S&E']
str2 = str1.replace(' ', '')
fields['S&E'] = str2
else:
pass
.
------------------------------
Shawn Pelletier
Knowledge Community Shared Account
------------------------------