Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is id a python builtin function?

Would you please look at code below,

def getCrewListAll(self):
    """
    Set to crew list to all available crew
    """
    crew = getIdNumbers()
    return map(lambda cr: cr.id, crew)

What is the meaning of cr.id here, is id a builtin python function or?

like image 614
alwbtc Avatar asked Dec 05 '25 19:12

alwbtc


1 Answers

In your example, the reference to cr.id is not a function call. Its accessing a member attribute of the cr variable, which is a placeholder for whatever the crew objects are.

id is the name of a builtin function, yes. But there is no way to know if its being used under the hood in these objects without seeing the actual class definitions.

As an example... if this were, say, a django application, model instances have id member attributes that give you the database id of that record. Its part of the design of the class for that framework.

Even though I am assuming its an attribute... for all we know it could also be a computed property which is similar to a method call that acts like an attribute. It could be doing more logic that it seems when looking at your example.

Lastly, since the cr.id could be anything, it could even be a method and the map is returning a lis of callables: cr.id()

like image 89
jdi Avatar answered Dec 09 '25 19:12

jdi