Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am having a problems with collections and tuples in Python v 3.3.2

Tags:

python

tuples

I am using the namedtuple with the collections. i am getting this error

NameError: name collections is not defined.  

I am using Python v 3.3.2. Any help would be very appreciated

[for Example] I am getting error on this line

Sale = collection.namedtuple("Sale","productid custerid date price")
like image 295
user3076828 Avatar asked Sep 19 '25 01:09

user3076828


1 Answers

Did you import collections module? The module name is collections, not collection.

>>> Sale = collection.namedtuple("Sale","productid custerid date price")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'collection' is not defined
>>>
>>> import collection
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named collection
>>>
>>> import collections
>>> Sale = collections.namedtuple("Sale","productid custerid date price")
like image 166
falsetru Avatar answered Sep 20 '25 16:09

falsetru