Trick is to use “r” before the string

See error

The “r” means it is a raw string

https://docs.python.org/3/reference/lexical_analysis.html

 

  File "C:\Users\jonallen\Documents\github\wsgi\FlaskApp\FlaskApp\obs_utils.py", line 13
    obs_dir = "C:\Users\jonallen\Documents\github\weather_obs"
                                                              ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

 

import os
import sys
import glob
from pathlib import Path
def get_obs_csv_files(  dir ):
  glob_path = Path(dir)
  file_list = [str(pp) for pp in glob_path.glob("*.csv")]
  return file_list


if __name__ == "__main__":
   print("testing csv files")
   obs_dir = r"C:\Users\jonallen\Documents\github\weather_obs"
   flist = get_obs_csv_files( obs_dir)
   print(flist)

 

Leave a Reply