You can also do this:
import importlib
module_name, name = path.rsplit('.', 1)
return getattr(importlib.import_module(module_name), name)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails fr
Just thought you might get a kick out of the fact that I just found this
very useful – 4 years later. Thanks.
On Tuesday, February 12, 2008 7:27:45 PM UTC-8, Julien wrote:
>
> Great! Thanks a lot, it worked!
>
> Here's a little function that I made and that is quite helpful:
>
> def get_class(c
Great! Thanks a lot, it worked!
Here's a little function that I made and that is quite helpful:
def get_class(class_path):
i = class_path.rfind('.')
module_path, class_name = class_path[:i], class_path[i+1:]
module = __import__(module_path, globals(), locals(),
[class_name])
retu
On Tue, 2008-02-12 at 18:30 -0800, Julien wrote:
> Hello,
>
> The module was not compiled, because it was the __import__ function
> itself that raised an exception and so didn't have the chance to do
> the compilation.
>
> As you've suggested, I tried:
>
> klass = __import__("myapp", {}, {}, [
Hello,
The module was not compiled, because it was the __import__ function
itself that raised an exception and so didn't have the chance to do
the compilation.
As you've suggested, I tried:
klass = __import__("myapp", {}, {}, [''])
-> Works, returns
klass = __import__("myapp.forms", {}, {}, [
On Tue, 2008-02-12 at 17:41 -0800, Julien wrote:
> 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
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 compi
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 =
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 e
On Tue, 2008-02-12 at 06:08 -0800, Julien wrote:
> Oh, I see!! Thanks for the explanation.
>
> So, what I'm trying to achieve is to specify a model class as a
> setting that can be used in some views.
>
> As you've said, doing "from myapp.forms import MyModelForm" is not
> possible, so I tried:
Oh, I see!! Thanks for the explanation.
So, what I'm trying to achieve is to specify a model class as a
setting that can be used in some views.
As you've said, doing "from myapp.forms import MyModelForm" is not
possible, so I tried:
MY_MODEL_FORM = 'myapp.forms.MyModelForm'
And then, in some v
On Tue, 2008-02-12 at 05:35 -0800, Julien wrote:
> Hi there,
>
> I'm trying import a class definition in settings.py with:
> from myapp.models import MyModel
Oh, don't do that. Very bad. :-(
Importing models means they start to get registered with the app_cache
(to track reverse relations, amo
Hi there,
I'm trying import a class definition in settings.py with:
from myapp.models import MyModel
But the compilation fails and I get the following error in the
console:
"Error: Can't find the file 'settings.py' in the directory containing
'E:\\workspace\\myproject\\manage.py'. It appears you
13 matches
Mail list logo