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


Groups > comp.lang.python > #60451 > unrolled thread

Getting the Appdata Directory with Python and PEP?

Started byEamonn Rea <eamonnrea@gmail.com>
First post2013-11-25 12:48 -0800
Last post2013-12-02 09:39 -0500
Articles 14 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  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

#60451 — Getting the Appdata Directory with Python and PEP?

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-25 12:48 -0800
SubjectGetting the Appdata Directory with Python and PEP?
Message-ID<50402350-c9cb-47be-b513-ad2fb7170187@googlegroups.com>
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!

[toc] | [next] | [standalone]


#60454

FromAndrew Berg <robotsondrugs@gmail.com>
Date2013-11-25 15:10 -0600
Message-ID<mailman.3195.1385413849.18130.python-list@python.org>
In reply to#60451
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

[toc] | [prev] | [next] | [standalone]


#60455

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-11-25 21:20 +0000
Message-ID<mailman.3196.1385414435.18130.python-list@python.org>
In reply to#60451
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

[toc] | [prev] | [next] | [standalone]


#60531

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-26 10:09 -0800
Message-ID<27870dae-87ff-4435-a2ff-a42f95c21d48@googlegroups.com>
In reply to#60451
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?

[toc] | [prev] | [next] | [standalone]


#60534

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-11-26 13:52 -0500
Message-ID<mailman.3253.1385491930.18130.python-list@python.org>
In reply to#60531
On Tue, 26 Nov 2013 10:09:11 -0800 (PST), Eamonn Rea <eamonnrea@gmail.com>
declaimed the following:

>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.
>

	APPDATA is a Windows conceit...

	My impression is that UNIX/Linux relies upon dot-directories
(file/directory names beginning with a . being automatically hidden).

~/.myAppData

and ~ expanding to the login home directory...



	Note that my Windows system doesn't /have/ a HOME variable


C:\Users\Wulfraed\Documents>set appdata
APPDATA=C:\Users\Wulfraed\AppData\Roaming

C:\Users\Wulfraed\Documents>set home
HOMEDRIVE=C:
HOMEPATH=\Users\Wulfraed

C:\Users\Wulfraed\Documents>set userprofile
USERPROFILE=C:\Users\Wulfraed

C:\Users\Wulfraed\Documents>

The closest is USERPROFILE (which is initially %HOMEDRIVE%%HOMEPATH%)

C:\Users\Wulfraed\Documents>echo %userprofile%
C:\Users\Wulfraed

C:\Users\Wulfraed\Documents>echo %homedrive%%homepath%
C:\Users\Wulfraed


PowerShell, OTOH

PS C:\Users\Wulfraed\Documents> Get-Variable home

Name                           Value
----                           -----
HOME                           C:\Users\Wulfraed
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#60536

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2013-11-26 20:40 +0100
Message-ID<5294f942$0$16012$e4fe514c@news.xs4all.nl>
In reply to#60531
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

[toc] | [prev] | [next] | [standalone]


#60543

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-26 14:49 -0800
Message-ID<2b6c4be1-e23f-488b-b64d-191d625dee46@googlegroups.com>
In reply to#60536
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 :)

[toc] | [prev] | [next] | [standalone]


#60551

FromChris Angelico <rosuav@gmail.com>
Date2013-11-27 10:20 +1100
Message-ID<mailman.3262.1385508034.18130.python-list@python.org>
In reply to#60543
On Wed, Nov 27, 2013 at 9:49 AM, Eamonn Rea <eamonnrea@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#60702

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-28 08:11 -0800
Message-ID<b69e5ab0-9871-47b5-95d6-d59724289313@googlegroups.com>
In reply to#60551
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

[toc] | [prev] | [next] | [standalone]


#60714

FromChris Angelico <rosuav@gmail.com>
Date2013-11-29 04:28 +1100
Message-ID<mailman.3368.1385659694.18130.python-list@python.org>
In reply to#60702
On Fri, Nov 29, 2013 at 3:11 AM, Eamonn Rea <eamonnrea@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#60722

Fromrusi <rustompmody@gmail.com>
Date2013-11-28 10:32 -0800
Message-ID<351895a9-cf56-493b-acd4-e2a48ce6cf07@googlegroups.com>
In reply to#60702
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.

[toc] | [prev] | [next] | [standalone]


#60732

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-11-28 16:29 -0500
Message-ID<mailman.3378.1385674170.18130.python-list@python.org>
In reply to#60702
On Thu, 28 Nov 2013 08:11:30 -0800 (PST), Eamonn Rea <eamonnrea@gmail.com>
declaimed the following:

>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 works well as long as the messages stay on GG...

	It's what it does when translating between GG's HTML and the rest of
the world using NNTP/SMTP standards that causes the problems.

	SMTP/NNTP standards recommend lines of <80 characters (Hollerith punch
card/old teletype/terminal physical limit). MIME Quoted-Printable permits
virtual long lines by 1) message header identifying QP format, 2) using an
=<newline> to break the long line into shorter segments. Clients would
remove the =<newline> and unwrap the longer line.

	GG /appears/ to be replacing new-lines with HTTP <P> markers for
received messages. The problem is that on output back to the net, it seems
to then replace the <P> with TWO new-lines (ie; puts in a blank line
between every original line). And since it treats everything one enters as
an HTML <P>, it is sending paragraphs as one line of text.

	PHPbb would have to go through hoops too, to transfer messages from its
internal format (HTML) to non-HTML NNTP/SMTP format.

	GG's change (sometime last year as I recall) simplified the web-based
handling of its messages -- at the cost of trashing classical Usenet and
Mailing lists that it cross-links.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#60552

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-11-26 23:21 +0000
Message-ID<mailman.3263.1385508104.18130.python-list@python.org>
In reply to#60543
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

[toc] | [prev] | [next] | [standalone]


#60868

FromKevin Walzer <kw@codebykevin.com>
Date2013-12-02 09:39 -0500
Message-ID<l7i636$9am$1@dont-email.me>
In reply to#60543
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web