Python os.getcwd() 方法
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Python os.getcwd() 方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                Python os.getcwd() 方法
轉存失敗?Python OS 文件/目錄方法
概述
os.getcwd() 方法用于返回當前工作目錄。
語法
getcwd()方法語法格式如下:
os.getcwd().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 )
# -*- 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 : /var/www/html
當前工作目錄 : /tmp 
                            總結
以上是生活随笔為你收集整理的Python os.getcwd() 方法的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: python yield 和 retur
 - 下一篇: jieba分词流程及部分源码解读(一)