温馨提示×

python getcwd函数在不同Python版本中的差异

小樊
83
2024-08-21 06:35:25
栏目: 编程语言

在Python 2中,getcwd()函数是通过os模块调用的,用法如下:

import os

current_dir = os.getcwd()
print(current_dir)

在Python 3中,getcwd()函数已经移到了os模块的path子模块中,用法如下:

import os

current_dir = os.path.abspath(os.path.curdir)
print(current_dir)

因此,在Python 2和Python 3中调用getcwd()函数的方式略有不同,需要注意这两个版本之间的差异。

0