Hi,
Why and When I need use r before the workspace declaration in python like below:
Thank´s
Solved! Go to Solution.
Search "python raw encoding" for the history.
Or read my precise
/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python
In short... the options are listed but a little 'r' goes a long way.
# ---- the bad
folder = "c:\users\andre souza\tools\gis"
File "<ipython-input-35-6d2d90c647fc>", line 1
folder = "c:\users\andre souza\tools\gis"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape
# ---- the good
folder = r"c:\users\andre souza\tools\gis"
folder
'c:\\users\\andre souza\\tools\\gis'
# ---- the ugly
folder = "C:\Temp\andre souza\tools\gis"
print(folder)
C:\Tempndre souza ools\gis
folder = r"C:\Temp\andre souza\tools\gis"
print(folder)
C:\Temp\andre souza\tools\gis
Search "python raw encoding" for the history.
Or read my precise
/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python
In short... the options are listed but a little 'r' goes a long way.
# ---- the bad
folder = "c:\users\andre souza\tools\gis"
File "<ipython-input-35-6d2d90c647fc>", line 1
folder = "c:\users\andre souza\tools\gis"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape
# ---- the good
folder = r"c:\users\andre souza\tools\gis"
folder
'c:\\users\\andre souza\\tools\\gis'
# ---- the ugly
folder = "C:\Temp\andre souza\tools\gis"
print(folder)
C:\Tempndre souza ools\gis
folder = r"C:\Temp\andre souza\tools\gis"
print(folder)
C:\Temp\andre souza\tools\gis
Fantastic! Help me a lot!!
Thank´s Dan!!