Python Forum
AttributeError: module 'collections' has no attribute 'namedtuple' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: AttributeError: module 'collections' has no attribute 'namedtuple' (/thread-26520.html)



AttributeError: module 'collections' has no attribute 'namedtuple' - epgs1975 - May-04-2020

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.


RE: AttributeError: module 'collections' has no attribute 'namedtuple' - buran - May-04-2020

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'])



RE: AttributeError: module 'collections' has no attribute 'namedtuple' - epgs1975 - May-04-2020

(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.