Problem/bug with class definition inside function definition

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue May 8 02:07:52 EDT 2018


Python 3.5.1 (default, Jun  1 2016, 13:15:26)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> def f(a):
...  class D:
...   pass
...  D.a = a
...  return D
...
 >>> c = f(42)
 >>> c
<class '__main__.f.<locals>.D'>
 >>> c.a
42

-- 
Greg



More information about the Python-list mailing list