To load the OS module first:
Import OS
Print OS.GETCWD ()
Or
Print Os.path.abspath (Os.curdir)
Print Os.path.abspath ('. ')
You can do it.
( . Represents the current path,: represents the upper-level path of the current path. This is similar in the sense of UNIX and Windows systems.
For example:
Take the WINODWS system as an example:
The current path is F:\Temp, then the absolute path of the . is F:\Temp
.. The absolute path is f:\.
)
It is also easy to get the path to the parent directory, print Os.path.abspath ('.. ') You can do it.
To change the current path, Os.chdir (path) can fill in the path to the directory to be changed, such as Os.chdir (' D:\Program Files ')
So most of the file operations are now relative to D:\Program files, such as Fobj = open (' Hello.txt '), which actually opens the D:\Program files\hello.txt file.
Python Gets the current path