0

I'm using iPython (Jupiter notebook) for visualizing my data. I planned storage my input data outside of the git repository liked that:

root/
|- git_repository/
|  |- research.ipynb
|- storage/
|  |- raw_data/
|  |  |- example.odx
...

I tried to import example.odx from all storages folder (raw_data, research_data...) to my code by this code below:

In  [1]: from os import listdir
         from os.path import isdir
         files = [file for file in listdir('../storage') if isdir(file)]
Out [1]: []

My output is [] mean I can not find my data. I tried some string path below however It still fails.

>>> from os import path
>>> path.join(path.dirname(__file__), '../')
NameError: name '__file__' is not defined
'./../storage', '../../storage', '../', './../', './../storage/', './..', '..'
Trần Đức Tâm
  • 4,037
  • 3
  • 30
  • 58
  • See this: https://stackoverflow.com/questions/38282336/is-it-possible-to-navigate-to-a-parent-directory-in-the-jupyter-tree – I_Al-thamary Jul 24 '19 at 07:07
  • 1
    Thank mr.@i_th for your suggested. I read it carefuly however this question mean how to change the home directory of the iPython server after started. I think that not point to my question. – Trần Đức Tâm Jul 24 '19 at 07:10

2 Answers2

1

. represents the current directory and .. represents the previous to the current directory

You can simply access your example.odx

path = '../storage/raw_data/example.odx'

from your git directory and it will work fine.

Ibtihaj Tahir
  • 636
  • 5
  • 17
0

Thank mr.@i_th and mr.@tbtihaj-tahir,

I found my problem's solution here:

Python not recognising directories os.path.isdir()

The iPython got a problem, I think. So I have to os.path.join the path which I invoke listdir on with the found file/directory, i.e.

for each in os.listdir(path):
    if os.path.isdir(os.path.join(path, each)):
        ....

[file for file in listdir('../storage') if isdir(file)] work well on windows cmd but [file for file in listdir('../storage') if isdir(join('../storage', file))] on jupyter notbook

Trần Đức Tâm
  • 4,037
  • 3
  • 30
  • 58