[Python] Python eval: SyntaxError: unexpected character after line continuation character

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I want to evaluate a string of a file path to open the file, but I get the error:
    File :1 'C:\Users\xxx\Desktop_Revenue\Input' + str(yr) + '\' + 'Survey' + YY + '_revenue.xlsx'

    SyntaxError: unexpected character after line continuation character

    The syntax error is at '\'

    I want to use eval as my file path is passed into a function later


    url= " 'C:\\Users\\xxx\\Desktop\\_Revenue\\Input\\' + str(yr) + '\\' + 'Survey' + YY + '_revenue.xlsx'"

    def test (yr):
    yr=yr
    YY=str(yr)[2:]

    survey_url= eval(url)

    test(2015)

    Continue reading...

Compartilhe esta Página