Python os.chdir() doesn't seem to work

懵懂的女人 提交于 2019-12-12 10:43:44

问题


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'

Am I missing something? What could be going wrong here?

Thanks


回答1:


 import os
 os.getcwd()
 'C:\\Program Files\\PYTHON'
 os.chdir('c:\\mytemp')
 os.getcwd()
 'c:\\mytemp'
 os.chdir(r'c:\')
 SyntaxError: EOL while scanning string literal
 os.chdir(r"c:\\")
 os.getcwd()
 'c:\\'

I have had inconsistent results with the use of r to communicate that the following is a raw string. As you can see when I use the r I get an error when I hit enter.

Thus have you tried to use escaped-backslashes in your os.chdir() command?

You are implying that you did not receive any error messages - this is strange because I get error messages when I try to chdir to a directory that I do not have rights to under my user name and when I try to chdir to a directory that does not exist.



来源:https://stackoverflow.com/questions/18239915/python-os-chdir-doesnt-seem-to-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!