-1

enter image description here

import os 

os.rename("C:\Users\user\Desktop\before.txt","C:\Users\user\Desktop\after.txt")

I want to Know why that message come. I already search a lot of documents and try change /->\ and attach r before "C:~~" and try \ I don't know why that problem happen.

Chris
  • 29,127
  • 3
  • 28
  • 51
  • Does this answer your question? [Windows path in Python](https://stackoverflow.com/questions/2953834/windows-path-in-python) – Rasoul Ghasemi Jun 14 '22 at 10:00

1 Answers1

0

Quick googling says that character is path separator in Korean windows. is shown in your screenshot so maybe thats the reason ?

I Wonder what should this show in your python:

import os
print(os.sep)

If that shows , then maybe you could something like this:

from pathlib import Path
before_file  = Path("C:") / "Users" / "user" / "Desktop" / "before.txt"
before_file.rename("after.txt")

Or if you insist on using os library, use os.sep as path separator instead of \\ or /

rasjani
  • 7,372
  • 4
  • 22
  • 35