![]() ![]() This works on any platform where users have a home directory, including Linux, Mac OS X, and Windows. The os.path.expanduser() function will expand a pathname that uses ~ to represent the current user's home directory. Calling the os.path.join() function will add an extra slash to the pathname before joining it to the filename. In this case, it simply concatenates strings. The os.path.join() function constructs a pathname out of one or more partial pathnames. ![]() ![]() Os.path contains functions for manipulating filenames and directory names. This is one of the places where Python tries to paper over the differences between operating systems. Note that when we called the os.chdir() function, we used a Linux-style pathname (forward slashes, no drive letter) even though we're on Windows. Then, we used the os.chdir() function to change the current working directory. If we run the Python Shell from the command line, the current working directory starts as the directory we were in when we ran python3. On Windows, this depends on where we installed Python the default directory is c:\Python32. When we run the graphical Python Shell, the current working directory starts as the directory where the Python Shell executable is. We used the os.getcwd() function to get the current working directory. There is always a current working directory, whether we're in the Python Shell, running our own Python script from the command line, etc. The current working directory is a property that Python holds in memory at all times. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |