1 00:00:00,000 --> 00:00:01,600 [no audio] 2 00:00:01,600 --> 00:00:06,000 Friends, we are going to discuss about 'os' module, operating system 3 00:00:06,000 --> 00:00:09,610 module, which is very, very important whenever if you're going 4 00:00:09,600 --> 00:00:17,510 to automate your tasks at server side, because the 'os' module, 5 00:00:17,500 --> 00:00:22,400 using this 'os' module you can work or interact with your operating system. 6 00:00:23,000 --> 00:00:26,200 See whenever you are able to interact with your operating system, 7 00:00:26,200 --> 00:00:29,810 you can automate some tasks like creating directory, removing, 8 00:00:29,800 --> 00:00:34,610 changing your directory, knowing your directory, right, and many more. 9 00:00:34,600 --> 00:00:36,700 So, that's why this is very, very important. 10 00:00:37,000 --> 00:00:43,600 And just to get confidence on your 'os' module, myself 11 00:00:43,600 --> 00:00:49,500 I am dividing this module as four parts, that is simply 12 00:00:49,500 --> 00:00:54,200 'os', and 'os.path()', then 'os.system()', and then 'os.walk()' 13 00:00:55,200 --> 00:00:59,200 So that means I want to explain this 'os' module with step-by-step. 14 00:01:00,100 --> 00:01:02,300 So in this video, we are going to see some simple 15 00:01:02,300 --> 00:01:05,500 operations with your 'os' module, right? 16 00:01:05,500 --> 00:01:09,910 See this is a module, right, 'os' module. That means using this 'os' module, 17 00:01:09,900 --> 00:01:12,400 you can work with your Windows operating systems, 18 00:01:12,400 --> 00:01:15,600 as well as Unix-like systems, right? 19 00:01:15,600 --> 00:01:19,710 Let me take a very simple variable from your 'os' module. 20 00:01:19,700 --> 00:01:23,800 You know module always consists of some functions and variables, 21 00:01:23,800 --> 00:01:27,900 right, or simply module consists of some operations. 22 00:01:27,900 --> 00:01:31,510 One of the operation is 'os.sep'. 23 00:01:31,500 --> 00:01:32,700 What is this 'os.sep'? 24 00:01:33,900 --> 00:01:38,710 See, if I take some Windows operating system path, right? 25 00:01:38,700 --> 00:01:45,500 Let me take this path. See this '\' is called OS separator on your Windows. 26 00:01:46,000 --> 00:01:48,100 Let me take your Unix systems. 27 00:01:49,500 --> 00:01:52,410 So now this is the different '/', right. 28 00:01:52,400 --> 00:01:56,600 This '/' is the separator for your Unix-like systems. Now, 29 00:01:58,000 --> 00:01:59,600 if you want to set some 30 00:02:01,000 --> 00:02:03,200 path separator you don't need to 31 00:02:03,200 --> 00:02:07,200 set manually, based on your operating system Python will set it. 32 00:02:08,199 --> 00:02:10,699 Suppose let me enter into my Python terminal, 33 00:02:12,100 --> 00:02:14,400 and you know whenever if you want to use 'os' module, 34 00:02:14,400 --> 00:02:19,700 you have to import your 'os', right, and then to see list of your 'os' 35 00:02:21,200 --> 00:02:24,500 module operations simply you can run 'dir(os)'. 36 00:02:24,800 --> 00:02:28,310 So, these all are the operations with your 'os', but I am 37 00:02:28,300 --> 00:02:32,100 going to divide this into 4 parts, and I am going to explain that step by step. 38 00:02:33,700 --> 00:02:36,510 So, you know that guys, these all are like some 39 00:02:36,500 --> 00:02:38,700 of them are functions, and some of them are variables. 40 00:02:38,700 --> 00:02:40,700 If you want to know which is a function, 41 00:02:40,700 --> 00:02:42,600 and which is a variable, you have to go with 'help'. 42 00:02:43,300 --> 00:02:46,200 If you press 'Enter', right, you are going to get your 43 00:02:46,200 --> 00:02:51,700 'os' module information with functions, and then some data, right. 44 00:02:51,700 --> 00:02:53,810 So if you want to see you can go through that. 45 00:02:53,800 --> 00:02:54,900 I'm not going with that. 46 00:02:56,300 --> 00:02:58,709 Let me simply print on your Windows operating system, 47 00:02:58,700 --> 00:03:03,200 'os.separator'. You're getting '/'. Same way, let me 48 00:03:03,200 --> 00:03:04,800 go with your Unix-like systems. 49 00:03:04,800 --> 00:03:08,000 I am going to enter into my Python terminal on my Unix system, 50 00:03:08,500 --> 00:03:09,600 that is Linux system. 51 00:03:10,100 --> 00:03:15,500 Let me 'import os' first. Then I am printing 'os.separator'. 52 00:03:17,100 --> 00:03:21,200 Right. Automatically based on your operating system, Python is finding. 53 00:03:21,200 --> 00:03:22,700 Now, this is the different '/', right? 54 00:03:24,300 --> 00:03:28,400 Fine. Now, let us assume that, let us assume that 55 00:03:29,300 --> 00:03:32,400 I have some simple directory called, 56 00:03:32,400 --> 00:03:36,000 let me take on my Desktop. Okay, I'm going to 57 00:03:36,000 --> 00:03:37,800 create some directory, new directory 58 00:03:37,800 --> 00:03:40,600 [no audio] 59 00:03:40,600 --> 00:03:47,000 like 'hi'. Then I'm going to create one more directory, one more directory. 60 00:03:47,400 --> 00:03:48,600 Let me create it. 61 00:03:49,800 --> 00:03:55,800 Simply I am going to create like, I will take 'New'. 62 00:03:55,800 --> 00:03:57,800 [no audio] 63 00:03:57,800 --> 00:04:00,200 Fine. Now, let me take this path. 64 00:04:01,000 --> 00:04:02,810 So 'path' is always a string guys. 65 00:04:02,800 --> 00:04:05,900 If you go anywhere, right, 'path' is always a string. 66 00:04:05,900 --> 00:04:08,300 Let me take 'path' is this one. 67 00:04:08,700 --> 00:04:10,300 I am storing into some variable. 68 00:04:10,300 --> 00:04:11,600 First I will take 'hi'. 69 00:04:12,600 --> 00:04:13,600 This is my path. 70 00:04:15,000 --> 00:04:18,100 Right. Okay, you're getting some error. 71 00:04:19,100 --> 00:04:20,800 Then let me take 'New' also. 72 00:04:22,300 --> 00:04:27,100 See why, whenever if you take a path your Python is giving some error 73 00:04:28,500 --> 00:04:32,500 but if I take on your Unix-like systems, right, 74 00:04:32,500 --> 00:04:34,200 let me take 'path= 75 00:04:34,200 --> 00:04:37,000 [no audio] 76 00:04:37,000 --> 00:04:38,200 /home/ec2-user'. 77 00:04:38,200 --> 00:04:41,200 [no audio] 78 00:04:41,200 --> 00:04:44,200 Right. Now, it's taking perfectly. The same thing, 79 00:04:44,200 --> 00:04:46,600 let me take different path. Instead of this one 80 00:04:46,600 --> 00:04:51,000 let me take some 'f', then in that let me take some 81 00:04:52,600 --> 00:04:54,400 '\python\videos', something like that. 82 00:04:54,400 --> 00:04:58,800 Now, it's taking. There is no error. Why you are getting an error 83 00:04:58,800 --> 00:05:02,000 whenever if you're assigning a path to some variable? 84 00:05:02,000 --> 00:05:05,400 Not only variable, even if you try to print your path you will get an error. 85 00:05:05,400 --> 00:05:11,100 [no audio] 86 00:05:11,100 --> 00:05:12,100 See that. 87 00:05:12,100 --> 00:05:14,400 [no audio] 88 00:05:14,400 --> 00:05:18,100 The reason is, guys you know in your Python you have some 89 00:05:18,100 --> 00:05:25,800 special characters like '/n', '/t', '/r', right, '/v', and then '/u', is unicode. 90 00:05:27,000 --> 00:05:31,900 Right. That's why to avoid that special case purpose 91 00:05:31,900 --> 00:05:34,300 you have to provide '//' in your Python. 92 00:05:34,300 --> 00:05:38,100 Now see that. There is no problem by taking in this way. 93 00:05:38,100 --> 00:05:40,100 [no audio] 94 00:05:40,100 --> 00:05:43,010 So, the problem is with your only Windows operating 95 00:05:43,000 --> 00:05:46,110 system not with your Unix-like systems, because in Unix-like 96 00:05:46,100 --> 00:05:49,409 systems the path separator is this one, but Windows this is 97 00:05:49,400 --> 00:05:52,300 the path separator and you know '\n' is a special character, 98 00:05:52,300 --> 00:05:53,600 '\r' is a special character. 99 00:05:53,600 --> 00:05:58,600 '\u' is some unique code, that's why, that's why whenever 100 00:05:58,600 --> 00:06:00,200 if you are providing a path 101 00:06:00,200 --> 00:06:04,310 on your Windows operating systems always, whether it is having 102 00:06:04,300 --> 00:06:08,909 some special characters or not, try to provide instead of '\', 103 00:06:08,900 --> 00:06:11,610 just try to provide '\\'. By providing '\\' 104 00:06:11,600 --> 00:06:14,010 there is no problem with your Windows, 105 00:06:14,000 --> 00:06:16,200 but if you don't provide, sometimes you will get an error. 106 00:06:17,200 --> 00:06:22,010 If you don't provide '\\' in your path, sometimes there is a chance to get an error. 107 00:06:22,000 --> 00:06:28,010 That's why just to avoid error, even by mistake to avoid your error 108 00:06:28,000 --> 00:06:31,500 try to take always '\\' in your path. That is the good practice. 109 00:06:31,500 --> 00:06:32,600 Just remember this point. 110 00:06:34,000 --> 00:06:35,000 That's fine. 111 00:06:35,800 --> 00:06:37,200 Now, what is the next operation? 112 00:06:37,700 --> 00:06:42,000 'os.getcwd()'. Guys to know your current working directory 113 00:06:42,000 --> 00:06:44,400 on Windows you have to run 'cd' command, on your Unix 114 00:06:44,400 --> 00:06:47,700 you have to run 'pwd' command. But instead of running this 115 00:06:47,700 --> 00:06:50,100 one and this one based on your operating system 116 00:06:50,100 --> 00:06:54,200 just go and run this. Irrespective of your operating system Python 117 00:06:54,200 --> 00:06:57,100 will take care and it will give the current working directory. 118 00:06:57,400 --> 00:06:59,700 See that. I am going to take first Windows. 119 00:07:00,800 --> 00:07:04,700 Let me print. Let me print 'os.getcwd()'. 120 00:07:05,500 --> 00:07:07,600 See that, you're getting some path. 121 00:07:07,600 --> 00:07:14,300 Let me go and run it on your Unix as well. 'os.getcwd()'. 122 00:07:14,300 --> 00:07:16,300 I can also assign this output into some variable. 123 00:07:17,700 --> 00:07:20,400 Sorry, I have given some extra parentheses. 124 00:07:20,400 --> 00:07:24,200 [no audio] 125 00:07:24,200 --> 00:07:27,710 Right. Or let me take current working directory variable, 'cwd'. 126 00:07:27,700 --> 00:07:31,000 I can assign 'os.getcwd()', 127 00:07:32,100 --> 00:07:35,500 and then I can print that 'cwd'. No problem. That's it. 128 00:07:36,900 --> 00:07:40,200 See now you don't need to worry about your operating system, 129 00:07:41,000 --> 00:07:43,700 okay. Generally to get your current working directory on Windows 130 00:07:43,700 --> 00:07:45,800 you have to run 'cd' command, on your Unix-like systems 131 00:07:45,800 --> 00:07:49,700 you have to run 'pwd' command, but if you go with Python 132 00:07:49,700 --> 00:07:53,200 you don't worry about which operating system you are using to 133 00:07:53,200 --> 00:07:56,000 get your current directory. Python will take care of that. 134 00:07:56,000 --> 00:08:00,200 The only thing you have to remember, 'os.getcwd()'. That's it. 135 00:08:01,300 --> 00:08:06,010 Then 'os.chdir()'. Let me do one thing. As of now 136 00:08:06,000 --> 00:08:08,600 you are under this location, 'C:\Users\Automation'. 137 00:08:09,400 --> 00:08:13,900 Now, I want to move into different location. Then simply run, in your 138 00:08:13,900 --> 00:08:17,800 script also you can use this, 'os.chdir()'. Guys, you have to 139 00:08:17,800 --> 00:08:20,300 provide 'path', to which location you want to move. 140 00:08:21,300 --> 00:08:23,710 'path' is always a string, and remember that you are working on 141 00:08:23,700 --> 00:08:26,300 Windows, you have to provide two '\\' in your 'path'. 142 00:08:26,300 --> 00:08:28,300 [no audio] 143 00:08:28,300 --> 00:08:30,100 Okay, already we are providing same path, right. 144 00:08:30,100 --> 00:08:31,300 Let me remove this 'Automation'. 145 00:08:31,300 --> 00:08:33,200 [no audio] 146 00:08:33,200 --> 00:08:35,200 Previously you are under this location. 147 00:08:35,200 --> 00:08:40,210 Now, I am moving into this location with the help of this syntax. Now see that. 148 00:08:40,200 --> 00:08:43,900 What is the current location where you are, using 'getcwd()'. 149 00:08:44,900 --> 00:08:45,900 That's it. 150 00:08:46,500 --> 00:08:49,700 Same thing you can do it on your Unix as well. Right. Let me do it 151 00:08:49,700 --> 00:08:51,799 at least this one on your Unix-like systems. 152 00:08:51,799 --> 00:08:58,500 So, I want to move, 'os.chdir()', just I want to move into 'home' location. 153 00:09:00,100 --> 00:09:01,600 Now, see that, where you are. 154 00:09:05,100 --> 00:09:09,000 That's it. So guys, is make sure that while working with Unix-like 155 00:09:09,000 --> 00:09:12,400 systems don't provide any double slashes in your path, 156 00:09:12,400 --> 00:09:14,000 but in Windows you have to provide it. 157 00:09:14,800 --> 00:09:15,800 Right. Fine. 158 00:09:16,500 --> 00:09:22,400 See, again to list some files on Windows 159 00:09:22,400 --> 00:09:26,100 you have to use 'dir' command, on Linux you have to use 'ls' command, 160 00:09:26,400 --> 00:09:29,600 but instead of that simply you can use 'os.listdir()'. 161 00:09:30,200 --> 00:09:35,300 Right. Let me run it on my Linux at least. Same you can run it 162 00:09:35,300 --> 00:09:37,500 on your Windows as well. 'print 163 00:09:37,500 --> 00:09:42,000 (os.listdir())'. See the output. 164 00:09:42,000 --> 00:09:44,000 [no audio] 165 00:09:44,000 --> 00:09:47,200 Right. Otherwise, I will do one thing, 'os.chdir()'. 166 00:09:47,200 --> 00:09:52,000 I want to move into '/home/ec2-user'. So in this location 167 00:09:52,000 --> 00:09:57,000 I want to list. So you can move and then you can list or 168 00:09:57,000 --> 00:09:59,400 directly you can do one thing. Let me do it. 169 00:10:00,200 --> 00:10:06,400 'os.', 'print(os.listdir())'. 170 00:10:06,400 --> 00:10:10,510 You can also provide path, for which location you need to list out your values. 171 00:10:10,500 --> 00:10:13,200 I mean files and directories using in this way. 172 00:10:13,200 --> 00:10:15,200 [no audio] 173 00:10:15,200 --> 00:10:18,200 I think I need to provide one more parentheses. Fine. See that. 174 00:10:19,200 --> 00:10:26,400 See, 'os.listdir()' is going to take a path, or if you don't provide a path 175 00:10:26,400 --> 00:10:31,400 it will take your current location as a path, and it will list in the 176 00:10:31,400 --> 00:10:33,500 current location whatever the files and directories 177 00:10:33,500 --> 00:10:37,000 are there. And output is always a list make sure of that. 178 00:10:37,400 --> 00:10:38,800 Output is always a list. 179 00:10:38,800 --> 00:10:40,300 You have to remember this, because sometimes 180 00:10:40,300 --> 00:10:44,000 you need to use this output. Right. Fine. 181 00:10:44,700 --> 00:10:47,700 So 'os.listdir()' without path, with path. 182 00:10:48,800 --> 00:10:53,200 Then 'os.mkdir()'. See you can use this just 183 00:10:53,200 --> 00:10:55,800 to create your directory maybe on Windows or Unix. 184 00:10:55,800 --> 00:10:58,400 You can practice with your Windows as well guys. 185 00:10:58,400 --> 00:11:01,400 I am doing as of now on Linux, but you can do same thing on 186 00:11:01,400 --> 00:11:06,200 Windows as well. See as of now in the current location first, let me check 187 00:11:06,200 --> 00:11:13,110 what are the files and directories are there with the help of 'os.listdir()'. 188 00:11:13,100 --> 00:11:15,100 So current location, no need to provide path. 189 00:11:16,400 --> 00:11:18,810 Now, what I am doing is 'os.mkdir()' 190 00:11:18,800 --> 00:11:21,600 I'm going to create suppose "narendra" directory. 191 00:11:25,200 --> 00:11:27,100 What happened? Maybe, 192 00:11:27,100 --> 00:11:30,300 [no audio] 193 00:11:30,300 --> 00:11:33,000 'home'. We are under 'home' location, right. 'home', 194 00:11:33,000 --> 00:11:34,210 I don't have permission for that. 195 00:11:34,200 --> 00:11:39,800 Let me move into my 'home', 'ec2-user' home. 'os.chdir()'. 196 00:11:39,800 --> 00:11:42,900 [no audio] 197 00:11:42,900 --> 00:11:47,400 Then '/home'. '/home', I don't have permissions in that location, 198 00:11:47,400 --> 00:11:51,300 that's why I have to enter into my location, 'ec2-user'. 199 00:11:52,700 --> 00:11:56,600 Then here I can make directory called, suppose anything, 'narendra'. 200 00:11:56,600 --> 00:11:58,800 [no audio] 201 00:11:58,800 --> 00:11:59,800 Right. Now 202 00:12:01,000 --> 00:12:04,300 'os.listdir()'. 203 00:12:05,400 --> 00:12:09,800 See previously we ran 'os.listdir()', this location. See the list of files 204 00:12:09,800 --> 00:12:12,300 and directories you have. Now see that you have 205 00:12:12,300 --> 00:12:14,900 somewhere 'narendra'. Previously you were not having this. 'udemy' 206 00:12:14,900 --> 00:12:18,500 and 'June-2019', but between 'June-2019' you have a 'narendra', 207 00:12:18,500 --> 00:12:21,500 because just now we created that with the help of 'os.mkdir()'. 208 00:12:23,000 --> 00:12:24,300 Right. Fine. 209 00:12:24,300 --> 00:12:26,300 [no audio] 210 00:12:26,300 --> 00:12:28,900 And make sure that guys, whenever if you are providing 211 00:12:28,900 --> 00:12:33,900 a directory name that is also a string, you have to write inside of quotation 212 00:12:35,100 --> 00:12:39,400 Fine. The next one is 'os.mkdirs()', and then 'path'. 213 00:12:40,300 --> 00:12:44,900 That means if it is in the current location, you can use 'os.mkdir(), 214 00:12:44,900 --> 00:12:47,000 but recursively if you want to create, 215 00:12:47,000 --> 00:12:49,700 I mean suppose assume that you are in somewhere 216 00:12:49,700 --> 00:12:53,800 '/home/ec2-user'. In this path you are. Now, 217 00:12:53,800 --> 00:12:58,310 I want to create some 'xyz'. In that 'xyz' I want to create 'x'. So at a time 218 00:12:58,300 --> 00:13:02,600 I want to create xyz', and then in that 'x'. Recursively I want to create this path. 219 00:13:03,800 --> 00:13:08,000 Then at that time you have to take 'os.mkdirs()'. See that. 220 00:13:08,000 --> 00:13:12,500 If I take simply 'os.mkdir()', 221 00:13:12,500 --> 00:13:14,600 suppose I want to create under 'udemy' 222 00:13:15,900 --> 00:13:18,400 I want to create 'xyz' and then 'x' path. 223 00:13:18,400 --> 00:13:20,300 [no audio] 224 00:13:20,300 --> 00:13:27,100 Right. It's not possible. But if I take 'os.mk', this one, right, 225 00:13:27,100 --> 00:13:33,300 'os.mkdirs()'. Now, let's observe that. Under 'udemy' 226 00:13:34,000 --> 00:13:38,000 I want to create 'xyz', and then in that 'x' I want to create. 227 00:13:38,000 --> 00:13:40,000 [no audio] 228 00:13:40,000 --> 00:13:46,500 Right. Now just list, 'os.listdir(udemy). 229 00:13:46,500 --> 00:13:50,700 [no audio] 230 00:13:50,700 --> 00:13:51,700 See the result. 231 00:13:51,700 --> 00:13:53,700 [no audio] 232 00:13:53,700 --> 00:13:56,100 Right. That's it. 233 00:13:57,700 --> 00:14:03,500 Otherwise come out here, 'ls udemy'. Now recursively 234 00:14:03,500 --> 00:14:07,000 you can see I think using 'tree' command, see that, 235 00:14:07,000 --> 00:14:08,500 sorry, maybe 'tree' is not there. 236 00:14:08,500 --> 00:14:12,100 Let me install it. 'sudo yum install tree' command. 237 00:14:12,100 --> 00:14:14,800 [no audio] 238 00:14:14,800 --> 00:14:20,400 So that you can see recursively. 'tree udemy'. See that inside 'udemy' 239 00:14:20,400 --> 00:14:22,500 you created 'xyz', inside that 'x'. 240 00:14:22,500 --> 00:14:25,100 So, recursively if you want to create you have to use 241 00:14:25,100 --> 00:14:26,900 'os.mkdirs()'. 242 00:14:27,900 --> 00:14:30,100 Now to remove some path you can use 243 00:14:30,100 --> 00:14:33,600 'os.remove', right. And then recursively if you want to remove 244 00:14:33,600 --> 00:14:36,500 I mean just now we created recursively, right. Under 245 00:14:36,500 --> 00:14:40,610 'udemy', 'xyz', under that 'x'. Now if you want to create 'x', or recursively 246 00:14:40,600 --> 00:14:45,210 this 'xyz' under 'udemy', then you have to use 'os.removedir()', 247 00:14:45,200 --> 00:14:49,200 then your path. Path is always a string. Then you can also create 248 00:14:49,200 --> 00:14:51,600 some directory using simply 'os.rmdir()'. 249 00:14:53,100 --> 00:14:58,310 So guys, these are some of the simple 'os' operations. Along with that 250 00:14:58,300 --> 00:15:03,600 if you want to rename some file name, right, 'os.rename' 251 00:15:03,600 --> 00:15:05,900 source location, destination location. 252 00:15:05,900 --> 00:15:06,900 Both must be a string. 253 00:15:07,300 --> 00:15:08,300 You just try it. 254 00:15:09,000 --> 00:15:13,100 Then 'os.environ()', which is very, very important guys. See 255 00:15:13,100 --> 00:15:15,800 let me run it on my command line, 'env' command. 256 00:15:16,200 --> 00:15:19,900 You're getting some environment variable values 257 00:15:19,900 --> 00:15:21,300 of your operating system, right. 258 00:15:22,300 --> 00:15:25,700 Now same things you can get it with your Python as well, 259 00:15:25,700 --> 00:15:30,300 I mean your Windows or Linux operating system environment 260 00:15:30,300 --> 00:15:38,200 variables you can get it with the help of 'os.getenviron'. 261 00:15:38,800 --> 00:15:39,800 See the output. 262 00:15:39,800 --> 00:15:41,800 [no audio] 263 00:15:41,800 --> 00:15:43,800 Oh man, 'get' 264 00:15:43,800 --> 00:15:45,500 [no audio] 265 00:15:45,500 --> 00:15:54,500 Simply, sorry. 'os.environ()'. Yeah. 'os.', ;e-n-v-i', 'environ'. 266 00:15:54,500 --> 00:15:57,500 [no audio] 267 00:15:57,500 --> 00:15:59,000 What happened? Let me check it. 268 00:16:05,500 --> 00:16:06,500 Where we are? 269 00:16:06,500 --> 00:16:12,500 [no audio] 270 00:16:12,500 --> 00:16:15,000 A, B, C, D, E, E 271 00:16:15,000 --> 00:16:21,500 [no audio] 272 00:16:21,500 --> 00:16:24,200 Oh, sorry, 'os.' 273 00:16:24,200 --> 00:16:25,500 Yeah, this is a variable, right? 274 00:16:25,500 --> 00:16:27,500 [no audio] 275 00:16:27,500 --> 00:16:30,800 'environ', See the output. 276 00:16:32,000 --> 00:16:34,600 You are getting some environment variable information. 277 00:16:34,600 --> 00:16:36,500 [no audio] 278 00:16:36,500 --> 00:16:40,000 Right. So, simply 'print(os. 279 00:16:40,000 --> 00:16:40,010 [no audio] 280 00:16:42,400 --> 00:16:47,100 'e-n-v-i-r-o-n', 'environ'. That's it. 281 00:16:48,400 --> 00:16:51,410 So, you are able to get your environment variable values 282 00:16:51,400 --> 00:16:53,900 of your operating system using 'os.environ()'. 283 00:16:54,900 --> 00:16:56,300 Right. Then fine. 284 00:16:56,300 --> 00:17:00,300 What is the user, 'uid'? You know, you have a 'uid' for your 285 00:17:00,300 --> 00:17:03,600 each and every user on your operating systems, right? 286 00:17:03,600 --> 00:17:08,000 Let me run it. 'uid' of this. Sorry, 'id'. 287 00:17:08,500 --> 00:17:15,300 We're going to get 'uid' of your user 500, right, and 'gid' 500 as of now, right? 288 00:17:15,300 --> 00:17:16,300 See, let me get it 289 00:17:16,300 --> 00:17:24,300 from my Python. 'import os'. 'os.getuid()', User Id - 500. 290 00:17:24,300 --> 00:17:28,000 'os.getguid', Group Uid. 291 00:17:29,300 --> 00:17:30,300 What is that? 292 00:17:32,300 --> 00:17:33,300 'getuid()'. 293 00:17:34,700 --> 00:17:37,500 Let me see the operation so that it will be clear for me. 294 00:17:39,000 --> 00:17:41,400 'getuid()'. 'get' 295 00:17:46,200 --> 00:17:48,400 Where is 'getuid()'? 'getuid()' 296 00:17:48,400 --> 00:17:51,000 [no audio] 297 00:17:51,000 --> 00:17:52,200 'process id' you can get it. 298 00:17:53,800 --> 00:17:55,600 Right. I want to get 'group id'. 299 00:17:57,000 --> 00:18:00,200 'get groups', yeah. 'getgid'. So what I did? 300 00:18:01,200 --> 00:18:02,000 I did I think 'getguid()', 301 00:18:03,900 --> 00:18:10,000 no. 'os.getgid', group id. 302 00:18:11,200 --> 00:18:12,200 That's it. 303 00:18:13,200 --> 00:18:14,200 Right. 304 00:18:15,300 --> 00:18:21,800 Then 'pid', process id. 'os.getpid', 305 00:18:23,200 --> 00:18:26,100 your current shell process id. Right. 306 00:18:27,100 --> 00:18:33,500 Yeah, so guys these are some simple basic 'os' operations, right? 307 00:18:33,500 --> 00:18:36,400 So irrespective of your operating systems if you want to 308 00:18:36,400 --> 00:18:41,100 get some details of your operating systems, 309 00:18:41,100 --> 00:18:43,500 if you want to do some tasks like creating directory, 310 00:18:43,400 --> 00:18:47,400 removing directory, changing your path, right, or getting your current 311 00:18:47,400 --> 00:18:50,500 working directory irrespective of your operating system. 312 00:18:51,000 --> 00:18:55,100 See without your Python, if you want to run suppose change directory 313 00:18:55,100 --> 00:18:57,500 commands are different based on your operating system. 314 00:18:57,500 --> 00:19:00,610 But if you go with Python, no need to worry about your operating 315 00:19:00,600 --> 00:19:05,310 systems, just use these syntaxes so that your Python 316 00:19:05,300 --> 00:19:07,400 will take care based on your operating systems. 317 00:19:07,500 --> 00:19:12,200 And this is guys, this is a variable don't use this parentheses here. 318 00:19:12,200 --> 00:19:16,200 'os.environ'. Right. Fine. 319 00:19:16,200 --> 00:19:18,400 Okay guys, thank you for watching this video. 320 00:19:18,400 --> 00:19:28,413 [no audio]