Skip to content

Files

Latest commit

 

History

History
26 lines (16 loc) · 617 Bytes

File metadata and controls

26 lines (16 loc) · 617 Bytes

Pattern: Assigning lambda to variable

Issue: -

Description

Lambdas should not be assigned to a variable. Instead, they should be defined as functions.

The primary reason for this is debugging. Lambdas show as <lambda> in tracebacks, where functions will display the function's name.

Example of incorrect code:

root = lambda folder_name: os.path.join(BASE_DIR, folder_name)

Example of correct code:

def root(folder_name):
    return os.path.join(BASE_DIR, folder_name)

Further Reading