Sublime Forum

F-string not recognized

#1

I’m running Sublime Text 3 version 3.22 (Build 3211) on macOS 10.15.4 (Catalina).
I’m running Python 3.7 but I wonder if ST is somehow building with an older Python.

I’ve just started using Sublime, been learning Python for months and I’m not new to programming.

print('Hello World!) # runs okay

print(f’Hello World!’) # f-string produces Syntax Error

SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u “/Users/martinmeo/SW_DEV/PYTHON/SANDBOX/RENAME_FILES/helloWorld1.py”]
[dir: /Users/martinmeo/SW_DEV/PYTHON/SANDBOX/RENAME_FILES]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin]

0 Likes

#2

Does running python in the terminal execute Python 3 for you?

The Python.sublime-build file that ships with Sublime executes python (as noted in your diagnostic above) so if that’s not the correct version of Python then you need to create your own build file that uses the correct version (e.g. python3 or what have you).

The easiest way to do that would be:

  1. Use View Package File from the command palette and enter python build, then open Python/Python.sublime-build
  2. Copy the entire contents of the file that opens (it will be read only)
  3. Use Tools > Build System > New Build System... from the menu
  4. Replace the content of the new buffer entirely with your copied content
  5. Adjust the shell_cmd as appropriate to execute the correct version of Python
  6. Save the file as a sublime-build file in the offered location with a meaningful name

Using your new build system will execute the version of Python that you want, which should solve your problem.

0 Likes

Import serial not found
#3

Does running python in the terminal execute Python 3 for you?
Running ‘python’ in the terminal window will execute Python 2.
Running ‘python3’ in the terminal window will execute Python 3.

Thank you OdatNurd!
I created a new build system as per your instructions and it works now.

1 Like