在 Python 中切换到 Linux 的指定目录可以使用 os.chdir() 函数。下面是一个示例:

import os

# 切换到指定目录
os.chdir('/path/to/directory')

# 打印当前工作目录
print(os.getcwd())

在上述示例中,/path/to/directory 是你想要切换到的目录的路径。os.chdir() 函数将当前工作目录更改为指定目录。os.getcwd() 函数用于获取当前工作目录并打印输出。

Python 切换到 Linux 指定目录 - 使用 os.chdir() 函数

原文地址: https://www.cveoy.top/t/topic/p1cj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录