Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit abd95cc

Browse files
Gaurav Sitlanichkumar246
Gaurav Sitlani
authored andcommitted
Additions and fixes. (#3)
Improvements in Exception handling docs.
1 parent 0b78a3c commit abd95cc

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

‎file_and_modules.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff 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.
55
* 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.
1111
```
1212
>>> names_list = ['chandan', 'nikhil']
1313
>>> data = open('names.txt', 'w')
@@ -36,11 +36,11 @@
3636
```
3737

3838
## 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.
4242
* 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.
4444
```
4545
>>> import math
4646
>>> dir(math)
@@ -62,12 +62,12 @@ ModuleNotFoundError: No module named 'foo'
6262
* A python script foo.py can be called as a module by using foo.py
6363

6464
## 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.
6767
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.
7171
```
7272
>>> import sys
7373
>>> def linux_interaction():
@@ -86,10 +86,10 @@ Executing the else clause.
8686
>>>
8787
```
8888

89-
## Writting simple CIL script
89+
## Writting a simple CIL script
9090
* We write scripts in order to reuse it multiple times.
9191
* In python you see '__' double underscore aka dunder.
92-
* create a script greetings.py
92+
* Create a script greetings.py
9393
```
9494
[raukadah@ironman python-workshop]$ python3 fun.py
9595
Welcome FOSS MEET
@@ -109,6 +109,7 @@ if __name__ == "__main__":
109109
#!/usr/bin/python3
110110
111111
import greetings
112+
112113
greetings.greeting('FOSS MEET')
113114
[raukadah@ironman python-workshop]$ python3 fun.py
114115
Welcome FOSS MEET
@@ -117,4 +118,4 @@ the value of __name__ is greetings
117118
```
118119

119120
## Installing a new python module
120-
$ python3 -m pip install requests
121+
$ python3 -m pip install requests

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /