2
2
3
3
This project serves as a comprehensive guide to executing shell commands and handling files using Python.
4
4
Installation. You can install Python through the official website: https://www.python.org/downloads/
5
- ## Usage
6
- This project can be used as a reference guide for executing shell commands and file handling in Python.
7
- Shell Commands with Python
5
+
6
+ ## Table of Contents
7
+
8
+ - [ Installation] ( #installation-requiments )
9
+ - [ Usage] ( #usage )
10
+ - [ Install Requirements] ( #install-requirements )
11
+ - [ Shell Commands with Python] ( #shell-commands-with-python )
12
+ - [ Creating and writing to a file] ( #creating-and-writing-to-a-file )
13
+ - [ Reading from a file] ( #reading-from-a-file )
14
+ - [ Appending to an existing file] ( #appending-to-an-existing-file )
15
+ - [ Deleting a file] ( #deleting-a-file )
16
+ - [ Checking if a file exists] ( #checking-if-a-file-exists )
17
+ - [ Creating a directory] ( #creating-a-directory )
18
+ - [ Large File Handling] ( #large-file-handling )
19
+ - [ Opening a file] ( #opening-a-file )
20
+ - [ Reading a file line by line] ( #reading-a-file-line-by-line )
21
+ - [ Reading a specific number of lines] ( #reading-a-specific-number-of-lines )
22
+ - [ Searching within a large file] ( #searching-within-a-large-file )
23
+ - [ Writing to a large file] ( #writing-to-a-large-file )
24
+ - [ Splitting files] ( #splitting-files )
25
+ - [ Handling Specific File Formats] ( #handling-specific-file-formats )
26
+ - [ Reading PDF files] ( #reading-pdf-files )
27
+ - [ Reading Word documents] ( #reading-word-documents )
28
+ - [ Reading Excel files] ( #reading-excel-files )
29
+ - [ Reading HTML files] ( #reading-html-files )
30
+ - [ Credits] ( #credits )
31
+ - [ Useful Resources] ( #useful-resources )
32
+
33
+
34
+
35
+
8
36
9
37
## Install requiments
10
38
``` python
11
39
pip install PyPDF2 python- docx pandas beautifulsoup4
12
40
```
41
+ ## Usage
42
+ This project can be used as a reference guide for executing shell commands and file handling in Python.
43
+ Shell Commands with Python
13
44
14
45
This project makes use of Python to execute shell commands. Here are some of the Python commands used in this project:
15
46
16
- ## Creating and writing to a file:
47
+ ## Creating and writing to a file
17
48
18
49
``` python
19
50
20
51
with open (" filename.txt" , " w" ) as f:
21
52
f.write(" Hello, World!" )
22
53
```
23
- ### Reading from a file:
54
+ ### Reading from a file
24
55
25
56
``` python
26
57
27
58
with open (" filename.txt" , " r" ) as f:
28
59
print (f.read())
29
60
```
30
- ### Appending to an existing file:
61
+ ### Appending to an existing file
31
62
32
63
``` python
33
64
34
65
with open (" filename.txt" , " a" ) as f:
35
66
f.write(" More text." )
36
67
```
37
- ### Deleting a file:
68
+ ### Deleting a file
38
69
39
70
``` python
40
71
41
72
import os
42
73
os.remove(" filename.txt" )
43
74
```
44
- ### Checking if a file exists:
75
+ ### Checking if a file exists
45
76
46
77
``` python
47
78
48
79
import os
49
80
os.path.exists(" filename.txt" )
50
81
```
51
- ### Creating a directory:
82
+ ### Creating a directory
52
83
53
84
``` python
54
85
import os
@@ -58,29 +89,29 @@ os.mkdir("directory_name")
58
89
59
90
Working with large files requires a different set of Python commands. Here are some examples:
60
91
61
- ### Opening a file:
92
+ ### Opening a file
62
93
63
94
``` python
64
95
65
96
file = open (' large_file.txt' , ' r' )
66
97
```
67
- ### Reading a file line by line:
98
+ ### Reading a file line by line
68
99
69
100
``` python
70
101
71
102
with open (' large_file.txt' , ' r' ) as file :
72
103
for line in file :
73
104
print (line)
74
105
```
75
- ### Reading a specific number of lines:
106
+ ### Reading a specific number of lines
76
107
77
108
``` python
78
109
79
110
from itertools import islice
80
111
with open (' large_file.txt' , ' r' ) as file :
81
112
head = list (islice(file , 5 ))
82
113
```
83
- ### Searching within a large file:
114
+ ### Searching within a large file
84
115
85
116
``` python
86
117
@@ -89,14 +120,14 @@ with open('large_file.txt', 'r') as file:
89
120
if ' some_text' in line:
90
121
print (line)
91
122
```
92
- ### Writing to a large file:
123
+ ### Writing to a large file
93
124
94
125
``` python
95
126
96
127
with open (' large_file.txt' , ' w' ) as file :
97
128
file .write(' some_text' )
98
129
```
99
- ### Splitting files:
130
+ ### Splitting files
100
131
101
132
``` python
102
133
@@ -112,7 +143,7 @@ with open('large_file.txt', 'r') as file:
112
143
113
144
Python can read various file formats using specific libraries. Here are some examples:
114
145
115
- ### Reading PDF files:
146
+ ### Reading PDF files
116
147
117
148
``` python
118
149
@@ -123,7 +154,7 @@ with open('example.pdf', 'rb') as file:
123
154
page = reader.getPage(0 )
124
155
print (page.extract_text())
125
156
```
126
- ### Reading Word documents:
157
+ ### Reading Word documents
127
158
128
159
``` python
129
160
@@ -133,7 +164,7 @@ doc = Document('example.docx')
133
164
for para in doc.paragraphs:
134
165
print (para.text)
135
166
```
136
- ### Reading Excel files:
167
+ ### Reading Excel files
137
168
138
169
``` python
139
170
@@ -142,7 +173,7 @@ import pandas as pd
142
173
data = pd.read_excel(' example.xlsx' )
143
174
print (data)
144
175
```
145
- ### Reading HTML files:
176
+ ### Reading HTML files
146
177
147
178
``` python
148
179
0 commit comments