点击此处浏览总目录

os.getcwd()

概述
  用于返回当前工作目录。

语法
  os.getcwd()

参数
  无

返回值
  返回当前进程的工作目录

使用示例

import os, sys

os.chdir("/var/www/html" ) # 切换到 "/var/www/html" 目录
print (os.getcwd()) # 输出:/var/www/html

fd = os.open( "/tmp", os.O_RDONLY ) # 打开 "/tmp"
os.fchdir(fd) # 使用 os.fchdir() 方法修改目录
print (os.getcwd()) # 输出:/tmp

os.close( fd ) # 关闭文件
posted @ 2019-12-31 10:04  立业的博客  阅读(602)  评论(0编辑  收藏  举报