List Info

Thread: Applications imports best practices ?




Applications imports best practices ?
country flaguser name
France
2007-05-30 20:00:50
Hi list,

What is the proper way to import modules within an
application ? For  
example if I have a project "foo" containing an
application "bar",  
how should I import things in bar's modules ?

1. import foo.bar.module
the source code has to be modified when using bar in another
project

2. import bar.module
the application is more portable, but its path has to be
included in  
PYTHON_PATH (at least under mod_python)

I feel like I am missing a more elegant solution 

Luper

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Applications imports best practices ?
user name
2007-05-30 20:29:51
On 5/30/07, Luper Rouch <luper.rouchgmail.com> wrote:
> 2. import bar.module
> the application is more portable, but its path has to
be included in
> PYTHON_PATH (at least under mod_python)

I generally opt for this one, but with one caveat: I almost
*never*
place applications directly inside the project directory.
It's true
that the tutorial involves an app that's created inside the
project
directory, and that's useful for giving a quick introduction
to Django
(and hence for the tutorial), but once you're writing
multiple
applications which may be shared among multiple projects,
having the
applications be "independent" and live somewhere
directly on the
Python path (say, in site-packages or a similar location
local to your
user account) is far more useful and encourages looser
coupling. It
also has the helpful side effect of removing any questions
about how
to handle imports 

-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Applications imports best practices ?
user name
2007-05-30 21:29:57
>What is the proper way to import modules within an application ? For
>example if I have a project "foo&quot; containing an application "bar&quot;,
>how should I import things in bar's modules ?

Great question!&nbsp; This is a problem that I've thought about as well. ; I am very interested in what more experienced django users have to say.

>I feel like I am missing a more elegant solution

I agree, both scenarios seem to couple the application with either the project or the environment.

--
J.P.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users"; group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to django-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: Applications imports best practices ?
user name
2007-05-31 06:30:00
> 2. import bar.module
> the application is more portable, but its path has to
be included in
> PYTHON_PATH (at least under mod_python)

A simpler variation of this is, "put it in your
PYTHON_PATH".
Personally, I have found this the easiest way to both
maintain apps
and deploy them.

-- 
     -Ben

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )