python - 如何修复 _pickle.PicklingError: can'tpickle : 它不是同一个对象
问题描述
我正在动态生成一些类(附加代码),现在需要腌制它们。但是,我得到 can't pickle 错误,说它不是同一个对象。
import pickle
class TagBase:
pass
class Tags:
container_tmi = "container"
pass
taglist = [attr for attr in dir(Tags) if not callable(
getattr(Tags, attr)) and not attr.startswith("__")]
for _ in taglist:
taginfo = getattr(Tags, _)
globals()[taginfo] = type(taginfo, (TagBase,), {})()
def launcher():
l = [container]
with open("l.pickle", "wb") as fh:
pickle.dump(l, fh)
launcher()
作为一种解决方法,我可能只是编写一个 scipt 来生成类定义而不是动态创建它们,但仍然想知道为什么会出现此错误以及任何可能的修复。
解决方案
推荐阅读
- loadrunner - 在 LOADRunner 中使用公式作为参数
- python - 如何在单个批处理请求中发送多个请求(批处理)
- python - Django PyTests - Visual Studio 代码 - 未发现测试,请检查测试的配置设置
- python - View 没有返回 HttpResponse 对象。它返回无
- java - 如何在 Java Servlet 中跟踪文件下载事件
- python - Python教程中do_global()的作用
- javascript - 意外的 JSON 行为
- javascript - 使用 filesGetThumbnail javascript 获取原始大小的图像
- mysql - 使用嵌套选择计算唯一行 - 帮助我优化
- oop - 多态性 OOP:'child' 的实例没有'basic_attack' memberpylint(无成员)