Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Traceback Error
#1
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
Larz60+ write Nov-21-2022, 10:39 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please do not attach images. Post the error in bbcode error tags.

Attached Files

Thumbnail(s)
   
Reply
#2
(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.
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Reply
#3
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~~~~~~
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,287 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Traceback error in PyCharm but not in other IDEs? devansing 7 6,384 Mar-05-2020, 11:27 AM
Last Post: buran
  Nameparser - Traceback error tjnichols 2 2,386 Feb-28-2020, 05:11 PM
Last Post: GodMaster
  I have Traceback error and a type error and i dont know how to fix it coltron1282 2 2,530 Feb-07-2019, 03:15 PM
Last Post: coltron1282
  Unexpected output, TypeError and traceback error fier259 2 3,121 May-06-2018, 10:52 PM
Last Post: fier259
  CSV unable to import (traceback error) learnermarx 3 6,342 Feb-09-2018, 03:24 PM
Last Post: buran
  [error]Traceback kikoko_2 1 2,725 Dec-01-2017, 11:30 PM
Last Post: Windspar
  Python Error (Traceback & ValueError) Help! helpplease 4 5,980 Dec-19-2016, 06:07 PM
Last Post: Ofnuts
  Python Traceback Error CaiGengYang 4 7,902 Nov-28-2016, 08:51 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020