Python Calculation SyntaxError: "unterminated string literal" when using [F001]

More
7 months 1 week ago - 7 months 1 week ago #25899 by Onkar2002
Hi,
I am trying to use a Python script in the "Calculation" transformation to remove duplicates from a column.
The Issue: When I hardcode the data into the script for testing, it works perfectly. However, when I replace the hardcoded data with the input variable [F001],
I get the following error: 
Code:
SyntaxError: unterminated string literal (detected at line 1)

my script
Code:
: raw_value  = str([F001]) items = [x.strip() for x in raw_value.split(',') if x.strip()] unique_items = for item in items:     if item not in unique_items:         unique_items.append(item) unique_items.sort() Result.value = ','.join(unique_items)

When I manually type the string (e.g., raw_value = 32607,32607), it works fine.
When I use [F001], it fails immediately.
In the "Data Preview" or execution log, the result for this column comes back as NULL because the script is failing.
It seems like the data inside [F001] might contain characters (like newlines) that are breaking the Python string syntax during the substitution.
Could you advise on the correct way to handle [F001] variables in Python that might contain special characters or newlines?

 

 
 
Last edit: 7 months 1 week ago by Onkar2002.
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

More
7 months 1 week ago #25900 by admin
Hi Onkar

1  When I use [F001], it fails immediately.

Parameters tab has a Test Value which you can use for testing and development





2 It seems like the data inside [F001] might contain characters (like newlines) that are breaking the Python string syntax during the substitution.

When [F001] is equal tp 1,2,3 the actual code executed is
raw_value  = str('1,2,3')

if [F001] has special characters the code will fail
This is expected python behavior, so what you need to do is to escape [F001] value
This can be done by using the following transformation
www.etl-tools.com/wiki/advanced-etl-proc...rings/escape-string/

Please keep us posted on your progress




 

Mike
ETL Architect
The following user(s) said Thank You: Onkar2002

Please Log in or Create an account to join the conversation.

More
7 months 1 week ago #25901 by prashant
Taking Mike's hunch , I asked Chatgpt & it gave me a single line to remove the delimiter,

raw_value = raw_value.replace('\r', '').replace('\n', '')

I tried a simple test and it worked at my end & it worked fine.
The following user(s) said Thank You: admin, Peter.Jonson, Onkar2002

Please Log in or Create an account to join the conversation.

Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Google
Accept
Decline
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Google Analytics
Accept
Decline
Functional
Tools used to give you more features when navigating on the website, this can include social sharing.
Advertisement
If you accept, the ads on the page will be adapted to your preferences.
Google Ad
Accept
Decline
Save