# Raw string fails to compile with "no viable alternative at input '\\n'

**URL:** <https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758>\
**Category:** Ignition\
**Created:** [October 27, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758 "2022-10-27T14:24:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Whitt](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Mark\_Whitt](https://forum.inductiveautomation.com/u/Mark_Whitt)\
**Post date:** [October 27, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/1 "2022-10-27T14:24:45Z")

</div>

I'm using Ignition 8.1.

From reading the [Strings - Ignition University](https://docs.inductiveautomation.com/display/DOC79/Strings), it seemed to me that the following two string assignments would be equivalent:

```
path = "C:\\Temp\\pHData\\Ignition\\"

path = r"C:\Temp\pHData\Ignition\"

```

However, the second one fails to compile, giving the error "no viable alternative at input '\n' "

To me, the second one looks the same as this example from the document:

```auto
# Specifying a Windows file path
myPath = r"C:\Folder\Another Folder\file.txt"
print myPath

```

Just wondering what I'm missing?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 27, 2022, 2:37pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/2 "2022-10-27T14:37:30Z")

</div>

In python the `\` character is an escape character, so you are escaping the `"` at the end of the string. This is kind of an edge case. However, removing that `\` is functionally equivalent. If you intend to use this as a sub string in building a larger path, then adding format place holders will allow you to use this as you're trying.

```auto
basePath = r"C:\Temp\pHData\Ignition\{}"
extendedPath = "SomeChildFolder"
print basePath.format(extendedPath)

```

Another alternative would be to use a string builder

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 27, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/3 "2022-10-27T14:43:59Z")

</div>

In basically everything in Python and Java's standard library, you can just use forward slashes instead of backslashes and avoid any escaping problems entirely.

---

<div class="post-metadata">

**Author:** ![Mark\_Whitt](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Mark\_Whitt](https://forum.inductiveautomation.com/u/Mark_Whitt)\
**Post date:** [October 27, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/4 "2022-10-27T14:46:46Z")

</div>

Thanks for the reply, Irose!

So, even on a 'raw' string, the backslash at the end acts as an escape? I'm having trouble making sense of that since it didn't do that with the other backslashes in the string. Any idea why only the last character seems to be a special case?

---

<div class="post-metadata">

**Author:** ![Mark\_Whitt](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Mark\_Whitt](https://forum.inductiveautomation.com/u/Mark_Whitt)\
**Post date:** [October 27, 2022, 2:47pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/5 "2022-10-27T14:47:34Z")

</div>

Good to know about the forward slashes, thanks!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 27, 2022, 2:55pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/6 "2022-10-27T14:55:35Z")

</div>

In the first example there are two `\\` so you're escaping the `\` and not the `"`. The `\` escapes the next character.

It needs to work this way, what if you want to include quotes in a string with out terminating the string?

```auto
myString = "This is a \"string\" that has quotes."

```

A raw string can not end in a single backslash.

---

<div class="post-metadata">

**Author:** ![Mark\_Whitt](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@Mark\_Whitt](https://forum.inductiveautomation.com/u/Mark_Whitt)\
**Post date:** [October 27, 2022, 3:20pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/7 "2022-10-27T15:20:22Z")

</div>

Again, thanks for the response.

For those (like me) who are still having trouble understanding it, I just stumbled across this document that explains about this particular topic for Python in general.  
[Why can't raw strings in Python end with a backslash?](https://docs.python.org/3/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash)

It still seems odd to me. But I tend to remember odd things, so maybe that's good? 🙂

---

<div class="post-metadata">

**Author:** ![Miguel\_Villasenor\_Es](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/miguel_villasenor_es/32/60416_2.png) [@Miguel\_Villasenor\_Es](https://forum.inductiveautomation.com/u/Miguel_Villasenor_Es)\
**Post date:** [February 15, 2024, 1:56pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/8 "2024-02-15T13:56:56Z")

</div>

What if production has a database with thousands of records that are just file paths on a network drive?

One path example would be "C:\folder1\folder2\folder3\items", that is how they're stored in our DB. I am trying to pull the paths from the db and then represent them in a tree view.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 15, 2024, 2:17pm UTC](https://forum.inductiveautomation.com/t/raw-string-fails-to-compile-with-no-viable-alternative-at-input-n/65758/9 "2024-02-15T14:17:28Z")

</div>

If you're not manually inputting the string then it shouldn't matter. However, if you're concerned then you can just do:

```auto
path = r'C:\folder1\folder2\folder3\items'
path = path.replace('\\','/')

```

EDIT: I hand typed in the path for testing purposes.
