1 00:00:00,420 --> 00:00:06,590 I want to talk quickly about file parts, because for some people, this might be a new concept. 2 00:00:06,840 --> 00:00:12,930 Up until now I wrote, let's say something like Sa'adat Pie or sad dot text. 3 00:00:13,140 --> 00:00:20,010 And I was able to run this code because when I ran it in my terminal or command prompt, there were 4 00:00:20,040 --> 00:00:23,330 all in the same folder on my desktop. 5 00:00:23,520 --> 00:00:30,040 If I do present working directory on a Mac, it shows me where I'm currently at, which is the desktop. 6 00:00:30,270 --> 00:00:38,280 So I was able to run it like this because my script file was in the same folder as my SAT and test text. 7 00:00:39,330 --> 00:00:41,970 But what happens if this wasn't the case? 8 00:00:42,690 --> 00:00:47,650 We can actually jump back a directory by saying KDDI, dot, dot. 9 00:00:47,970 --> 00:00:56,160 So if we go back, my present working directory is now user and I go, so I'm not on the desktop anymore, 10 00:00:56,520 --> 00:01:03,390 so that if I try and run Python three and then say script. 11 00:01:06,100 --> 00:01:11,560 Well, can't find the file, right, so let's go back to desktop. 12 00:01:13,920 --> 00:01:18,720 And try to figure out this problem, I'm going to for now make a directory. 13 00:01:20,380 --> 00:01:22,420 And call it, let's say. 14 00:01:23,940 --> 00:01:27,370 Well, a very generic folder or let's just call it at. 15 00:01:28,750 --> 00:01:31,240 So now I have an app folder. 16 00:01:32,220 --> 00:01:33,270 I can move. 17 00:01:34,680 --> 00:01:42,480 This sad text into the app folder now, so if I grab the sad text and move it to the app folder. 18 00:01:43,850 --> 00:01:45,740 If I go back now and. 19 00:01:47,040 --> 00:01:51,210 Try to access Saddat text, so let's say Python three. 20 00:01:52,350 --> 00:01:53,190 Script up by. 21 00:01:55,380 --> 00:02:00,990 Well, if I go back, I've appended Sadad text, so it's actually creating it for me. 22 00:02:01,440 --> 00:02:10,800 So instead, let's actually remove sad text because we actually have one already in here in the app 23 00:02:11,160 --> 00:02:12,630 instead of appending it. 24 00:02:12,840 --> 00:02:14,400 Let's just do a read. 25 00:02:15,060 --> 00:02:18,930 If I try to read now, I get a file not found. 26 00:02:18,930 --> 00:02:25,140 Er Saddat text doesn't exist because it checks the desktop and on the desktop we have nothing. 27 00:02:25,230 --> 00:02:26,580 We don't have said that text. 28 00:02:27,430 --> 00:02:28,890 So how can we get around this. 29 00:02:29,580 --> 00:02:39,090 Well I simply say that I want to go into the directory app Slash said dot text so that if I run this. 30 00:02:41,850 --> 00:02:47,760 Now it's it it's reading it, but it's an unsupported operation, so let's just turn this into a read. 31 00:02:51,610 --> 00:02:53,680 And we don't need any of this, so let's just. 32 00:02:56,660 --> 00:02:58,610 Read here if I run this. 33 00:02:59,740 --> 00:03:04,150 All right, it's working now I'm able to change the Forbath. 34 00:03:05,480 --> 00:03:11,900 Now, if you're on a non Unix based system, that is, if you're not on a Mac or Linux and you're on 35 00:03:11,900 --> 00:03:16,960 Windows most of the time instead of the slash, it's a back slash like this. 36 00:03:17,720 --> 00:03:23,430 So Windows and Unix systems have different file paths and file system in place. 37 00:03:23,930 --> 00:03:30,320 So this is something that you can read up on depending on your file path and why your prison working 38 00:03:30,320 --> 00:03:35,220 directory is you'll have a better idea of how it should look on windows. 39 00:03:35,240 --> 00:03:39,930 It's usually something like C and then backslash and then you'll have different file path. 40 00:03:40,910 --> 00:03:43,610 Now this is called a relative path. 41 00:03:43,610 --> 00:03:49,310 So relative to where I am, where I'm writing the script from, I am going to go from here into the 42 00:03:49,310 --> 00:03:50,900 app, into Sadaa text. 43 00:03:51,320 --> 00:03:54,680 I could have also copied this entire file path. 44 00:03:57,830 --> 00:04:02,780 And this is called an absolute path, so if I run this. 45 00:04:04,670 --> 00:04:11,090 This still works because I'm giving an absolute path, it's saying, hey, on this computer, this exists 46 00:04:11,090 --> 00:04:14,340 from the root user all the way into here. 47 00:04:14,750 --> 00:04:16,490 So this is another way of doing it. 48 00:04:16,760 --> 00:04:20,390 Most of the time you'll see relative because it's a lot simpler. 49 00:04:21,880 --> 00:04:29,540 Finally, you might sometimes see something like a dot slash dots simply means from the current folder. 50 00:04:29,920 --> 00:04:32,830 So if I run this, it's still going to work. 51 00:04:32,950 --> 00:04:39,030 It's going to say, hey, from the current folder, go to app folder, then go to the text folder. 52 00:04:39,760 --> 00:04:50,310 If I do dot, dot, slash like this, if I run this, I'll get an air dot dot means back a folder. 53 00:04:50,650 --> 00:04:58,780 So instead of our present working directory being desktop because we did dot dot will actually go into 54 00:04:58,810 --> 00:05:04,450 my user account and it's going to try and find an ugly slash app. 55 00:05:04,960 --> 00:05:07,630 Slash said text which is not going to find. 56 00:05:09,340 --> 00:05:14,470 Anyway, this is a bit of a tangent, but I want to let you know that these file parts are important 57 00:05:14,470 --> 00:05:23,140 and it's really dependent on a what operating system you're using, like Mac or Windows and also where 58 00:05:23,140 --> 00:05:24,460 you're calling the file from. 59 00:05:25,900 --> 00:05:28,270 Let's continue our discussion of files in the next video. 60 00:05:29,270 --> 00:05:36,500 One quick note that I forgot to mention, there's a really useful built in module in Python and you 61 00:05:36,500 --> 00:05:43,220 can see here it's new in version three point four called Path Lab. It's an object oriented filesystem 62 00:05:43,400 --> 00:05:43,970 path. 63 00:05:44,270 --> 00:05:48,410 Now, the main thing is you can see how to use it through the documentation. 64 00:05:48,710 --> 00:05:55,160 But the key thing is that if you're building a program that, lets say reads something from the file 65 00:05:55,160 --> 00:05:56,450 system, like a file. 66 00:05:57,410 --> 00:06:04,940 And this program can be used both on Windows and Mac and Linux systems, you want a way to make sure 67 00:06:04,940 --> 00:06:06,830 that it works on both, right? 68 00:06:06,830 --> 00:06:11,480 Because we saw how Mac and Windows have different file system with different slashes. 69 00:06:12,440 --> 00:06:16,160 Well, Pat, Leyb Library actually works with both. 70 00:06:16,610 --> 00:06:22,160 You can see over here if you want to manipulate Windows path on a Unix machine or vice versa, this 71 00:06:22,160 --> 00:06:23,750 is going to work for you. 72 00:06:25,480 --> 00:06:32,380 And it's a good way for you to create software that is compatible with both systems because Path Live 73 00:06:32,380 --> 00:06:37,770 is going to take care of the file pass for you based on what machine is running your code. 74 00:06:39,410 --> 00:06:43,640 Now, this is something you can read on your own and experiment, but I wanted to let you know that 75 00:06:43,640 --> 00:06:48,860 this does exist and it is a useful library for you to have in the back of your pocket. 76 00:06:49,760 --> 00:06:50,480 That's it for now. 77 00:06:50,870 --> 00:06:51,770 I'll see in the next one. 78 00:06:52,400 --> 00:06:52,730 Bye bye.