Finding where to store application data portably

Ron Adam rrr at ronadam.com
Thu Sep 22 19:30:14 CEST 2005


Steve Holden wrote:

> Ron Adam wrote:
> 
>> Tony Houghton wrote:
>>
>>> I'm using pygame to write a game called Bombz which needs to save some
>>> data in a directory associated with it. In Unix/Linux I'd probably use
>>> "~/.bombz", in Windows something like
>>> "C:\Documents And Settings\<user>\Applicacation Data\Bombz".
>>>
>>> There are plenty of messages in the archives for this group about how to
>>> find the correct location in Windows, but what about Mac OS? There I
>>> don't know the correct location for this sort of thing at all. And there
>>> are other, more obscure systems like RISC OS (it may not have pygame but
>>> it definitely has python). Surely this is something that's crying out
>>> for an official function in os or sys.
>>
>>
>>
>>
>> This works on Win XP.  Not sure if it will work on Linux.
>>
>> import os
>>
>> parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0]
>> file = parent + os.sep + '.bombz'
>>
>> Cheers,
>> Ron
>>
> Since you've gone to the trouble to use os.path functions why not use
> 
>     file = os.path.join(parent, 'bombz')

It just didn't come to mind first.  I don't use os.path that often.

Thanks. :-)


> regards
>  Steve



More information about the Python-list mailing list