List Info

Thread: Re: Where to set the cwd?




Re: Where to set the cwd?
user name
2008-02-23 18:35:52
Michael Hipp wrote:

[...]

> But I have lots of "data" files that live in
and around my Django
> code and I have to access with them with stuff like:
>
>     f = open("somedir/myfile.dat", 'r')
>
> So how do I make those lines look like that instead of
having a bunch of 
>   absolute paths stuck in there or lots of messy stuff
with 
> os.path.join(os.path.dirname(__file__)...) in it?

Don't use specific paths throughout your code.  Set
variables in
settings.py and scatter those around.

To avoid the proliferation of os.path.* everywhere, I use
something
like this in my settings files:

  import os
  HOME = os.path.abspath(os.path.dirname(__file__))

  TEMPLATE_DIRS = (
      HOME + "/templates",
  )

  UPLOADS = HOME + "/files"

and so on.

-Drew


--~--~---------~--~----~------------~-------~--~----~
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: Where to set the cwd?
user name
2008-02-23 18:43:37
Drew Raines wrote:
> Michael Hipp wrote:
> 
> [...]
> 
>> But I have lots of "data" files that live
in and around my Django
>> code and I have to access with them with stuff
like:
>>
>>     f = open("somedir/myfile.dat", 'r')
>>
>> So how do I make those lines look like that instead
of having a bunch of 
>>   absolute paths stuck in there or lots of messy
stuff with 
>> os.path.join(os.path.dirname(__file__)...) in it?
> 
> Don't use specific paths throughout your code.  Set
variables in
> settings.py and scatter those around.
> 
> To avoid the proliferation of os.path.* everywhere, I
use something
> like this in my settings files:
> 
>   import os
>   HOME = os.path.abspath(os.path.dirname(__file__))
> 
>   TEMPLATE_DIRS = (
>       HOME + "/templates",
>   )
> 
>   UPLOADS = HOME + "/files"
> 
> and so on.

Me like. Thanks.

Michael

--~--~---------~--~----~------------~-------~--~----~
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-2]

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