How to get the current directory in python?

I’m trying to get the current directory using the OS module, like that:


However, when I do this, the directory comes with \, like 'C:\Users\...', and I need to use directory with \\ or /.

Is that anyway to get the directory with \\ or /?

>Solution :

You can just replace the \ with /. Note that the former must be escaped with another \, like below:

import os
directory = os.getcwd().replace('\\', '/')

Leave a Reply