0

When I define a class in function that use function's params, throw NameError: name 'x' is not defined.

def foo(x):
  class Meta:
    x = x

foo(1)

# throw NameError
NameError: name 'x' is not defined
Horia Coman
  • 8,681
  • 2
  • 23
  • 25
Dong
  • 33
  • 1
  • 7

1 Answers1

2

Your field x inside the class is masking the parameter x from the function.

def foo(x):
  class Meta:
    y = x

foo(1)

will stop giving you this error.

The question is poorly written (there is not even a question), so I might have misunderstood you.

Lucas Araujo
  • 453
  • 4
  • 14