FAQ
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?


Also, what is PEP, PEP8, etc? Is it like the Python programming layout conventions? Is there more to it than that?


Thanks!

Search Discussions

  • Andrew Berg at Nov 25, 2013 at 9:10 pm

    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
  • Mark Lawrence at Nov 25, 2013 at 9:20 pm

    On 25/11/2013 20: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?

    Take a look here
    http://docs.python.org/3/library/os.html#process-parameters,
    specifically os.environ.

    Also, what is PEP, PEP8, etc? Is it like the Python programming layout conventions? Is there more to it than that?

    PEP stands for Python Enhancement Proposal, please see
    http://www.python.org/dev/peps/ PEP8 is the style guide for Python code.


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Eamonn Rea at Nov 26, 2013 at 6:09 pm
    Thanks for the help on PEP, but I can't find a way to get the application support (appdata on Windows, no idea on Linux). If I do:


    print os.environ['HOME']


    I get: '/Users/eamonn', as that is my home directory. But when I do:


    print os.environ['APPDATA']


    I get an error. But when I do:


    print os.getenv('APPDATA')


    I get: None.


    Apparently os.getenv() works on Windows, but I can't see a way to get this on Mac. If I could get the names of this for different OS's I could just check the OS and run the appropriate code.


    Any help?
  • Irmen de Jong at Nov 26, 2013 at 7:40 pm

    On 26-11-2013 19:09, Eamonn Rea wrote:
    Thanks for the help on PEP, but I can't find a way to get the application support (appdata on Windows, no idea on Linux). If I do:

    print os.environ['HOME']

    I get: '/Users/eamonn', as that is my home directory. But when I do:

    print os.environ['APPDATA']

    I get an error. But when I do:

    print os.getenv('APPDATA')

    I get: None.

    Apparently os.getenv() works on Windows, but I can't see a way to get this on Mac. If I could get the names of this for different OS's I could just check the OS and run the appropriate code.

    Any help?



    Maybe this module is of some use to you:
    https://pypi.python.org/pypi/appdirs


    It provides a unified Python API to the various OS specific 'user' directory locations.


    Irmen
  • Eamonn Rea at Nov 26, 2013 at 10:49 pm

    On Tuesday, November 26, 2013 7:40:50 PM UTC, Irmen de Jong wrote:
    On 26-11-2013 19:09, Eamonn Rea wrote:

    Thanks for the help on PEP, but I can't find a way to get the application support (appdata on Windows, no idea on Linux). If I do:

    print os.environ['HOME']

    I get: '/Users/eamonn', as that is my home directory. But when I do:

    print os.environ['APPDATA']

    I get an error. But when I do:

    print os.getenv('APPDATA')

    I get: None.

    Apparently os.getenv() works on Windows, but I can't see a way to get this on Mac. If I could get the names of this for different OS's I could just check the OS and run the appropriate code.

    Any help?




    Maybe this module is of some use to you:

    https://pypi.python.org/pypi/appdirs



    It provides a unified Python API to the various OS specific 'user' directory locations.



    Irmen

    I saw this, but I wanted to do it myself as I stated in the OP :)
  • Chris Angelico at Nov 26, 2013 at 11:20 pm

    On Wed, Nov 27, 2013 at 9:49 AM, Eamonn Rea wrote:
    Maybe this module is of some use to you:
    https://pypi.python.org/pypi/appdirs

    It provides a unified Python API to the various OS specific 'user' directory locations.
    I saw this, but I wanted to do it myself as I stated in the OP :)

    You could read the module's source code - that's one of the coolest
    benefits of open source, you can learn from someone else's
    implementation.


    Your posts, your replies particularly, are showing the
    increasingly-annoying fingerprints of Google Groups. Look at how they
    appear to us:


    https://mail.python.org/pipermail/python-list/2013-November/661217.html


    Note the double-spaced quoted text, and the unwrapped lines. Please do
    not use Google Groups, as it's nearly impossible to use without
    creating obnoxious posts.


    ChrisA
  • Mark Lawrence at Nov 26, 2013 at 11:21 pm

    On 26/11/2013 22:49, Eamonn Rea wrote:
    On Tuesday, November 26, 2013 7:40:50 PM UTC, Irmen de Jong wrote:
    On 26-11-2013 19:09, Eamonn Rea wrote:

    Thanks for the help on PEP, but I can't find a way to get the application support (appdata on Windows, no idea on Linux). If I do:

    print os.environ['HOME']

    I get: '/Users/eamonn', as that is my home directory. But when I do:

    print os.environ['APPDATA']

    I get an error. But when I do:

    print os.getenv('APPDATA')

    I get: None.

    Apparently os.getenv() works on Windows, but I can't see a way to get this on Mac. If I could get the names of this for different OS's I could just check the OS and run the appropriate code.

    Any help?




    Maybe this module is of some use to you:

    https://pypi.python.org/pypi/appdirs



    It provides a unified Python API to the various OS specific 'user' directory locations.



    Irmen
    I saw this, but I wanted to do it myself as I stated in the OP :)

    Do you realise that stock markets wordwide have plumetted again today
    because of the massive surplus of newlines from this year's harvests?
    The only way to get the markets back up, and with it my pension funds,
    is to invest very heavily in a tool that somehow prevents this surplus.
       Would you be kind enough to get one?


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Eamonn Rea at Nov 28, 2013 at 4:11 pm
    Oh, sorry, I'm new to how Google Groups works. I wonder why it lays it out like that. Can it not just show quotes like the way that PHPbb does?


    I never thought of reading the source code, thanks! :-)


    Oh, and the last message is just spam :P
  • Chris Angelico at Nov 28, 2013 at 5:28 pm

    On Fri, Nov 29, 2013 at 3:11 AM, Eamonn Rea wrote:
    Oh, sorry, I'm new to how Google Groups works. I wonder why it lays it out like that. Can it not just show quotes like the way that PHPbb does?

    Google Groups is just a newsgroup client (and one of the worst in the
    world, imho). Ultimately, what you're reading and writing is netnews
    and a mailing list (the two are automatically linked, anything sent to
    either gets copied to the other). It's fundamentally plain text, not
    HTML and not PHPBB.


    I recommend signing up for the mailing list, rather than using GG.


    https://mail.python.org/mailman/listinfo/python-list


    There are ways to use GG without it being quite as obnoxious as it
    usually is, but it's a lot more work than just using a better
    interface.


    ChrisA
  • Rusi at Nov 28, 2013 at 6:32 pm

    On Thursday, November 28, 2013 9:41:30 PM UTC+5:30, Eamonn Rea wrote:
    Oh, sorry, I'm new to how Google Groups works. I wonder why it lays it out like that. Can it not just show quotes like the way that PHPbb does?

    I never thought of reading the source code, thanks! :-)

    Oh, and the last message is just spam :P

    Here's a solution
    https://groups.google.com/forum/#!topic/comp.lang.python/H4NZPk1HqbI


    You can skip the initial emacs suggestion and jump to the pure python one
    at end -- 18th post or so.
  • Kevin Walzer at Dec 2, 2013 at 2:39 pm

    On 11/26/13, 5:49 PM, Eamonn Rea wrote:
    Maybe this module is of some use to you:
    https://pypi.python.org/pypi/appdirs



    It provides a unified Python API to the various OS specific 'user' directory locations.



    Irmen
    I saw this, but I wanted to do it myself as I stated in the OP:)

    This module appears to simply use hard-coded paths on Unix/Linux and OS
    X--not much to learn there, except which paths to code.


    --Kevin


    --
    Kevin Walzer
    Code by Kevin/Mobile Code by Kevin
    http://www.codebykevin.com
    http://www.wtmobilesoftware.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 25, '13 at 8:48p
activeDec 2, '13 at 2:39p
posts12
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase