@@ -13,74 +13,74 @@ pip install PyPDF2 python-docx pandas beautifulsoup4
13
13
14
14
This project makes use of Python to execute shell commands. Here are some of the Python commands used in this project:
15
15
16
- Creating and writing to a file:
16
+ ## Creating and writing to a file:
17
17
18
18
``` python
19
19
20
20
with open (" filename.txt" , " w" ) as f:
21
21
f.write(" Hello, World!" )
22
22
```
23
- Reading from a file:
23
+ ### Reading from a file:
24
24
25
25
``` python
26
26
27
27
with open (" filename.txt" , " r" ) as f:
28
28
print (f.read())
29
29
```
30
- Appending to an existing file:
30
+ ### Appending to an existing file:
31
31
32
32
``` python
33
33
34
34
with open (" filename.txt" , " a" ) as f:
35
35
f.write(" More text." )
36
36
```
37
- Deleting a file:
37
+ ### Deleting a file:
38
38
39
39
``` python
40
40
41
41
import os
42
42
os.remove(" filename.txt" )
43
43
```
44
- Checking if a file exists:
44
+ ### Checking if a file exists:
45
45
46
46
``` python
47
47
48
48
import os
49
49
os.path.exists(" filename.txt" )
50
50
```
51
- Creating a directory:
51
+ ### Creating a directory:
52
52
53
53
``` python
54
54
import os
55
55
os.mkdir(" directory_name" )
56
56
```
57
- Large File Handling
57
+ ## Large File Handling
58
58
59
59
Working with large files requires a different set of Python commands. Here are some examples:
60
60
61
- Opening a file:
61
+ ### Opening a file:
62
62
63
63
``` python
64
64
65
65
file = open (' large_file.txt' , ' r' )
66
66
```
67
- Reading a file line by line:
67
+ ### Reading a file line by line:
68
68
69
69
``` python
70
70
71
71
with open (' large_file.txt' , ' r' ) as file :
72
72
for line in file :
73
73
print (line)
74
74
```
75
- Reading a specific number of lines:
75
+ ### Reading a specific number of lines:
76
76
77
77
``` python
78
78
79
79
from itertools import islice
80
80
with open (' large_file.txt' , ' r' ) as file :
81
81
head = list (islice(file , 5 ))
82
82
```
83
- Searching within a large file:
83
+ ### Searching within a large file:
84
84
85
85
``` python
86
86
@@ -89,14 +89,14 @@ with open('large_file.txt', 'r') as file:
89
89
if ' some_text' in line:
90
90
print (line)
91
91
```
92
- Writing to a large file:
92
+ ### Writing to a large file:
93
93
94
94
``` python
95
95
96
96
with open (' large_file.txt' , ' w' ) as file :
97
97
file .write(' some_text' )
98
98
```
99
- Splitting files:
99
+ ### Splitting files:
100
100
101
101
``` python
102
102
@@ -108,11 +108,11 @@ with open('large_file.txt', 'r') as file:
108
108
chunk_file.write(chunk)
109
109
chunk = file .read(chunk_size)
110
110
```
111
- Handling Specific File Formats
111
+ ## Handling Specific File Formats
112
112
113
113
Python can read various file formats using specific libraries. Here are some examples:
114
114
115
- Reading PDF files:
115
+ ### Reading PDF files:
116
116
117
117
``` python
118
118
@@ -123,7 +123,7 @@ with open('example.pdf', 'rb') as file:
123
123
page = reader.getPage(0 )
124
124
print (page.extract_text())
125
125
```
126
- Reading Word documents:
126
+ ### Reading Word documents:
127
127
128
128
``` python
129
129
@@ -133,7 +133,7 @@ doc = Document('example.docx')
133
133
for para in doc.paragraphs:
134
134
print (para.text)
135
135
```
136
- Reading Excel files:
136
+ ### Reading Excel files:
137
137
138
138
``` python
139
139
@@ -142,7 +142,7 @@ import pandas as pd
142
142
data = pd.read_excel(' example.xlsx' )
143
143
print (data)
144
144
```
145
- Reading HTML files:
145
+ ### Reading HTML files:
146
146
147
147
``` python
148
148
@@ -152,6 +152,6 @@ with open("example.html") as fp:
152
152
soup = BeautifulSoup(fp, ' html.parser' )
153
153
print (soup.prettify())
154
154
```
155
- Credits
155
+ ## Credits
156
156
157
157
This README was generated with the help of ChatGPT, an AI developed by OpenAI.
0 commit comments