[16:17:38] [## Class Started at Tue Aug 16 16:17:38 2016 ##] [16:17:38] startclass [16:17:47] Roll Call [16:17:50] Abhishek Shrivastava [16:17:52] ganesh kadam [16:17:52] Tabrez khan [16:17:52] Mriyam Tamuli [16:17:56] Md Tasin Siddiqi [16:17:57] Madhuri Muley [16:17:59] avik, no class yesterday [16:18:01] Sudeep Mukherjee [16:18:06] Varsha R [16:18:08] Poonam Jadhav [16:18:10] Jogender Kota [16:18:13] Shantanu Acharya [16:18:19] Akash Mishra [16:18:24] HoloIRCUser3 is now known as jogender [16:18:32] sandeep kumar choudhary [16:18:32] Mahesh [16:18:39] Anupama Mandal [16:18:41] Abhishek Gupta [16:19:12] Avik Mukherjee. thanks kushal [16:20:05] Ayush Kesarwani [16:20:16] brahmanNaman is now known as AyushKesar [16:20:49] Moiz Sajid [16:20:55] yash bhardwaj [16:20:56] https://shellshare.net/r/summertraining [16:21:20] Before we start, any question on Python till now? [16:21:36] Deepanshu kapoor [16:22:09] Harsh Vardhan [16:22:14] Rhitik Bhatt [16:22:26] So no questions. [16:22:31] Today's topic: Files [16:23:08] Roll call : Aman Kumar [16:24:25] For normal usage we have two different types of files, text files, and binary files for different formats. [16:24:35] Can you type some names for text files? [16:24:50] Also type some names for binary files :) [16:25:04] .docx file [16:25:31] tasin, what kind? [16:25:37] What about .mp3 and .jpg? [16:25:42] What about .py files? [16:25:44] .txt and .bin [16:25:54] aman_, which one is what? :) [16:26:15] .txt is for text and .bin for binary [16:26:27] Okay [16:26:30] Anyone else? [16:26:31] :) [16:26:51] What about .mp3 and .jpg? [16:26:53] What about .py files? [16:27:04] others tell us what do you think. [16:27:10] Feel free to use google.com :) [16:27:15] .mp3 and .jpg is binary [16:27:25] .py is text. .mp3 and .jpg binary [16:27:32] .mp3 or .jpg are binary files as open any editior see 0 and 1 [16:27:47] .py is text file [16:27:51] kushal: ^^ [16:27:51] .exe is binary [16:27:51] .pyc is binary I guess. [16:27:58] Ye [16:28:00] yes. [16:28:28] py is scripting file format [16:28:38] madhurii, text or binary? [16:28:49] binary [16:28:59] .py is text [16:29:07] As shown by the file command. [16:29:10] ASCII text. [16:29:14] mbtamuli12_, :) [16:29:18] Correct me if I am wrong? [16:29:27] .docx is a kind of archive file [16:29:27] mbtamuli12_, Can you please explain that command to others here? [16:29:51] kushal,correct me also if am wrong? [16:29:54] file command is used to determine the file type. [16:29:57] file < [16:30:14] file will display the type of a file [16:30:15] madhurii, try file somefile.py [16:30:50] https://shellshare.net/r/summertraining [16:32:26] Is that okay for everyone? [16:32:35] If you have question, feel free to type ! [16:33:36] What is all that code on shellshare? [16:34:23] tasin: That's kushal sharing his terminal [16:34:29] tasin, it is not code, it is the output of the file command [16:34:45] ok got it [16:36:10] Now first tip: [16:36:11] roll call: Shrimadhav U K [sorry I am late] [16:36:28] Roll Call : Akash Ganbote [16:36:31] Mudit Maurya [16:41:10] Roll Call : Saurav Saha [16:41:23] Sorry for being late. Was busy in playing Badminton [16:42:56] Is the session going on ?? [16:43:18] SRvSaha, yes. [16:44:19] sorry got disconnected [16:44:21] What was the last line from me? [16:44:37] Now first tip: [16:44:57] If you open a file, remember to close it. [16:44:59] In any programming language, in any OS [16:45:07] Always remember to close the open files. [16:46:27] * kushal is having huge network lags [16:47:11] In Python we use open call to open a file handler. [16:47:29] please follow https://shellshare.net/r/summertraining [16:49:53] anushil kumar [16:52:57] So the easy way: Open a file, read all the lines, and then close it. [16:53:42] If you want read the whole file at once (bad idea for big files), you can use the read method. [16:53:47] fobj.read() [16:53:59] Now python has a better way to do this. [16:54:43] Where we do not have to manually close the file. [16:54:49] Let us go back to the shell [16:55:52] You can see, I never closed the file manually [16:56:19] with statement makes sure that the opened file is closed at the end. [16:57:12] Any questions till now? [16:57:24] Always try to use the with statements. [16:57:53] ! [16:58:17] next [16:58:19] next [16:58:20] but what if we want to use the file again in later part of program ? Will we have to reopen it ? [16:58:28] abstatic, Yes. [16:58:31] yes [16:58:41] Okay [16:58:58] Question is why do need to read it again? [16:59:07] You can read once, store it in a variable [16:59:15] and use that variable as many times as you want. [16:59:29] Unless you know that the file content is changed in between. [17:00:14] Any other question? [17:00:21] Thanks kushal [17:01:10] To write to a file, you will have to open it in write mode. [17:01:17] open("filepath", "w") [17:01:39] that w stands for write mode [17:02:24] We actually open in read mode when we do open("filepath", "r") [17:02:52] But that r is the default value, means if you do not provide it, then it will open in read mode. [17:04:08] Is this okay? [17:04:32] yes [17:04:34] Yes [17:04:38] yes [17:04:38] yup [17:04:54] yes [17:05:29] ! [17:05:30] yep [17:05:31] Yes [17:05:34] next [17:06:46] w used to append the , is there any option to overwrite the file? [17:07:07] w is for overwriting [17:07:39] okay then what is for appending? [17:07:41] for append we use "a" [17:07:45] w is for writing, does not matter if it is a new file, or old file (which will be overridden) [17:08:02] okay [17:12:33] less /proc/meminfo [17:12:41] See the contents of that file. [17:13:04] First 3 lines show total, free and available memory in your computer. [17:13:17] Now try to write a code, myfree.py [17:13:26] which will show those 3 values in MB. [17:13:41] remember to write proper functions, and call them [17:13:49] ! [17:14:55] next [17:15:00] Does free -m show the same information as the information in /proc/meminfo [17:15:19] Does it actually read from /proc/meminfo? [17:15:25] mbtamuli12_, I guess so :) [17:15:44] Not sure how it is implemented, but the same information. [17:24:02] http://sprunge.us/GbZa?py [17:25:44] * mbtamuli12_ going for dinner. Be back later. Sorry. [17:25:55] mbtamuli12_, which one is what? [17:25:58] :) [17:26:12] https://paste.fedoraproject.org/409247/ [17:26:25] Finish this off, show us the answer tomorrow [17:26:52] code_geek, show us what is what :) [17:26:56] Roll Call [17:27:02] okay [17:27:11] Shantanu Acharya [17:27:11] Abhishek Shrivastava [17:27:32] Deepanshu KAPOOR [17:27:38] Anupama Mandal [17:27:40] sandeep kumar choudhary [17:27:42] yash bhardwaj [17:27:47] Jogender Kota [17:27:50] Varsha R [17:27:52] Tabrez khan [17:27:54] Rhitik Bhatt [17:28:19] Rohan Hazra [17:29:33] https://paste.fedoraproject.org/409250/14713613/ [17:30:05] Does the wrong thing. Sorry. [17:30:26] Akash Ganbote [17:31:00] endclass [17:31:00] [## Class Ended at Tue Aug 16 17:31:00 2016 ##]