python - 在 python 中使用 exec() 运行具有字典语法的字符串
问题描述
txt_cmd = f"output_{oem_alias}_.rename(columns = {'code_tagic':'code_pred'},inplace=True)";exec(txt_cmd)
尝试在 exec 中将字典作为字符串执行,我得到的错误如下图所示。
解决方案
txt_cmd = f"output_{oem_alias}_.rename(columns = {'{'}'code_tagic':'code_pred'{'}'},inplace=True)";exec(txt_cmd)
只需尝试使用{'{'}
for {
& {'}'} 来解决}
这个问题,特别是在字典中使用。
推荐阅读
- html - 如何从 html 表单读取输入到 python 脚本?
- javascript - removing specific element from array Javascript
- reactjs - 如何在日历中呈现标记日期?
- javascript - 有没有办法在 Vue JS 的列表渲染(v-for)中使用条件渲染
- user-interface - 如何创建独特的 TextBox 设计
- php - 我正在部署我的 symfony 5 应用程序。我忘了做什么?
- python - python3:为什么 __init__ 方法中的 for 循环没有执行?
- java - 无法授权使用 Google api 客户端访问 Hangout 聊天 api
- angular - 使用 ngx-device-detector,出现错误 - 类型“ModuleWithProviders”不是通用的
- html - 如何修复 select2 的占位符在文档准备好时被截断?