Re: noob: cyclic import issue

2010-03-29 Thread bruno desthuilliers
On 29 mar, 12:16, vamsy krishna  wrote:


> thnx jonas...i figured datz wat i mite do...

Totally OT, but talking "datz way" won't make you looks "kewl" here.

> so django has a limitation
> on imports like in da case i mentioned?
>

It's not a django limitation, it's a Python one.

Technical point : almost everything happens at runtime in Python. the
'def', 'class' and 'import' statements are executable statements, and
the first import of a given module imply the execution of all top-
level statements in this module. So, if modA has a top-level import
statement referencing modB (directly or indirectly FWIW) and modB
itself has a top-level import statement referencing modA, it just
cannot work, period.

Now this "limitation" is a GoodThing(tm) from a design POV - such
cyclic dependencies are something you want to avoid even in languages
that allow it, because they make for very unmananageable code.

HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: noob: cyclic import issue

2010-03-29 Thread vamsy krishna
thnx jonas...i figured datz wat i mite do...so django has a limitation
on imports like in da case i mentioned?

On Mar 29, 2:51 pm, Jonas Obrist  wrote:
> On 03/29/2010 10:28 AM, vamsy krishna wrote:
>
> > hi...am very new to django and am having some problem with my code...
>
> > say i've two modules...mod1 n mod2...n views in both modules have
> > certain generic functions which i need to import from each other...as
> > in
>
> > (in views.py of mod1)
>
> > from mod2.views import xyz
>
> > (and in views.py of mod2)
>
> > from mod1.views import abc
>
> > and this ofcourse is throwing an import error saying cannot import
> > name xyz...how do i get this working? thanks in advance
>
> I recommend creating an utils.py (or however you want to name that) and
> put 'xyz' and 'abc' in there. Then do:
>
> in mod1.views.py:
>
> from utils import xyz, abc
>
> in mod2.views.py:
>
> from utils import xyz, abc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: noob: cyclic import issue

2010-03-29 Thread Jonas Obrist

On 03/29/2010 10:28 AM, vamsy krishna wrote:

hi...am very new to django and am having some problem with my code...

say i've two modules...mod1 n mod2...n views in both modules have
certain generic functions which i need to import from each other...as
in

(in views.py of mod1)

from mod2.views import xyz

(and in views.py of mod2)

from mod1.views import abc

and this ofcourse is throwing an import error saying cannot import
name xyz...how do i get this working? thanks in advance

   
I recommend creating an utils.py (or however you want to name that) and 
put 'xyz' and 'abc' in there. Then do:


in mod1.views.py:

from utils import xyz, abc

in mod2.views.py:

from utils import xyz, abc

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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.



noob: cyclic import issue

2010-03-29 Thread vamsy krishna
hi...am very new to django and am having some problem with my code...

say i've two modules...mod1 n mod2...n views in both modules have
certain generic functions which i need to import from each other...as
in

(in views.py of mod1)

from mod2.views import xyz

(and in views.py of mod2)

from mod1.views import abc

and this ofcourse is throwing an import error saying cannot import
name xyz...how do i get this working? thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.