Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60454

Re: Getting the Appdata Directory with Python and PEP?

Date 2013-11-25 15:10 -0600
From Andrew Berg <robotsondrugs@gmail.com>
Subject Re: Getting the Appdata Directory with Python and PEP?
References <50402350-c9cb-47be-b513-ad2fb7170187@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3195.1385413849.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2013.11.25 14:48, Eamonn Rea wrote:
> I've heard that there is a library that allows you to get the appdata directory for a given OS, but I'd like to do it myself, as a learning experience.
> 
> Is there a built in way to get a users Appdata Directory? For example on OS X it's in '~/Library//Application Support/'. I can get the OS just fine (sys.platform and then storing it in my own way; example: darwin = OS X, just for my own readability), and I can get the home directory just fine (expanduser), but I have no idea how to get the appdata directory.
> 
> One way I could think of doing it would be to just detect the os and join the string on like so (completely untested, but an idea);
> 
> if os == 'OS X':
>     appdata_dir = os.path.join(home_dir, '/Application Support/')
> 
> But then that arises the problem of cross platform compatibility.
> 
> So is here a good, cross platform solution to this problem?
I don't know about OS X, but on Windows Vista and later, there is os.environ['APPDATA']. I don't explicitly check for OS; instead, I see if
APPDATA exists as an environment variable:
try:
        user_data_dir = os.path.join(os.environ['APPDATA'], 'NoiseBot')
except KeyError:
        user_data_dir = os.path.join(os.environ['HOME'], '.NoiseBot')

I didn't even know that such a thing existed on OS X.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 10.0

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Getting the Appdata Directory with Python and PEP? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-25 12:48 -0800
  Re: Getting the Appdata Directory with Python and PEP? Andrew Berg <robotsondrugs@gmail.com> - 2013-11-25 15:10 -0600
  Re: Getting the Appdata Directory with Python and PEP? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-25 21:20 +0000
  Re: Getting the Appdata Directory with Python and PEP? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-26 10:09 -0800
    Re: Getting the Appdata Directory with Python and PEP? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-26 13:52 -0500
    Re: Getting the Appdata Directory with Python and PEP? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-11-26 20:40 +0100
      Re: Getting the Appdata Directory with Python and PEP? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-26 14:49 -0800
        Re: Getting the Appdata Directory with Python and PEP? Chris Angelico <rosuav@gmail.com> - 2013-11-27 10:20 +1100
          Re: Getting the Appdata Directory with Python and PEP? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-28 08:11 -0800
            Re: Getting the Appdata Directory with Python and PEP? Chris Angelico <rosuav@gmail.com> - 2013-11-29 04:28 +1100
            Re: Getting the Appdata Directory with Python and PEP? rusi <rustompmody@gmail.com> - 2013-11-28 10:32 -0800
            Re: Getting the Appdata Directory with Python and PEP? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-28 16:29 -0500
        Re: Getting the Appdata Directory with Python and PEP? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-26 23:21 +0000
        Re: Getting the Appdata Directory with Python and PEP? Kevin Walzer <kw@codebykevin.com> - 2013-12-02 09:39 -0500

csiph-web