Saturday, July 9, 2022
HomeCyber SecuritySyntaxError: EOL whereas scanning string literal | by Teri Radichel | Bugs...

SyntaxError: EOL whereas scanning string literal | by Teri Radichel | Bugs That Chew | Jul, 2022


Error in a line with a python escape character

Iā€™m writing a json template parser in python and go the next error:

SyntaxError: EOL whereas scanning string literal

The issue was that I used to be checking for a backslash in a string like this:

if line.startswith(ā€œ[ā€):

The backslash is an escape character used in front of special characters within string so they will be processed correctly. For example, letā€™s say you want to print out a string with quotes in it like this:

The word is "test."

You need to escape the double quotes if they are inside a string wrapped in double quotes:

variable="The word is "test"."

Now returning to my string the command I was trying to process, python things that Iā€™m trying to escape the second string instead of end the string.

if line.startswith("["):

In order to correctly interpret the the bracket and backslash I would need to escape the backslash itself with another backslash.

if line.startswith("[")

That causes the backslash to be processed as a backslash character instead of an escape character in front of a quote.

Teri Radichel

If you liked this story please clap and follow:

Medium: Teri Radichel or Email List: Teri Radichel
Twitter: @teriradichel or @2ndSightLab
Requests services via LinkedIn: Teri Radichel or IANS Research

Ā© 2nd Sight Lab 2022

____________________________________________

Author:

Cybersecurity for Executives in the Age of Cloud on Amazon

Need Cloud Security Training? 2nd Sight Lab Cloud Security Training

Is your cloud secure? Hire 2nd Sight Lab for a penetration test or security assessment.

Have a Cybersecurity or Cloud Security Question? Ask Teri Radichel by scheduling a call with IANS Research.

Cybersecurity & Cloud Security Resources by Teri Radichel: Cybersecurity and Cloud security classes, articles, white papers, presentations, and podcasts



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments