Python os.chdir()似乎不起作用 [英] Python os.chdir() doesn't seem to work

查看:287
本文介绍了Python os.chdir()似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在python中更改目录:

I can't seem to change my directory in python:

import os

os.getcwd()

'C:\\Users\\Jon\\Folder\\IdbyGenotype'

os.chdir(r"C:\Users\Jon\Folder\IdbyGenotype\thisone")

os.getcwd()

'C:\\Users\\Jon\\Folder\\IdbyGenotype'

我错过了什么吗?

谢谢

推荐答案

向前使用无论您使用的是Windows还是Linux,路径中的-slash(/)

Use forward-slash(/) in path whether you are using Windows or Linux

import os

os.getcwd()

'C:\\Users\\Jon\\Folder\\IdbyGenotype'

os.chdir("C:/Users/Jon/Folder/IdbyGenotype/thisone")

在我的案例中,此方法有效。

This worked in my case.

这篇关于Python os.chdir()似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆