首页 > 试题广场 >

编写代码,将当前工作目录修改为“C:\”,并验证,最后将当前

[问答题]

编写代码,将当前工作目录修改为“C:\”,并验证,最后将当前工作目录恢复为原来的目录。

>>> import os
>>> os.getcwd()
'C:\\Python34'
>>> os.chdir(r'c:\\')
>>> os.getcwd()
'c:\\'
>>> os.chdir(r'c:\Python34')
>>> os.getcwd()
'c:\\Python34'

发表于 2017-12-28 15:56:34 回复(0)
#coding=utf-8
import os
currentpath = os.getcwd()
os.chdir('C:\\')
if os.getcwd() == 'C:\\':
    print 'true'
os.chdir(currentpath)
print os.getcwd()

发表于 2018-05-04 13:52:51 回复(0)