2.6. How to refer to files¶
2.6.1. File references should work on any computer!¶
If any of the code loads a file by loading
C:\Users\DonBowen\Desktop\Death_is_Which_Way\build\input\got1.txt, then that code will not work on your computer, or if I move my folder within my own computer!
That long file path is called an “absolute path”. No matter where you put your code, it will look for a file with that entire path.
Instead, use relative file paths, which only tells your code where to look relative to the current folder. So, now,
..\ tells it to look “one level up”, then inside the input folder.
(Aside: You can go up two levels with
..\..\ and so on…)
If you use relative paths, your code can work on anyone’s computer. This is kind of the point!
This chapter leans heavily on the wonderful Code and Data for the Social Sciences: A Practitioner’s Guide by Matthew Gentzkow and Jesse M. Shapiro1.
2.6.3. How was this chapter?¶
Hopefully, not like this
Anyways, please use this form for the whole chapter. (I didn’t want to put this on every single page.)