1

I'm creating a function that uses pandas to read different csv files located in the same folder in my workign directory. I used a loop to attach the individual file names onto the path name for the folder. My problem is that some of my file names are 'freq1, freq5, freq15' so when using the backslash as Window's path separator I end up with a string '\freq1','\freq5', etc. However when I run the file the names convert to \x0creq1' because of the form-feed special character for separating print pages. Is there a way to turn off or pass this special character so I can list my file names?

  • If your backslashes are read as syntactic rather than literal, there's a larger problem with your code. Let us see the code, and we should be able to identify the problem. – Charles Duffy Jul 16 '19 at 19:37
  • That is to say -- if you open a file that contains a literal backslash, read that value, and then print it in the Python REPL, it'll be doubled, because that's how the REPL represents a single literal backslash. If your strings are being evaluated as Python syntax rather than read as literals, that's a bug in the code doing the reading, and we'd need to see how it's written to speak to how to fix it. – Charles Duffy Jul 16 '19 at 19:38
  • (To be clear, a backslash *in your code* can be put inside a raw string, or doubled in a regular string; but a backslash *in your data* -- read from a file, or in `os.listdir()` results, or similarly -- doesn't need any of things to be done; backslash escapes are language syntax for how strings in your code are interpreted when they're being parsed into data, not a modification that Python silently performs once something *already is* data). – Charles Duffy Jul 16 '19 at 19:41
  • ...anyhow -- please [edit] to provide enough details to distinguish from the linked duplicate -- ideally, a proper [mcve] -- and then we'll be in a position to reopen and answer this question. – Charles Duffy Jul 16 '19 at 19:43
  • It was as simple as doubling my backslashes in the regular string. Thanks for the help Charles. – Jake Catron Jul 16 '19 at 20:00

0 Answers0