Python will fail if there is a space after the backslash

I'm sure it's common sense knowledge, but I admit this article in the sense of self-discipline because I've done it.

From the conclusion

--You can't leave a space behind the backspace. --In the first place, the description that divides into multiple lines with backspace is not recommended.

Background of that

I modified the code written by others in the git project managed by others. The modification is a simple thing of adding Where in the SQL statement.

I modified the code as follows.

Before correction


    ...
    sql = "SELECT "\
          "  user.id ,"\
          "  user.name "\
          "FROM "\
          "  user "\
          "WHERE "\
          "  user.age >= 20 "\
          "  AND user.sex == 'M' "
    c.execute(sql)
    ...

Revised



    ...
    sql = "SELECT "\
          "  user.id ,"\
          "  user.name "\
          "FROM "\
          "  user "\
          "WHERE "\
          "  user.age >= 20 "\
          "  user.age <= 60 "\␣␣␣␣␣␣␣␣
          "  AND user.sex == 'M' "
    c.execute(sql)
    ...

A few weeks after uploading the code to git. Around the time when I forgot to apply it to the production after passing reviews and verifications. The customer told me that the place where I was pulling SQL did not seem to work. After investigating, I got this error.

SyntaxError: EOL while scanning string literal

Cant Believe It.

Why this happened

Actually, this code was a file with separate management for the production environment and the test environment. ← This structure itself is not good However, it's not the code I manage, so I modified the code for the test environment as I was told. After passing the developer test, copy and submit the modified code to the production source. At that time, it seems that a space was mixed in at the end.

Comprehensive verification was carried out for the corrected part and passed. The test code was also used at this time. Since there is a space only in the production code, it is released undetected. And it happened when the customer used it.

Countermeasures

There are many things I want to say in the organizational development flow,

For the time being, implement the following as a personal measure

I can't do anything ...

Recommended Posts

Python will fail if there is a space after the backslash
Check if the string is a number in python
Delete a particular character in Python if it is the last
[python] [meta] Is the type of python a type?
What to do if there is a decimal in python json .dumps
If branch depending on whether there is a specific element in the list
Create a python script to check if the link at the specified URL is valid 2
Create a python script to check if the link at the specified URL is valid
How to check in Python if one of the elements of a list is in another list
python> check NoneType or not> if a == None:> if a is None:
There is a pattern that the program did not stop when using Python threading
[Python] Make sure the received function is a user-defined function
Checks if there is a specific character string for all files under the directory that is Python and outputs the target line
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
Which is the most popular python visualization tool after all?
I want to initialize if the value is empty (python)
Determine if a string is a time with a python regular expression
[python] Reverse with slices! !! (There is also a commentary on slices!)
Is there a bias in the numbers that appear in the Fibonacci numbers?
Is there a secret to the frequency of pi numbers?
Python list is not a list
The image is a slug
What is a python map?
In the python dictionary, if a non-existent key is accessed, initialize it with an arbitrary value
[Blender] Script to check if the selected one is a mesh
Play a sound in Python assuming that the keyboard is a piano keyboard
Determine if standard output is piped when running a Python script
After researching the Python library, I understood a little about egg.info.
[Golang] Check if a specific character string is included in the character string
Check if there is a specific symbol in the executable file and its dependent libraries (simplified version)
Python> Slice> A slice offset earlier than the beginning of a string is treated as 0, and one after the end is treated as -1
Is there a special in scipy? ??
[Python] What is @? (About the decorator)
[python] What is the sorted key?
[Python] Make the function a lambda function
Determine if the string is formatable
There is no switch in python
Determine if the library is installed.
What is the python underscore (_) for?
[Python] Determine if any coordinate point is inside or outside the polygon
[Python] What is a formal argument? How to set the initial value
What is the XX file at the root of a popular Python project?
If you want a singleton in python, think of the module as a singleton
[Introduction to Python] What is the difference between a list and a tuple?
Is the space replaced by a plus sign or% 20 in percent-encoding processing?
Note that Python dict returns default value if there is no key
DJango memo: From the beginning (editing the management screen) There is a mystery
What is the fastest way to create a reverse dictionary in python?
I created a script to check if English is entered in the specified position of the JSON file in Python.