You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: file_and_modules.md
+22-21Lines changed: 22 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
-
## File operations
2
-
* file is a storage format where we store information on the computer.
3
-
*It might text files like music, video, code and other stuff or binary
4
-
files which are only understood able by computer.
1
+
## Filesystem Operations
2
+
*A file is stored as a resource on the computer on top of a [filesystem](https://www.tldp.org/LDP/sag/html/filesystems.html), which is a storage format.
3
+
*Files can be text, music or media which can be understood by any human user.
4
+
* And some files are binaries which can only be understood by computer.
5
5
* By using Python, we can easily manipulate these files.
6
-
*let's create a file names.txt and add few names.
7
-
*mode of files based on purpose
8
-
*r - read the content of file, setted default
9
-
*w - write the content to file, if file is not there it will create it.
10
-
*a - append contents to the file.
6
+
*Let's create a file - `names.txt` and add few names in it.
7
+
*list of different modes for opening files:
8
+
*`r` - read the content of file, setted default
9
+
*`w` - write the content to file, if file is not there it will create it.
10
+
*`a` - append contents to the file.
11
11
```
12
12
>>> names_list = ['chandan', 'nikhil']
13
13
>>> data = open('names.txt', 'w')
@@ -36,11 +36,11 @@
36
36
```
37
37
38
38
## Python Modules
39
-
* Python provides a rich support of modules.
40
-
* Modules/library are a collection of python scripts which can be reusable for writting complex program.
41
-
* We can import a module using import keyword.
39
+
* Python provides a rich support for python modules.
40
+
* Modules/libraries (also known as python packages) are a collection of python scripts which can be reusable for writing complex programs.
41
+
* We can import a module using `import` keyword.
42
42
* If it is not available it will give import error.
43
-
* dir() method tells what these modules provides.
43
+
* dir() method tells what the attribute provides.
44
44
```
45
45
>>> import math
46
46
>>> dir(math)
@@ -62,12 +62,12 @@ ModuleNotFoundError: No module named 'foo'
62
62
* A python script foo.py can be called as a module by using foo.py
63
63
64
64
## Exceptions
65
-
While writting programs, Errors are prone to occur. But It can be handled via
66
-
exception.
65
+
While writing programs, errors are prone to occur. But they can be handled with
66
+
exceptions.
67
67
For example, we were trying to import a module but it was not there.
68
-
we can by pass this error by using try and except.
69
-
With try keyword, we do something, then in except clause once this
70
-
exception comes we do something else
68
+
We can by pass this error by using try and except.
69
+
With `try` keyword, we write something, then in `except` clause once an
70
+
exception comes, we handle it or do something else. And using `finally` we can move ahead and do something else.
71
71
```
72
72
>>> import sys
73
73
>>> def linux_interaction():
@@ -86,10 +86,10 @@ Executing the else clause.
86
86
>>>
87
87
```
88
88
89
-
## Writting simple CIL script
89
+
## Writting a simple CIL script
90
90
* We write scripts in order to reuse it multiple times.
91
91
* In python you see '__' double underscore aka dunder.
0 commit comments