pythonpython-3.xcomments

Why is the text located inside the multi-line comment causing a syntax error in my python script?


terminal console messages for my command:

PS C:\Users\dev> python 'C:\a-c-151_(o-c-091)\uk-land-registry-data-pipeline.py'
  File "C:\a-c-151_(o-c-091)\uk-land-registry-data-pipeline.py", line 315
    """
    ^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 6-7: truncated \UXXXXXXXX escape
PS C:\Users\dev>

relevant part of the code (the lines from 313 to 323):

# terminal output log saved below

"""
PS C:\Users\dev> cd 'C:\a-c-151_(o-c-091)\'                                
PS C:\a-c-151_(o-c-091)> python 'C:\a-c-151_(o-c-091)\uk-land-registry-data-pipeline.py'
Traceback (most recent call last):
  File "C:\a-c-151_(o-c-091)\uk-land-registry-data-pipeline.py", line 8, in <module>
    import geopandas as gpd
ModuleNotFoundError: No module named 'geopandas'
PS C:\a-c-151_(o-c-091)> 
"""

Solution

  • As suggested by @001's comment, my issue was finally resolved by prepending "r" in the beginning of the comment, just before the quotation marks, to turn it into a raw string.