Python Forum

Full Version: Python Traceback Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,

I am running python script via command line, getting below error.
Error is showing in two py files.

Traceback
main.py at line ----->11
test.py at line ----->153
how to understand where exactly the error has occurred.

attached snapshot
(Nov-21-2022, 06:30 AM)mg24 Wrote: [ -> ]Hi Team,

I am running python script via command line, getting below error.
Error is showing in two py files.

Traceback
main.py at line ----->11
test.py at line ----->153
how to understand where exactly the error has occurred.

attached snapshot
It's very hard to read images, please post code like the '<python> </python>'
It will look like this.
#the code
Also, please post code and not just errors. I don't know what you did.
As mention post code and error message in code tags.
The error occurred in line-11.
The error message is clear,can make the same error messge.
>>> name = 'Kent'
>>> color = 'blue'
>>> print(f'Kent has a {car_type\n} and the color is {color}')
  File "<interactive input>", line 1
    print(f'Kent has a {car_type\n} and the color is {color}')
                                                             ^
SyntaxError: f-string expression part cannot include a backslash
So cannot have backslash new line \n or any escape character inside the f-string expression.
Move it outside and it's ok.
>>> name = 'Kent'
>>> color = 'blue'
>>> print(f'Kent has a {car_type}\nand the color is {color}')
Kent has a BMW
and the color is blue

print(f'Kent has a {car_type}\nand the color is {color:~^15}')
Kent has a BMW
and the color is ~~~~~blue~~~~~~