1

I am getting the above error for the code:

from_csv = pd.readcsv('2968986.log.txt',sep= r'^\')

The text file I'm parsing uses ^\ as a separator, using Python 2.7 on OsX. Thanks in advance.

chepner
  • 497,756
  • 71
  • 530
  • 681
shawn kumar
  • 59
  • 1
  • 8

1 Answers1

1

You are escaping your end single quote '

A "raw string literal" is a slightly different syntax for a string literal, in which a backslash, \, is taken as meaning "just a backslash" (except when it comes right before a quote that would otherwise terminate the literal) link

from_csv = pd.readcsv('2968986.log.txt',sep= r'^\\')

This escapes the escape character and allows you to post a backslash. You can find all the other escape characters here

Community
  • 1
  • 1
Michal Frystacky
  • 1,418
  • 21
  • 38
  • Hey thanks, that did the trick! I thought the 'r' in front precluded the need for the additional backslash... still wrapping my head around that. – shawn kumar Feb 11 '16 at 02:07
  • 1
    @shawnkumar If the `r` allowed you to put a quote inside the string without escaping it, how would it know which quotes are inside, and which one is the end of the string? – Barmar Feb 11 '16 at 02:38
  • @Barmar, thanks for the edit and you are correct Its mentioned in another post **[quote]** "A "raw string literal" is a slightly different syntax for a string literal, in which a backslash, \, is taken as meaning "just a backslash" (except when it comes right before a quote that would otherwise terminate the literal) **[/quote]** [here](http://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-in-python-and-what-are-raw-string-l) – Michal Frystacky Feb 11 '16 at 18:20