当前位置: 首页 > 图灵资讯 > 行业资讯> python os.chdir()的使用

python os.chdir()的使用

发布时间:2024-06-28 21:32:46

1、os.chdir()用于将当前工作目录改为指定路径。

2、语法为os.chdir(path)。

3、要切换的新路径是参数path。

4、返回值,如果允许访问返回True,否则False。

实例

importos
os.chdir('G:/阿里云盘/音乐/#39;)
datanames=os.listdir()
print(datanames)
forfileindatanames:
if'-'infile:
new_name=file.replace('-','')
os.rename(file,new_name)
print(file+'已改为'+new_name)
else:
pass

以上是python os.chdir()使用,希望对大家有所帮助。更多多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12