Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

!ls in Jupyter notebook (Python 3)

If I use:

!ls '/Users/martyn/Documents/rawData'

it gives me a list of the files in the required directory.

But I want to paramterize this. I tried:

pathData = '/Users/martyn/Documents/rawData'
!ls pathData

But this gives the error:

ls: pathData: No such file or directory

I can see the problem ... but can't see how to fix it. Any help would be greatly appreciated.

like image 810
Martyn Avatar asked Feb 06 '23 01:02

Martyn


2 Answers

You probably need

!ls {pathData}

or

!ls $pathData
like image 122
Slam Avatar answered Feb 08 '23 16:02

Slam


Using only %ls gives you the list in your current directory.

like image 42
Marjan Radfar Avatar answered Feb 08 '23 16:02

Marjan Radfar