0

I am making a level editor, where i need to save the "Maps" they build. And they can make there own name to the "Map".

but i can't use "\" because, yeah i don't know why(I know it is something about escape sequences) and i hope there is either a way to get around it or use another method and i am a noob at this so i don't know to make that a code:

The_name = "Easy_map" #that's what they called it

path = "levels\" + the_name + ".txt" #making the path

I expect the variable path to be levels\Easy_map.txt but the output is SyntaxError: EOL while scanning string literal because i use "\"

Ankit Agrawal
  • 616
  • 9
  • 20
  • Hey Anders, this is a common problem we've all had to deal with! Check out the link that Ankit Agrawal commented. We have to escape a backslash for it to be used in strings, the other post will explain it for you. – GantTheWanderer Jul 17 '19 at 18:14

1 Answers1

2

The backslash \ is the escape character. If you want to include a backslash in your string, you need to escape it (preface it with the escape character). So, the string literal '\\' would print out as \

Zachary Oldham
  • 838
  • 1
  • 5
  • 21