Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 2
    @Gareth, I am very lazy and often found myself using '/'. However in the long run the use of os.path is more convenient. It also allows you to use mydir and myfile as variables that you can easily modify. Commented Jun 1, 2010 at 22:48
  • 29
    The only thing to be careful with on raw strings is that they can't end with \ Commented Jun 29, 2010 at 16:15
  • 2
    You can use os.path.join() to remove the need to end paths with \. Commented Aug 5, 2014 at 14:53
  • 1
    I like the r (raw string) syntax. Useful if you're copying a long path where you'd usually have to replace all the backslashes with forward slashes Commented Aug 21, 2016 at 5:07
  • raw string can end with \\ so we can concatenate a file to the path: codecs.open(r"C:\maXbox\EKON24\tweet_data\\" + file, 'r', encoding='utf-8') as f: Commented Jun 24, 2020 at 13:34