在Python 2中,getcwd()函數(shù)是通過os模塊調(diào)用的,用法如下:
import os
current_dir = os.getcwd()
print(current_dir)
在Python 3中,getcwd()函數(shù)已經(jīng)移到了os模塊的path子模塊中,用法如下:
import os
current_dir = os.path.abspath(os.path.curdir)
print(current_dir)
因此,在Python 2和Python 3中調(diào)用getcwd()函數(shù)的方式略有不同,需要注意這兩個版本之間的差異。