如何求解“列表对象没有模型”。 Python的错误?

发布于 2025-01-24 04:26:11 字数 2574 浏览 0 评论 0原文

我一直在尝试制作一个可以使Anki抽认卡的语言制作的抽认卡制造商,但是似乎有一个问题,在将“列表”对象写入文件时,它没有属性'模型' '关于最后一部分的输出。我已经尝试了几件事,但似乎没有使它起作用,现在已经被困了一个星期。有人可以帮我吗?

下面的代码:

# In[1]:


pip install genanki


# In[2]:


pip install dutch_words


# In[3]:


pip install translate


# In[4]:


import genanki


# In[5]:


import dutch_words


# In[6]:


from translate import Translator


# In[7]:


dutchwords = dutch_words.get_ranked()


# In[8]:


translator = Translator(from_lang = "nl", to_lang="en")


# In[9]:


my_model = genanki.Model(
  1607392319,
  'Simple Model',
  fields=[
    {'name': 'Question'},
    {'name': 'Answer'},],  templates=[
    {
      'name': 'Card 1',
      'qfmt': '{{Question}}',
      'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
    },
  ])


# In[10]:


my_deck = genanki.Deck(
  2059400110,
  'Dutch Dictionary')


# In[11]:


mynotes = []
x = 0 
for x in range (10):
 my_note = genanki.Note(
  model=my_model,
  fields=[dutchwords[x], translator.translate(dutchwords[x])]), 
mynotes.append(my_note)

          


# In[12]:


my_deck = genanki.Deck(
  2059400115,
  'Dutch Dictionary')

my_deck.add_note(mynotes)


# In[13]:


genanki.Package(my_deck).write_to_file('DutchDictionary.apkg')

,在运行[13]部分中我会遇到此错误:


AttributeError                            Traceback (most recent call last)
Input In [13], in <cell line: 1>()
----> 1 genanki.Package(my_deck).write_to_file('DutchDictionary.apkg')

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\package.py:40, in Package.write_to_file(self, file, timestamp)
     37   timestamp = time.time()
     39 id_gen = itertools.count(int(timestamp * 1000))
---> 40 self.write_to_db(cursor, timestamp, id_gen)
     42 conn.commit()
     43 conn.close()

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\package.py:60, in Package.write_to_db(self, cursor, timestamp, id_gen)
     57 cursor.executescript(APKG_COL)
     59 for deck in self.decks:
---> 60   deck.write_to_db(cursor, timestamp, id_gen)

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\deck.py:61, in Deck.write_to_db(self, cursor, timestamp, id_gen)
     59 models = json.loads(models_json_str)
     60 for note in self.notes:
---> 61   self.add_model(note.model)
     62 models.update(
     63   {model.model_id: model.to_json(timestamp, self.deck_id) for model in self.models.values()})
     64 cursor.execute('UPDATE col SET models = ?', (json.dumps(models),))

AttributeError: 'list' object has no attribute 'model'

I've been trying to make a flashcard maker which can make lots of language Anki flashcards in one go, but seem to have an issue where when it comes to writing to the file it says ''list' object has no attribute 'model'' on the output of the final section. I've tried a few things but don't seem to get it to work and have now been stuck for a week now. Can somebody help me please?

Code below:

# In[1]:


pip install genanki


# In[2]:


pip install dutch_words


# In[3]:


pip install translate


# In[4]:


import genanki


# In[5]:


import dutch_words


# In[6]:


from translate import Translator


# In[7]:


dutchwords = dutch_words.get_ranked()


# In[8]:


translator = Translator(from_lang = "nl", to_lang="en")


# In[9]:


my_model = genanki.Model(
  1607392319,
  'Simple Model',
  fields=[
    {'name': 'Question'},
    {'name': 'Answer'},],  templates=[
    {
      'name': 'Card 1',
      'qfmt': '{{Question}}',
      'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
    },
  ])


# In[10]:


my_deck = genanki.Deck(
  2059400110,
  'Dutch Dictionary')


# In[11]:


mynotes = []
x = 0 
for x in range (10):
 my_note = genanki.Note(
  model=my_model,
  fields=[dutchwords[x], translator.translate(dutchwords[x])]), 
mynotes.append(my_note)

          


# In[12]:


my_deck = genanki.Deck(
  2059400115,
  'Dutch Dictionary')

my_deck.add_note(mynotes)


# In[13]:


genanki.Package(my_deck).write_to_file('DutchDictionary.apkg')

and I get this error when running the In[13] section:


AttributeError                            Traceback (most recent call last)
Input In [13], in <cell line: 1>()
----> 1 genanki.Package(my_deck).write_to_file('DutchDictionary.apkg')

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\package.py:40, in Package.write_to_file(self, file, timestamp)
     37   timestamp = time.time()
     39 id_gen = itertools.count(int(timestamp * 1000))
---> 40 self.write_to_db(cursor, timestamp, id_gen)
     42 conn.commit()
     43 conn.close()

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\package.py:60, in Package.write_to_db(self, cursor, timestamp, id_gen)
     57 cursor.executescript(APKG_COL)
     59 for deck in self.decks:
---> 60   deck.write_to_db(cursor, timestamp, id_gen)

File ~\anaconda3\envs\pythonProject3\lib\site-packages\genanki\deck.py:61, in Deck.write_to_db(self, cursor, timestamp, id_gen)
     59 models = json.loads(models_json_str)
     60 for note in self.notes:
---> 61   self.add_model(note.model)
     62 models.update(
     63   {model.model_id: model.to_json(timestamp, self.deck_id) for model in self.models.values()})
     64 cursor.execute('UPDATE col SET models = ?', (json.dumps(models),))

AttributeError: 'list' object has no attribute 'model'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文