0

I wanted to get the directories in a path, so I did:

directory = os.path.dirname(os.path.abspath(__file__))
self.dir = directory

I then did this:

self.path = os.path.abspath(self.dir)
self.path_list = self.path.split(os.path.sep)

If I now print self.path_list, I get:

['', 'home', 'marienbad', 'python3']

Why is there an empty string at the start?

marienbad
  • 1,461
  • 1
  • 9
  • 19
  • 3
    Because there's an empty string between the start of the string and the first path separator in `'/home/marienbad/python3'`? That's how split works in general, it's not really specific to paths. – jonrsharpe Jun 09 '21 at 21:19
  • What? No there isn't. print("directory=", end="") print(directory) - there is no space between the = and the /. the_string = "this is a string" words = the_string.split() print(words) = ["this", "is", "a", "string"] again, no space. – marienbad Jun 09 '21 at 22:42
  • 1
    A space `' '` is **not** the same thing as an empty string `''`. – jonrsharpe Jun 10 '21 at 06:34

0 Answers0