diff --git a/comprehensions.html b/comprehensions.html index 702948b..2969380 100644 --- a/comprehensions.html +++ b/comprehensions.html @@ -68,13 +68,13 @@ body{counter-reset:h1 3}
>>> import os
>>> print(os.path.join('/Users/pilgrim/diveintopython3/examples/', 'humansize.py')) ①
-/Users/pilgrim/diveintopython3/examples/humansize.py
+/Users/pilgrim/diveintopython3/examples/humansize.py
>>> print(os.path.join('/Users/pilgrim/diveintopython3/examples', 'humansize.py')) ②
-/Users/pilgrim/diveintopython3/examples\humansize.py
+/Users/pilgrim/diveintopython3/examples\humansize.py
>>> print(os.path.expanduser('~')) ③
-c:\Users\pilgrim
+c:\Users\pilgrim
>>> print(os.path.join(os.path.expanduser('~'), 'diveintopython3', 'examples', 'humansize.py')) ④
-c:\Users\pilgrim\diveintopython3\examples\humansize.py
+c:\Users\pilgrim\diveintopython3\examples\humansize.py
os.path.join() function constructs a pathname out of one or more partial pathnames. In this case, it simply concatenates strings.
join will add an extra backslash to the pathname before joining it to the filename. 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.