Jump to content

Python error

Rylyguy

So I have a program written in python. When I try to run it it opens for half a second then closes. So I tried to run it from command prompt. It gives an error that I don’t understand. I’ll send a photo of it below. 

 

Link to comment
Share on other sites

Link to post
Share on other sites

It's probably the backslashes. Those indicate an escape sequence coming up. \<something> has special meaning, for example \n is a newline or \t is a tab. You'll need to escape your \ if you want to use them in your path there as \\ or prepend the string with r like

 r"C:\Users\R&R"

The r indicates a raw string so it won't try to escape anything.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, tikker said:

It's probably the backslashes. Those indicate an escape sequence coming up. \<something> has special meaning, for example \n is a newline or \t is a tab. You'll need to escape your \ if you want to use them in your path there as \\ or prepend the string with r like


 r"C:\Users\R&R"

The r indicates a raw string so it won't try to escape anything.

I’m sorry. I understood very little of that. I found the script on GitHub and modified it to work for this computer. Though I ram it on my laptop and it was fine. Can you eli5. 

Link to comment
Share on other sites

Link to post
Share on other sites

Oh. Never mind. I reread what you said added an r before the string and it worked. Thank you so much. My sister really wants a ps5 so I’m trying to get her one for Christmas. 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Rylyguy said:

I’m sorry. I understood very little of that. I found the script on GitHub and modified it to work for this computer. Though I ram it on my laptop and it was fine. Can you eli5. 

https://www.python-ds.com/python-3-escape-sequences

 

Windows uses \ as path separators. This causes a problem, because for Python (and usually) a backslash indicates an escape sequence, which means it will replace it with something else. As I said \n means a new line, for example.

# \n is "escaped" into a new line
print('Hello\nWorld')
Hello
World

# Here the \ is escaped so it won't interpret the \n combination as a new line
print('Hello\\nWorld')
Hello\nWorld

# Here r"" tells Python it's a so-called raw string, so it also won't try to escape anything
print(r'Hello\nWorld')
Hello\nWorld

In your case it tries to interpret \U as a unicode character and fails because what follows isn't valid.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×