The path is not working,i tried making changes to the path but didn’t work.
import os
print(os.chdir("Users\Nikhil\Desktop\Python"))
The path is not working,i tried making changes to the path but didn’t work.
import os
print(os.chdir("Users\Nikhil\Desktop\Python"))
If you want to pass path this way you need to either escape backslashes or use the co-called raw strings.
Another approach would be looking at the os.path.join
function and allowing it to construct the actual path, which can be then passed to os.chdir
.
The Path is not working
What do you mean exactly?
This is the error I am getting
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
And I tried the walk method ,even then I am getting the same error
import os
for path,dir_name,file_name in os.walk('C:\Users\Nikhil\Desktop\Python'):
print(dir_name)
Did you try what I wrote in the first response?
I am doing it ,I’ll tell you once I am done.Do reply
I tried it using an slash in front of every slash,and it worked.