python 2.7 - Open file when path contain folder which name starts with double underscore -


I can not open a file if its path contains a folder that starts with the name double underscore. For example:

  file = open ('C: \ user \ __ foldername \ file.txt')  

This works if the folder's The name starts only with an underscore, but unfortunately I can not change its name.

Is there a solution?

The reason is not to open the file, because there is no double underscore, that's because an escape character in the string is. Windows paths should be defined using a raw string - from the back side, by avoiding the slash or by using the forward slash, by entering r ,

  file = Open file (r'C: \ user \ __ foldername \ file.txt ') file = open (' C: \\ user \\ __ folder name \\ file.txt ') file = open (' C: / user / __ foldername / file  

Something in the path should not be affected by double underscores, it is still a valid path name.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -