0

This is my problem:

fpaths=os.listdir(ligand_names_list[0].replace("'", "\\'"))
OSError: [Errno 2] No such file or directory: "5-iodoindirubin-3\\'-oxime"

There is a file named 5-iodoindirubin-3'-oxime but I cannot make os.listdir() to find it. Here's another attempt I made inspired by this thread Adding backslashes without escaping [Python] :

fpaths=os.listdir(ligand_names_list[0].__ repr __())
OSError: [Errno 2] No such file or directory: '"5-iodoindirubin-3\'-oxime"'

The problem in this case is the leading single quotes which I don't know how to remove them. Any idea?

Community
  • 1
  • 1
tevang
  • 518
  • 1
  • 4
  • 17

1 Answers1

6

You don't have to escape anything; you only have to escape things when entering string literals into your code. Once the string has the right value, you can just use it as it is.

Is the file in the current directory, or in some other directory? (The current directory is the same directory your Python script is in, unless you've changed it.) If it's not in the current directory, that would explain why it's not being found.

(You say it's a file; I hope it is a directory, since you're calling os.listdir() on it...)

kindall
  • 178,883
  • 35
  • 278
  • 309
  • Indeed it is a directory and you're right, there's no need to escape the single quotes here. – tevang Sep 25 '13 at 22:34