Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"End of statement expected " string syntax error in python

Tags:

python

string

enter image description here

I have the following variable assignment:

xpath_query="xpath='//a[@id="mylink"]'"

This is giving me an error in my pycharm editor and giving a syntax error when I run this code. What am I doing wrong?

when I hold the cursor over the red squiggle it says:"end of statement expected "

like image 751
user1592380 Avatar asked Oct 21 '22 00:10

user1592380


1 Answers

You have double quotes inside your " " block. so it becomes:

"xpath='//a[@id=" <-- stick together with --> "]'"

Hence it is a string syntax error.

To include " inside " " block, you can use \ to escape the character:

xpath_query="xpath='//a[@id=\"mylink\"]'"
like image 142
Anzel Avatar answered Oct 30 '22 21:10

Anzel