diff --git a/comprehensions.html b/comprehensions.html index 4a382d2..702948b 100644 --- a/comprehensions.html +++ b/comprehensions.html @@ -78,8 +78,8 @@ body{counter-reset:h1 3}
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.
-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.
-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.
+os.path.join() function can take any number of arguments.
os.path also contains functions to split full pathnames, directory names, and filenames into their constituent parts.
@@ -99,8 +99,8 @@ body{counter-reset:h1 3}
>>> extension
'.py'
split function splits a full pathname and returns a tuple containing the path and filename. Remember when I said you could use multi-variable assignment to return multiple values from a function? The os.path.split() function does exactly that.
-split function into a tuple of two variables. Each variable receives the value of the corresponding element of the returned tuple.
+split function splits a full pathname and returns a tuple containing the path and filename.
+os.path.split() function does exactly that. You assign the return value of the split function into a tuple of two variables. Each variable receives the value of the corresponding element of the returned tuple.
os.path.split() function, the file path.
os.path.split() function, the filename.
os.path also contains the os.path.splitext() function, which splits a filename and returns a tuple containing the filename and the file extension. You use the same technique to assign each of them to separate variables.