Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (â‹®) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to fix python syntax errors (f-string..backslash & unmatched '(') etc?

Featured Replies

Hi guy's,

I was trying to test an python script but it runs into some errors. Below the script line

print(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 backslash

Seems 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

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
  • 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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.