Sublime Forum

Does Python f-strings work?

#21

That looks like linting, which will be dependent on the linter you are using.

0 Likes

#22

Thanks, after bit of ressearch on linters I figured my issue by installing MagicPython package for syntax highlight and flake8 package for linting :slight_smile:

0 Likes

#23

Did you ever figure this out? I’m having the exact same problem (I’m using the same book you are) – I’m running 3.8.1 on macOS and get a syntax error.

0 Likes

#24

You can verify whether the correct version of Python is being used by following OdatNurd’s reply.

0 Likes

#25

Hello there, try this syntax package https://packagecontrol.io/packages/MagicPython
After that choose option to open Python files with MagicPython syntax.

For error highlighting and etc I’d recommend Anaconda package https://packagecontrol.io/packages/Anaconda

Maybe there is better solutions for f-string issue, but this is solution I came up with :slight_smile:

0 Likes

#26

Just to reiterate what was stated above, the original problem(s) in the posts above have nothing to do with the syntax definition being deficient (as witnessed by the code in the screenshots being highlighted correctly); the actual problems seen by various posters are caused by:

  1. A linter package that is linting Python 3 code as if it was Python 2
  2. Trying to run Python 3 code using Python 2

In particular, Sublime executes an external program (the python interpreter) to run your code, so if running your program fails, that’s an issue with the external tool that’s being launched.

If you see some error indication in the gutter and/or colored boxes around code that’s invalid, that is a package you installed that’s trying to lint (verify) your code for you incorrectly assuming the version of Python that you’re using.

That’s not to say that the syntax provided by the MagicPython package isn’t somehow better for syntax highlighting purposes, but it’s by no means required to execute Python 3 code using f-strings.

1 Like

#27

Problem is (as far as I understood) that Sublime is using build in version of Python 3.3.6 for syntax linting. I’ve tried dozen different ways to use macOS system version of Python but none of them worked, thats why I end up with such solution as MagicPython. Sure, it’s not solving original issue directly, but for me it was only way to overcome this limitation :sweat_smile:

0 Likes

#28

No, it does not, because Sublime Text by itself does no syntax linting at all. It uses Python 3.3.6 for its plugin runtime, but it does not use that for linting. Linters using the SublimeLinter framework are external libraries or executables that are run on your code using whatever version you installed them for or configured.

1 Like

#29

Oh, I see, thanks for clarification. In this case there is issue with SublimeLinter framework on macOS. I’ve tried different ways outlined in this forum (including this thread and couple others), but none of them worked for me :frowning:

0 Likes