python - SyntaxError: f-string: 期待 '}'
问题描述
我这里有问题。
我不知道为什么这段代码不起作用。
newline = '\n'
tasks_choosen = ['markup', 'media', 'python_api', 'script', 'style', 'vue']
print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')
错误:
文件“new-gulp-project.py”,第 85 行
print(f'{ newline }### 使用以下任务初始化项目:{ ' '.join(tasks_choosen) }.{ newline }')
SyntaxError: f-string: 期待 '}'
谁能帮我?
谢谢
解决方案
因为你使用单引号两次你得到:
print(f'{ newline }### Initializing project with the following tasks: { '
而不是
print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')
在里面使用双引号:
print(f'{ newline }### Initializing project with the following tasks: { " ".join(tasks_choosen) }.{ newline }')
推荐阅读
- javascript - 无法统一显示网格
- python - How to load numpy array to gensim Keyedvector format?
- javascript - 正则表达式匹配给定字符串后的文本,不包括字符本身
- wordpress - 如何删除按钮
- javascript - 注意有关滚动滑块的帮助
- omnet++ - OMNET++:无法将 openflow 扩展导入静脉
- c# - WebAPI 返回“堆栈不足,无法继续安全地执行程序。”
- python - 当我构建一个简单的模型时,在 keras 中引发了 InvalidArgumentError
- c# - 在文件返回类型的 MVC 操作中,文件下载在大约 1 分钟后停止
- asp.net-mvc - 如何在 MVC Razor 语法中设置默认图像