I am using Spyder IDE , Python 3.5, which is a part of the anaconda distribution. Given below are the first few lines of the code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 20 16:22:40 2016
@author: pavan
This program reads csv file from the given directory .
The input directory for this is : "C:\Users\pavan\Documents\Python Scripts\EOD from Yahoo"
The output file is "comprehensive_trend.xlsx"
"""
import pdb
import pandas as pd
from datetime import date, datetime, timedelta
import os, glob
# Delarations
full_path = os.path.realpath(__file__)
current_directory = os.path.dirname(full_path)
directory = current_directory + "\\EOD from Yahoo\\"
#directory = "C:\\Users\\pavan\Documents\\Python Scripts\\EOD from Yahoo\\"
I was running this code on Python 2.7 and it was working fine. Just recently I migrated to Python 3.5 and when I execute this code, I get the following output:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 145-146: truncated \UXXXXXXXX escape
After wrecking my head quite a bit, I deleted this line from the comments section:
The input directory for this is : "C:\Users\pavan\Documents\Python Scripts\EOD from Yahoo"
Now the program runs correctly.
My doubts:
- Why does this happen?
- What is the best way to write comments in Python 3.5 to avoid these kind of errors?