Yesterday at 05:36 PM1 day Hi guy's,I was trying to test an python script but it runs into some errors. Below the script lineprint(f'Available audios:\n {"\n ".join((' ' if i<10 else ' ') + str(i)+'. '+j for i, j in enumerate(display_ids, 1))}\n')=SyntaxError: f-string expression part cannot include a backslashSeems that the "\n " is the problem used in {} brackets. On internet I found some info to use chr(10) instead like this...print(f'Available audios:\n {chr(10).join((' ' if i<10 else ' ') + str(i)+'. '+j for i, j in enumerate(display_ids, 1))}\n')...but I get another error...SyntaxError: f-string: unmatched '('...then I tried to find some python fixer online which gave me 2 other lines like this...print(f'Available audios:\n' f'{"\n ".join((" " if i < 10 else " ") + str(i) + ". " + j for i, j in enumerate(display_ids, 1))}\n') or print(f'Available audios:\n' f'{"\n ".join((" " if i < 10 else " ") + str(i) + ". " + j for i, j in range(1, len(display_ids) + 1), display_ids)}\n')..but also fails with...SyntaxError: f-string: Generator expression must be parenthesized...so can anyone of you tell me how to fix this line? Thanks.greetz
20 hours ago20 hr Maybe you need to update your Python?Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> display_ids = ["first", "second", "third"] >>> print(f'Available audios:\n{"\n".join(f'{i:2}. {j}' for i, j in enumerate(display_ids, 1))}\n') Available audios: 1. first 2. second 3. third
2 hours ago2 hr Author Hi @adoxa,oh okay, seems that the Python version I used was too low 3.10 in the VE. I tried it again with latest version and now I don't get this error anymore. 🙂 Thanks.greetz
Create an account or sign in to comment