[Python] f-string works properly on Linux, raises error on mac

Discussão em 'Python' iniciado por Stack, Agosto 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following f-string in my python code:

    text = f'<b>Hello!</b>\n\
    Your ID: {userid}\n\
    Balance: {user_data['balance']} $\n'


    Basically this works perfectly fine on my linux ubuntu, but when I run it on my mac it raises the following error:

    Balance: {user_data['balance']} $\n
    ^^^^^^^
    SyntaxError: f-string: unmatched '['


    I looked up this kind of error online, the answers suggested to upgrade to python 3.12 or later, which I did, but it didn't work.

    I know i could refactor this string like so:

    text = f'blablabla \n'\
    f'lalalal \n'\
    f'blablabla'


    but the catch is that I have tons of strings like this which would be a waste of time to rewrite all of them (at least I don't have much time for this now). Hence, I'm looking for an answer to my questin.

    Continue reading...

Compartilhe esta Página