0

When using the python interpreter I try and use an imported class within a class, and get a NameError. However, when using it outside the class, I get no error. The code works fine in the file in which it ran, but could someone explain this behaviour please?

    In [27]: class DataSheet(factory.DjangoModelFactory):
                    FACTORY_FOR = A.B.C
                    FACTORY_DJANGO_GET_OR_CREATE = ('title',)
                    <other_fields>
      ....:     
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    ~/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
    ----> 1 class DataSheet(factory.DjangoModelFactory):
          2         FACTORY_FOR = A.B.C
          3         FACTORY_DJANGO_GET_OR_CREATE = ('title',)
          4 ...         

    ~/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in DataSheet()
          1 class DataSheet(factory.DjangoModelFactory):
    ----> 2         FACTORY_FOR = A.B.C
          3         # Equivalent to ``FACTORY_FOR = myapp.models.User``
          4         FACTORY_DJANGO_GET_OR_CREATE = ('title',)
          5         

    NameError: name 'A' is not defined

    In [30]: A.D()
    Out[30]: 
   [ <products.Folder instance at 0x32594d0>,
     <products.Folder instance at 0x3259560>,
     <products.Folder instance at 0x30d25f0>]

And yes, the comment below is apt -- I'm using Django 1.4.11

David Boshton
  • 2,555
  • 5
  • 30
  • 51

0 Answers0