Python Forum
AttributeError: module 'collections' has no attribute 'namedtuple'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: module 'collections' has no attribute 'namedtuple'
#1
i am starting in python. in my command prompt, py gives the following
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32

i have a code with these two lines

import collections
collections.namedtuple('Card', ['rank', 'suit'])
then i get this error
AttributeError: module 'collections' has no attribute 'namedtuple'

this clearly appears to be a beginner issue. i have spent some time online to get past this issue.
Reply
#2
do you have collections.py file? If yes - rename it.
Also, please always post full traceback, not just the last line.
As a note, it's not the cause of the error, but line#2 will do nothing, even when you resolve the issue
it should be something like
Card = collections.namedtuple('Card', ['rank', 'suit'])
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(May-04-2020, 08:02 PM)buran Wrote: do you have collections.py file? If yes - rename it.
Also, please always post full traceback, not just the last line.
As a note, it's not the cause of the error, but line#2 will do nothing, even when you resolve the issue
it should be something like
Card = collections.namedtuple('Card', ['rank', 'suit'])

Yes, I had a collections.py. good lesson learned. renaming it solved the issue.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 721 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,533 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,668 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,216 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,303 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,738 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 7,000 Jul-06-2022, 10:55 AM
Last Post: deanhystad
  AttributeError: 'numpy.int32' object has no attribute 'split' rf_kartal 6 4,202 Jun-24-2022, 08:37 AM
Last Post: Anushka00
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,721 Apr-27-2022, 09:27 AM
Last Post: Anldra12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020