gpt4 book ai didi

python - 为什么 VSCode Code Runner 不支持 f-strings?

转载 作者:行者123 更新时间:2023-12-05 01:39:33 34 4
gpt4 key购买 nike

我遇到了 VSCode 和 Code Runner 扩展的问题,这里是导致问题的代码片段:

class init_error(Exception):
def __init__(self, comp="Internals"):
self.component = comp
self.message = f"Error occurred while initiating {self.component}"

def __str__(self):
return self.message

我一开始以为是把编译器弄错了 Python2 和 Python3,但是在指定了 #!/usr/bin/env python3 并检查了 print("foo") 有效,我相当确定这不是版本问题。我已经检查过 Code Runner 中的编译器是否设置为 3.7.4 64-bit 所以我尝试通过 Python 扩展运行代码,并且它有效,所以我相信这是一个 Code Runner 问题。

很抱歉,很长,但最后,f 字符串没有用红色下划线,它不会出现问题,因此出于某种原因,f 字符串被认为是有效的语法,但不会在只有 Code Runner 扩展。

如何让 Code Runner 接受 f 字符串?

谢谢你的帮助。

附言我认为这无关紧要,但我本可以在一个月前发誓它有效。

最佳答案

关于python - 为什么 VSCode Code Runner 不支持 f-strings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58166910/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com