Skip to content

Naming collision between Processing map() and Python map() #131

@SableRaf

Description

@SableRaf

Trying to port the array example (See issue: Port Basics / Arrays / Array #3) and I'm running into this error:

coswave = [abs(cos(map(i, 0, width, 0, pi))) for i in range(width)]
                       ~~~^^^^^^^^^^^^^^^^^^^^
TypeError: 'int' object is not iterable

I suppose this is because Python has its own map() function (a list transformation) different from the map() function in Processing (a linear interpolation function).

Processing.py handles this by wrapping map() and dispatching based on the arguments (see source code). It uses the Processing version when called with five numeric arguments, and otherwise falls back to Python’s built-in. Note: the same approach is used for filter().

By contrast, py5 avoids the conflict by renaming the function to remap() instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions