# Python - replace backslash in string - rs.documentpath()

**URL:** <https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702>\
**Category:** Scripting\
**Created:** [June 16, 2015, 3:54am UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702 "2015-06-16T03:54:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![isvflorin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/isvflorin/32/531169_2.png) [@isvflorin](https://discourse.mcneel.com/u/isvflorin)\
**Post date:** [June 16, 2015, 3:54am UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/1 "2015-06-16T03:54:06Z")

</div>

Trying to replace the backslash character in a string obtained with the rs.documentpath() method. The string replace function will not work since the backslash is an escape character. Any way to change my string into a raw string? Or any tips? I need to use the converted string with a os.chdir method.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [June 16, 2015, 4:58am UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/2 "2015-06-16T04:58:02Z")

</div>

Have you tried `\\`, which is one escaped backslash?

---

<div class="post-metadata">

**Author:** ![Miguel](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/miguel/32/182196_2.png) [@Miguel](https://discourse.mcneel.com/u/Miguel)\
**Post date:** [June 16, 2015, 9:04am UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/3 "2015-06-16T09:04:43Z")

</div>

The following works for me, as @menno suggested

```auto
import rhinoscriptsyntax as rs

myString = rs.DocumentPath()
myString = myString.replace("\\"," ")
print myString

```

---

<div class="post-metadata">

**Author:** ![axa](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/axa/32/772588_2.png) [@axa](https://discourse.mcneel.com/u/axa)\
**Post date:** [June 16, 2015, 2:15pm UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/4 "2015-06-16T14:15:13Z")

</div>

You might want to look at [Python’s os.path module](https://docs.python.org/2/library/os.path.html). It takes care of OS-specific path separator conventions. You should never have to do this the hard way.

---

<div class="post-metadata">

**Author:** ![isvflorin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/isvflorin/32/531169_2.png) [@isvflorin](https://discourse.mcneel.com/u/isvflorin)\
**Post date:** [June 16, 2015, 3:24pm UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/5 "2015-06-16T15:24:33Z")

</div>

Thanks guys, replacing double backslashes worked. However I am still stuck passing my string to the os.chdir method. I though chdir doesn’t like backslashes, but even if I change those to forward slashes it still gives me a “windows error”. Is there any trick to make that work? Should I purge some characters from my path string or something?

---

<div class="post-metadata">

**Author:** ![isvflorin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/isvflorin/32/531169_2.png) [@isvflorin](https://discourse.mcneel.com/u/isvflorin)\
**Post date:** [June 16, 2015, 3:38pm UTC](https://discourse.mcneel.com/t/python-replace-backslash-in-string-rs-documentpath/21702/6 "2015-06-16T15:38:48Z")

</div>

Ok, all works now. Thanks guys.
