编写代码,将当前工作目录修改为“C:\”,并验证,最后将当前工作目录恢复为原来的目录。
>>> import os >>> os.getcwd() 'C:\\Python34' >>> os.chdir(r'c:\\') >>> os.getcwd() 'c:\\' >>> os.chdir(r'c:\Python34') >>> os.getcwd() 'c:\\Python34'
#coding=utf-8 import os currentpath = os.getcwd() os.chdir('C:\\') if os.getcwd() == 'C:\\': print 'true' os.chdir(currentpath) print os.getcwd()
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题