當前位置:
首頁 >
python getcwd 转义,Python os.getcwd() 方法
發布時間:2023/12/10
40
豆豆
生活随笔
收集整理的這篇文章主要介紹了
python getcwd 转义,Python os.getcwd() 方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python os.getcwd() 方法
概述
os.getcwd() 方法用于返回當前工作目錄。
語法
getcwd()方法語法格式如下:
os.getcwd()
參數
無
返回值
返回當前進程的工作目錄。
實例
以下實例演示了 getcwd() 方法的使用:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# 切換到 "/var/www/html" 目錄
os.chdir("/var/www/html" )
# 打印當前目錄
print "當前工作目錄 : %s" % os.getcwd()
# 打開 "/tmp"
fd = os.open( "/tmp", os.O_RDONLY )
# 使用 os.fchdir() 方法修改目錄
os.fchdir(fd)
# 打印當前目錄
print "當前工作目錄 : %s" % os.getcwd()
# 關閉文件
os.close( fd )
執行以上程序輸出結果為:
當前工作目錄 : /var/www/html
當前工作目錄 : /tmp
總結
以上是生活随笔為你收集整理的python getcwd 转义,Python os.getcwd() 方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse安装jsp
- 下一篇: 55exception对象