Outline
os.getcwd () method returns the current working directory.
grammar
getcwd () method syntax is as follows:
os.getcwd()
parameter
- no
return value
Returns the working directory of the current process.
Examples
The following example demonstrates getcwd () method of use:
. 1 # ! / Usr / bin / Python 2 # - * - Coding: UTF-. 8 - * - . 3 . 4 Import OS, SYS . 5 . 6 # switch to the "/ var / www / html" directory . 7 the os.chdir ( " / igihub / IPython / Base / file_handle " ) . 8 . 9 # Print directory 10 Print ( " current working directory:% S " % The os.getcwd ()) . 11 12 is # open" / tmp " 13 is FD = os.open ( " / IPython / Base " , os.O_RDONLY) 14 15 #Use os.fchdir () method to modify the directory 16 os.fchdir (FD) . 17 18 is # Print directory . 19 Print ( " current working directory:% S " % The os.getcwd ()) 20 is 21 is # close file 22 is os.close ( fd)
When used, remember to replace the path you need on the line.
reference: