Python Forum

Full Version: Problem with importing and using collections module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greatings,

I am a new to python and actually whole concept of programming.

Since last one one month i have been working hard but getting stuck many times because training material i have are from instructors who made it on python 2.

I am learning to create a base file for my games references.

I have import collections module

import collections

then while creating vector i used it

class vector(collection.Sequence)

and now the problem start. whenever i tried using vector class for my game but i have error:

Traceback (most recent call last):
File "d:/pYtHON/Pythongames/base.py", line 18, in <module>
class vector(collection.Sequence):
NameError: name 'collection' is not defined

Please share resolution with little explanation to understand it for future reference. Thank You. Smile
As far as the python interpreter is concerened, collections and collection are two different words.
Hey, thats's what made me confused too.

here is line of codes which my instructor is able to use but not me.
import collection

class vector(collection.sequence):
    PRECISION = 6
    ....
that's creating an error for collection module. please assist.
Again, it's Sequence and not sequence. Also usually one capitalizes class names, so it would be a better style to write class Vector although Python does not enforce this.