If I run the following code:
from pathlib import Path
path = Path('data/mnist')
path.ls()
I get the following error:
AttributeError: ‘PosixPath’ object has no attribute ‘ls’
Looking at the Path class in pathlib, I find:
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args, init=False)
if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
self._init()
return self
I'm guessing this means it will run PosixPath instead, which is:
class PosixPath(Path, PurePosixPath):
"""Path subclass for non-Windows systems.
On a POSIX system, instantiating a Path should return this object.
"""
__slots__ = ()
Not too sure what this means.
And actually, I can't find Path.ls() at all in the pathlib source code. Does this make sense? The coding tutorial I'm following used it (on a windows machine).