- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
: attribute lookup "a class"on __main__ failed-6ren"> : attribute lookup "a class"on __main__ failed-import pickle class NoClass(): def __init__(self, name, level, cls, time_played): self.n-6ren">
import pickle
class NoClass():
def __init__(self, name, level, cls, time_played):
self.name = name
self.level = level
self.cls = cls
self.time_played = time_played
def Write_char_file(registered_username):
avatar = NoClass('',1,'',0) #--------i am trying to pickle and write this
a = str('Characters\%s.txt' % registered_username) #---- the saving file
f = open(a, 'wb')
f.write(pickle.dumps(avatar))
f.close()
def Asign_to_slot(char_lst):
pass
Asign_to_slot(Write_char_file('my_name'))
When trying to run this in bge it raises that error BUT when i run it with python IDLE there isn't a problem and i manage to write the pickled class in the file though i know classes usually can't be pickled then i even manage to open the file, unpickle it and print the class' attributes
"_pickle.PicklingError: Can't pickle <class '__main__.NoClass'>: attribute lookup NoClass on __main__ failed"
最佳答案
由于这在 blender 中运行时有效并且仅在游戏引擎中失败,我认为这与游戏引擎 python 绑定(bind)中的优化有关。
在 handling stateful objects 之后示例和添加自定义 __getstate__
也失败,表明游戏引擎可能实现自定义 __slots__
仅提供最小的功能集。
解决方案似乎是直接 pickle 对象 __dict__
,然后您还需要 unpickle 到新实例 __dict__
。
f.write(pickle.dumps(avatar.__dict__))
关于Python - Blender Game Engine : _pickle. PicklingError: Can't pickle <class '__main__."a class "'>: attribute lookup "a class"on __main__ failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51235713/
我正在使用这个 python 代码 import _pickle 我得到一个 ImportError: No module named _pickle 但我无法使用 conda 或 pip insta
当使用空集成员 participants 对 EventFrame 的对象(列表)进行 pickle 时,我遇到了类似 UnicodeDecodeError 的异常。 class EventFrame
我正在尝试应用 _pickle 将数据保存到磁盘上。但是调用_pickle.dump的时候报错了 OverflowError: cannot serialize a bytes object larg
我正在使用 python3.6/。我使用 protocol=pickle.HIGHEST_PROTOCOL pickle 了我的文件 当我按如下方式加载时: with open('data.sav',
我有this pickle 文件,我正尝试使用以下 Python 脚本解开它: import _pickle as pickle pickle_file = open('bof.pkl', 'rb')
我有一个文本文件,我正尝试使用 python pickle 来挑选它。 tx b'88877343430010000000000' tx b'59343410000000000' rx b'34445
我有一个 doc2vec 模型来驱动我的推荐应用程序。我已经构建了 doc2vec 模型并保存到 s3 存储桶中。现在,当我打开 webapp 时,模型应该从 s3 加载回来,但这不会发生。我使用 A
我正在尝试将 5000 个数据元素存储在一个数组中。这 5000 个元素存储在现有文件中(因此它不是空的)。 但是我遇到了一个错误。 输入: def array(): name = 'punt
我想使用 Kafka 和 Spark 进行情感分析。我想要做的是从 Kafka 读取流数据,然后使用 Spark 对数据进行批处理。之后,我想使用我使用 Tensorflow 制作的函数情绪预测()来
我有一个很大的句子列表(约 700 万个),我想从中提取名词。 我使用 joblib 库来并行化提取过程,如下所示: import spacy from tqdm import tqdm from j
我正在尝试运行 PythonVirtualenvOperator在dag内在 gcloud composer环境,但在创建虚拟环境时收到错误。谷歌搜索让我找到了https://github.com/u
我正在尝试运行以下报告与其他用户一起运行良好的代码,但我发现了这个错误。 -- 编码:utf-8 -- 导入东西 import torch import torch.nn as nn import t
尝试通过 Spark-Submit 或 Zeppelin 运行某些代码时出现以下错误:“_pickle.PicklingError: __ newobj __ args 中的 args[0] 具有错误
import pickle class NoClass(): def __init__(self, name, level, cls, time_played): self.n
我是一名优秀的程序员,十分优秀!