温馨提示×

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

小樊
91
2024-08-21 06:35:25
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在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()函数的方式略有不同,需要注意这两个版本之间的差异。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python如何输出文件路径

0