1

Python-3.x IDLE is giving me a syntax error when I attempt to run this code with a custom input .json file and .csv output file. The codes purpose is to convert any .json file into a .csv file and output it to a specific path.

I have attempted cloning the repository through Github. First I used the python 3.9 IDLE, then the python 3.4 IDLE; both do not run the code because of a syntax error. I tried running the code in the path it was in using the following input "python index.py --input /path/to/file.json --output /path/to/output/file.csv" in the python terminal and it comes up as an error. The final and most recent try, which I have displayed in the code, was writing to the add argument lines for the input and output (not sure why I didn't try it before) and it came up with a unicode read error

parser = argparse.ArgumentParser(description='Convert Google Maps location history to csv file.')
parser.add_argument('-i', '--input', action="store", help='C:\Users\bmevans\Downloads\takeout-20190904T042913Z-001.zip\Takeout\Location History.json file.', required=True)
parser.add_argument('-o', '--output', action="store", help='C:\Users\bmevans\Desktop.csv file.', required=True)

I expect the following error to be "error: "unicodeescape codec can't decode bytes in position 2-3: truncated\UXXXXXXXX escape", not sure why that is. I had assumed the lack of an os import was the problem but that isnt the case either. Could it be that I included an absolute path, not a relative?

Brandon Evans
  • 73
  • 1
  • 5
  • Possible duplicate of [(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape](https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca) – snakecharmerb Sep 12 '19 at 20:25
  • The error is caused by the paths like `'C:\Users\...'`. Python interprets the `'\U...'` as an escaped 32-bit unicode character. Since it can't find a match, the error is raised. Mitigations are described in the linked duplicate target. – snakecharmerb Sep 02 '20 at 17:40

0 Answers0