String compare issue

A very simple script to compare string, if string include \n,\t, how to use compare?

*** Test Cases ***
compare
{abc1} set Variable 1\n2 {abc2} set Variable 12
run keyword if ‘{abc1}'!='{abc2}’ log 1234

ERROR:
20200820 17:29:49.055 : FAIL :
Evaluating expression ‘‘1
2’!=‘12’’ failed: SyntaxError: EOL while scanning string literal (, line 1)

The script is simple, but it is not a simple string. It must be cleaned-up before comparing.
Here is your working script:

*** Test Cases ***
Compare
    ${abc1}=    Set Variable    1\n2
    ${abc2}=    Set Variable    12
    Run Keyword If    "${abc1.replace('\n','').strip()}" != "${abc2.replace('\n','').strip()}"    Log    1234
2 Likes

It pretty good. it works well now. Thanks :slight_smile:

An EOL (End of Line) error indicates that the Python interpreter expected a particular character or set of characters to have occurred in a specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error . The error eol while scanning string literal error in python occurs when while scanning a string of a program the python hit the end of the line due to the following reasons:

  • Missing quotes
  • Strings spanning multiple lines

Python is particularly prone to this type of error, since Python ends statements with newlines/line breaks , whereas most other programming languages have a character such as a semicolon (:wink: , which means that other programming languages work more easily with multi-line statements out of the box.

clear. thank you for your explanation:)