os.curdir与os.getcwd ( )有何区别
for each_file in os.listdir (os.curdir ):print( os.getdir() + os.sep + each_file)
这两个语句中的 os.curdir和 os.getcwd ( ) 能不能通用?
os.curdir是指代当前目录,os.getcwd ( )是返回当前目录,这两者有什么区别,在一般的用法上有何不同? 首先,没有os.getdir() 只有os.getcwd()
其次print()这一句应该这样写:
print((os.getcwd() + os.sep + each_file))
是可以运行的:
C:\Users\Administrator\Pictures\Saved Pictures\捕获.PNG
32269100 发表于 2017-2-24 17:54
os.getcwd : 得到当前python脚本工作的目录路径。
os.curdir : 获得当前工作目录的字符串名称
不好意思,不是很明白,这二者有什么区别么 我看了,两者没啥区别
os.listdir(os.curdir)
os.listdir(os.getcwd())
得出来的结果是一样的 区别就是一个是变量一个是函数! 如图:os.curdir 是个变量。是个相对路径
os.getcwd()是函数,返回当前目录的绝对路径 os.getcwd()会返回绝对路径
os.curdir是返回当前路径,print出来会是个点 本帖最后由 hrp 于 2020-6-30 07:06 编辑
页:
[1]