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, clean_data.py loads ..\input\got1.txt. The ..\ 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!

2.6.2. Credits


2.6.3. How was this chapter?

Hopefully, not like this