Python Forum

Full Version: AttributeError: module 'collections' has no attribute 'namedtuple'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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'])
(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.