Newbie question - array module/fromlist method

Jeff Epler jepler at unpythonic.net
Thu Feb 20 14:39:22 EST 2003


fromlist is a method of an array object, not a function of the array
module.

    >>> import array
    >>> array.fromlist
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      AttributeError: 'module' object has no attribute 'fromlist'
    >>> array.array('i').fromlist
    <built-in method fromlist of array.array object at 0x40063218>
    >>> 

If fromlist() was a function, or a class/static method, it would have no
way to know what type of array to create and return.  by saying
    >>> array.array('i').fromlist(l
you can get an array of the desired numeric type.

Of course,
    >>> array.fromlist('i', l)
might make a nice shorthand for this.

Jeff





More information about the Python-list mailing list