On Jan 4, 9:29 pm, Mark Jones <mark0...@gmail.com> wrote:
> For the discussion below, ALL the code is in .../intomec/tenq
>
> I wrote some code in tests.py like so:
>
>    from tenq.models import *
>         self.expectedValue = Answers((1,2,3,4))
>
> within the to_python() method of AnswersField in models.py:
>     def to_python(self, _value):
>         print "_value.__class__ =",_value.__class__
>         if isinstance(_value, Answers):
>             return _value
>
> isinstance(_value, Answers) fails for the object created in tests.py
> because the
>
> >>>_value.__class__ = <class 'intomec.tenq.models.Answers'>
> >>>_value.__class__ = <class 'tenq.models.Answers'>
>
> when I change tests.py to
> from intomec.tenq.models import *
>         self.expectedValue = Answers((1,2,3,4))
>
> I get>>>_value.__class__ = <class 'intomec.tenq.models.Answers'>
> >>>_value.__class__ = <class 'intomec.tenq.models.Answers'>
>
> and isinstance doesn't fail.
>
> What I can't figure out is, why do both imports work, and why do they
> generate different results.  It seems to me the name of the class is
> the name of the class, and either the import should fail or they
> should both yield the same name.
>
> Anyone have any ideas on why this is?  I'm not even sure why the
> second from statement works, since I'm already in the intomec folder
> when I run
>
> python manage.py test

I can't really understand your problem, I'm afraid - in particular I
can't see what is generating those two output lines in either case.
Could you post a bit more code (preferably on dpaste.com)?

In the meantime, the best reference on import (as on many other
intricacies of Python) is the effbot, Frederik Lundh:
http://effbot.org/zone/import-confusion.htm
Does that help answer your question at all?

And to answer your final question, the reason the second import works
is because manage.py adds the parent of the current directory to the
pythonpath automatically.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to