CiaranWelsh
CiaranWelsh

Reputation: 7681

Is there a built in python method for double slashing file paths?

When giving file paths to a Python script I find myself constantly having to manually double slash the file path (because of escape characters). My question: is there an in-built python function/class/method that either signify escape characters do not apply to the string in question or will simply double slash the paths for me?

i.e.

D:\MPhil\Model_Building\Models\TGFB\Vilar2006\Another_Fit_test\Fit15

into:

D:\\MPhil\\Model_Building\\Models\\TGFB\\Vilar2006\\Another_Fit_test\\Fit15

Upvotes: 0

Views: 79

Answers (1)

Joe
Joe

Reputation: 2564

You can prefix your string with r like this:

some_path = r"escape\codes\will\be\bypassed"

Upvotes: 5

Related Questions