From 44ce5a1bd3d0752ea9ede305d5436a1972dd7fb6 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 12 May 2010 14:29:57 -0400 Subject: [PATCH] more fiddling --- comprehensions.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comprehensions.html b/comprehensions.html index c10632c..70f0f43 100644 --- a/comprehensions.html +++ b/comprehensions.html @@ -79,7 +79,7 @@ body{counter-reset:h1 3} c:\Users\pilgrim\diveintopython3\examples\humansize.py
  1. The os.path.join() function constructs a pathname out of one or more partial pathnames. In this case, it simply concatenates strings. -
  2. In this slightly less trivial case, join will add an extra slash to the pathname before joining it to the filename. It’s a backslash instead of a forward slash, because I constructed this example on Windows. If you replicate this example on Linux or Mac OS X, you’ll see a forward slash instead. Don’t fuss with slashes; always use os.path.join() and let Python do the right thing. +
  3. In this slightly less trivial case, calling the os.path.join() function will add an extra slash to the pathname before joining it to the filename. It’s a backslash instead of a forward slash, because I constructed this example on Windows. If you replicate this example on Linux or Mac OS X, you’ll see a forward slash instead. Don’t fuss with slashes; always use os.path.join() and let Python do the right thing.
  4. The os.path.expanduser() function will expand a pathname that uses ~ to represent the current user’s home directory. This works on any platform where users have a home directory, including Linux, Mac OS X, and Windows. The returned path does not have a trailing slash, but the os.path.join() function doesn’t mind.
  5. Combining these techniques, you can easily construct pathnames for directories and files in the user’s home directory. The os.path.join() function can take any number of arguments. I was overjoyed when I discovered this, since addSlashIfNecessary() is one of the stupid little functions I always need to write when building up my toolbox in a new language. Do not write this stupid little function in Python; smart people have already taken care of it for you.