Now I have a file named Land/SeaMask
and I want to open it, but it cannot be recognized as a filename by programme, but as a directory, how to do it?
Asked
Active
Viewed 142 times
-1

Jiao Li
- 323
- 1
- 5
- 13
-
Show us your code and error you received. – DeepSpace Aug 30 '16 at 09:36
-
3Possible duplicate of [How do I escape forward slashes in python, so that open() sees my file as a filename to write, instead of a filepath to read?](http://stackoverflow.com/questions/29014481/how-do-i-escape-forward-slashes-in-python-so-that-open-sees-my-file-as-a-file) – Daniel Aug 30 '16 at 09:37
-
For a full discussion of this problem, see [this](http://stackoverflow.com/questions/9847288/is-it-possible-to-use-in-a-filename). – goldiex Aug 30 '16 at 09:40
-
try `Land\\seamask` – Daniel Lee Aug 30 '16 at 09:59
1 Answers
3
First of all I recommend you to find out how Python interpreter displays yours file name. You can do this simply using os
built-in module:
import os
os.listdir('path/to/directory')
You'll get a list of directories and files in directory you passed as argument in listdir
method. In this list you can find something like Land:SeaMask
. After recognizing this, open('path/to/Land:SeaMask')
will work for you.

finomayato
- 80
- 7