Hi!

I can't try this out at the moment as I don't have access to the code.
But I just thought I'd add the fact that forms.py is never compiled
(no trace of a forms.pyc). Should the __import__ function force the
compilation of a module when it's imported, or does it require that
module to be compiled prior (and if so, how can you force that
compilation)?

On Feb 13, 12:23 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2008-02-12 at 14:12 -0800, Julien wrote:
> > Hi,
>
> > Thanks for the tip. However I still get an ImportError: "No module
> > name MyModel".
>
> > I tried the following:
> > klass = __import__(settings.MY_MODEL_FORM, {}, {}, '')
> > klass = __import__(settings.MY_MODEL_FORM, {}, {}, [''])
> > klass = __import__(settings.MY_MODEL_FORM, globals(),  locals(), [''])
>
> > I even tried to hard code it:
> > klass = __import__("myapp.forms.MyModelForm", {}, {}, [''])
>
> > But I still get that ImportError. What is strange is that if I do:
> > from myapp.forms import MyModelForm
>
> Hmm. Are you perhaps trying to execute this whilst myapp.forms is still
> being imported? For example, something that myapp.forms imports if
> running this line of code? That won't work (until a module is fully
> imported, its name exists in sys.modules to prevent circular imports,
> but the value (module) attached to that name is empty, so you cannot
> access the internals of a module until it's been fully imported).
>
> If that's not the case, can you import 'myapp.forms' using the above
> technique (you're probably right that a list is needed at the end, btw;
> I posted without actually checking too carefully)? What I'm trying to
> work out is where in the dotted import path it all goes wrong.
>
> My first thought was that you didn't have "myapp" on your Python path
> (the parent directory of myapp has to be on the Python path), but that
> would probably generate a message saying it couldn't import "myapp",
> rather than something about "MyModelForm" (guessing; I didn't test it).
>
> So, how far can you get down the import chain here?
>
>         (a) klass = __import__("myapp", {}, {}, [''])
>         (b) klass = __import__("myapp.forms", {}, {}, [''])
>         (c) klass = __import__("myapp.forms", {}, {}, ['MyModelForm'])
>
> None of these are what you want, but it might give some idea as to where
> the problem really lies.
>
> Malcolm
>
> --
> The cost of feathers has risen; even down is 
> up!http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to