0

Robocorp can not convert path-like string properly when it intercept with raw python methods.

My code:
Get config from files
    [Arguments]    ${path}
    Directory Should Exist    ${path}    msg=目录不存在
    Directory Should Not Be Empty    ${path}    msg=目录为空
    ${main_dirs}=    List Directory    ${path}    absolute=${True}
    ${item_package_lst}=    Create List
    ${config_files}=    Create List
    FOR    ${element}    IN    @{main_dirs}
        ${dir_exist}=    Does Directory Exist    ${element}
        IF    ${dir_exist} == ${True}
            Append To List    ${item_package_lst}    ${element}
        ELSE
            IF    ${element}.endswith("全局商品共用.xls") or ${element}.endswith("全局商品共用.xlsx")
                Append To List    ${config_files}    ${element}
            END
        END
    END
    Log To Console    全局配置:${config_files}
    Log To Console    商品包:${item_package_lst}
    RETURN    ${config_files}    ${item_package_lst}

focus on the following line:

 IF    ${element}.endswith("全局商品共用.xls") or ${element}.endswith("全局商品共用.xlsx")

and the element value is "C:\Users"

The "\U" is not escapable and will occur an error,because endswith is not a robocorp framework function and can not handle the path-like string properly,so it will cause error like this:

Evaluating IF condition failed: Evaluating expression '"C:\Users\Leyan\Desktop\天猫测试\desktop.ini".endswith("全局商品共用.xls") or "C:\Users\Leyan\Desktop\天猫测试\desktop.ini".endswith("全局商品共用.xlsx")' failed: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (, line 1)

dogewang
  • 648
  • 1
  • 7
  • 15

0 Answers0