Can’t find any information on Path.BASE_PATH
online. Why? What am I missing?
I checked the pathlib
documentation here and found nothing on BASE_PATH
attribute. Why? What am I doing wrong?
Can’t find any information on Path.BASE_PATH
online. Why? What am I missing?
I checked the pathlib
documentation here and found nothing on BASE_PATH
attribute. Why? What am I doing wrong?
@thetj09
BASE_PATH is a fastai thing, which is defined in the fastcore library, which is nothing but a collection of slight modifications of already existing Python libraries and functions, to make life a little bit easier (and a few functions which dont exist anywhere else)
You can see here, the repr is modified to print the path without the BASE_PATH part.
This is great. Thanks.
So I looked at the Path
object. I checked the location of Path by using Shift tab
. It didn’t appear to be modified (File: /opt/conda/envs/fastai/lib/python3.8/pathlib.py). So I assumed it is the real pathlib without any modifications.
How to I go from looking at Path
in a sheet to this page? How do I systematically go there? can you please help me?
I’m no expert, but the way I thought of this was:
I first checked the Pathlib documentation and source code - could’nt find anything about the BASE_PATH variable.
Then I thought - what if BASE_PATH is just a dummy name. What if you can attribute a string to any variable name, and it would still work? For example, I tried, Path.BASE = ‘path/…’. But that didnt work. So BASE_PATH definitely must be hard coded somewhere.
So it must be within fastai. So just to be sure, I reloaded the notebook, and tried doing this without importing fastai or fastcore. That didnt work, so I knew it was definitely a fastai thing. And not any fastai module, it must be within fastcore, because thats what its meant to do.
So it must be stored in a place where all other Path modifications are stored. I know one of them - Path.ls() (this too is a fastai thing). So I did ??Path.ls
and saw that it is stored in a file inside fastcore, called xtras.py. So its quite likely that this too would be in the same file.
So i went there on github, did a quick CTRL+F BASE_PATH, and sure it was there…
Hope this helps you develop an idea of searching through source codes.
Cheers and stay safe
Amazing. But I can’t believe it is this convoluted to find what is happening where.
With the limited experience of fastai
which I have, I can suggest the following thing.
fastai
repo in GitHub and search in the repo. This will give you the file name where it is defined.fastcore
.I too struggled a lot initially, but now I am able to find the many things with relative ease. however this time I stumbled on this thing and had to do a Google search to find this post BASE_PATH
.
Thank you for sharing!
Jeremy briefly touches upon it here (Lesson 3 - Deep Learning for Coders (2020) - YouTube at time stamp 1:08:02)
2.5 - google and find this post
@jeremy is using a lot of dirty patches, which is not very cool for educational purposes, and I’ve seen a lot of criticism of fastai because of that.
He has his point on that, at the end of the day it is his library and his rule, but I think fastai could be much more popular if one uses more stand way of development.
@CreatorCreation the video gives a wrong impression of pathlib
for example @jeremy said that pathlib doesn’t have ls, it doesn’t, but it has glob function, which has more functions than its own ls implementation + it returns generator instead of list, which is better by definition