1024cl最新手機地址一地址二地址三tyy6論壇caoliu

1024cl最新手機地址一地址二地址三tyy6論壇caoliu:python進入到指定目錄下的方法:php

Python能夠使用os.chdir()方法轉到指定目錄。os.chdir() 方法用於改變當前工做目錄到指定的路徑。python

chdir()方法語法格式以下:spa

1code

os.chdir(path)ci

參數get

path -- 要切換到的新路徑。string

實例io

如下實例演示了 chdir() 方法的使用:table

1function

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

#!/usr/bin/python

# -*- coding: UTF-8 -*-

 

import os, sys

 

path = "/tmp"

 

# 查看當前工做目錄

retval = os.getcwd()

print "當前工做目錄爲 %s" % retval

 

# 修改當前工做目錄

os.chdir( path )

 

# 查看修改後的工做目錄

retval = os.getcwd()

 

print "目錄修改爲功 %s" % retval

相關文章
相關標籤/搜索