How get a Python pathlib Path from an Azure blob datastore?
I am trying to do some custom manipulation of a torch.utils.data.DataLoader in AzureML but cannot get it to instantiate directly from my azureml.core.Datastore :

ws = Workspace( # ... etc ... )
ds = Datastore.get(ws, datastore_name='my_ds')
am = ds.as_mount()

# HOW DO I GET base_path, data_file from am?

dataloader = DataLoader(
        ListDataset(base_path, data_file), #... etc...
    )



The value of am.path() is "$AZUREML_DATAREFERENCE_my_ds" but I cannot figure out how to go from that to a pathlib.Path as is expected by the constructor to ListDataset. Things I've tried include Path(am.path()) and Path(os.environ[am.path()]) but they don't seem to work.

It's clear that there's some answer, since : 

script_params = {
    '--base_path': ds.as_mount(), 
    '--epochs': 30,  
    '--batch_size' : 16,  
    '--use_cuda': 'true'
}
torch = PyTorch(source_directory='./',
                        script_params=script_params,
                        compute_target=compute_target,
                        entry_script='train.py',
                        pip_packages=packages,
                        use_gpu=True) 


seems to create a legit object. 

You can perhaps try using the DataPath class. It exposes attributes such as path_on_datastore which might be the path you're looking for.

To construct this class from your DataReference object i.e. variable am; you can use  create_from_data_reference() method.

Example:

ds = Datastore.get(ws, datastore_name='my_ds')
am = ds.as_mount()

dp = DataPath().create_from_data_reference(am)

base_path = dp.path_on_datastore


