![](/img/trans.png)
[英]Quotation mark completion with f-strings in Sublime Text's Python 3
[英]f-Strings in Sublime Text
如果我检查 Python 的版本,我的终端会说它是 3.8.1。 但是如果我尝试在 Sublime Text 中使用这些 f 字符串,我总是会遇到语法错误。
谁能告诉我为什么?
所以这是我的版本,与我的终端有关
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
这是代码:
greeting = 'Hello'
name = 'Hannah'
message = f'{greeting}, {name}. Welcome!'
print(message)
这是错误:
File "/Users/bennimueller/Desktop/Intro.py", line 4
message = f'{greeting}, {name}. Welcome!'
^
SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/bennimueller/Desktop/Intro.py"]
[dir: /Users/bennimueller/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
当您从 macOS 上的 python.org 安装程序安装 Python 时,可执行文件实际上是通过运行python3
调用的。 您的构建系统实际上正在调用/usr/bin/python
,这是 macOS 附带的 Python 2 版本。
为了解决这个问题,您只需创建一个自定义构建系统。 转到Tools
→ Build System
→ New Build System…
(一直在底部)并输入下面的内容(删除所有出现的占位符模板)。
{
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.8/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
/Library/Application Support/Sublime Text 3/Packages/User if you're interested.当你去保存文件时,它会自动把你放在正确的目录中——如果你感兴趣的话,它是/Users/ /Library/Application Support/Sublime Text 3/Packages/User
。 将文件命名为Python 3.sublime-build
,现在将有一个Tools
→ Build System
→ Python 3
选项。
对于 Python 3.9,其:
1.转到 Sublime Text 到:Tools -> Build System -> New Build System 并放置下一行:
{
"cmd": ["python3", "-i", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
}
然后用一个有意义的名字保存它,比如: python3.sublime-build
2.转到工具->构建系统->并检查python3
测试它:
import sys
print(sys.version)
按:Ctrl + b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.