0

I am trying to print a location path as hyperlink in python using below code:

print("""<a href=r"\\ucd.int.com\user\ClientData\sigma\RPAOutput">link</a>""")

But I get following error upon running though I am using raw string:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 23-24: truncated \uXXXX escape

Any suggestion is appreciated. Thanks

Amrita
  • 23
  • 5

2 Answers2

0

The error you're seeing is likely caused by the backslashes (\) in the file path. In Python, backslashes are used as escape characters, so you need to use an extra backslash to indicate that you want to include the backslash in the string, rather than using it as an escape character.

To fix this, you should replace all the backslashes in the file path with forward slashes (/).

print("""<a href=r"\\ucd.int.com\user\ClientData\sigma\RPAOutput">link</a>""".replace('\\','/'))

Alternatively, you can use forward slashes instead of backslashes in the file path in the first place.

print("""<a href=r"//ucd.int.com/user/ClientData/sigma/RPAOutput">link</a>""")

This will work as forward slashes are not escape characters in python.

Also please note that, if you're trying to access a Windows file path, you should use double backslashes (\) instead of single backslashes to separate directories.

print("""<a href=r"\\ucd.int.com\\user\\ClientData\\sigma\\RPAOutput">link</a>""")
Fractalism
  • 1,231
  • 3
  • 12
0

try using:

print(r"""<a href=r"\\ucd.int.com\user\ClientData\sigma\RPAOutput">link</a>""")
Mariox
  • 16
  • 1