FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonGeneratorProject/data_filtering.py at master · Resh404/pythonGeneratorProject · GitHub
Resh404
/
pythonGeneratorProject
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonGeneratorProject
/
data_filtering.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (49 loc) · 2.39 KB
Breadcrumbs
pythonGeneratorProject
/
data_filtering.py
Copy path
File metadata and controls
54 lines (49 loc) · 2.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class
DataFiltering
:
def
__init__
(
self
,
collect_data_from
:
str
,
data_encoding
:
str
):
self
.
target_file_name
=
collect_data_from
self
.
data_encoding
=
data_encoding
def
my_read_line
(
self
):
try
:
with
open
(
self
.
target_file_name
,
"r"
,
encoding
=
self
.
data_encoding
)
as
file
:
for
line
in
file
:
yield
line
except
FileNotFoundError
:
print
(
f"Error: File '
{
self
.
target_file_name
}
' not found."
)
except
PermissionError
:
print
(
f"Error: Permission denied to access file '
{
self
.
target_file_name
}
'."
)
except
UnicodeDecodeError
:
print
(
f"Error: Unable to decode file '
{
self
.
target_file_name
}
' using encoding '
{
self
.
data_encoding
}
'."
)
except
Exception
as
e
:
print
(
f"Error: Unexpected error occurred:
{
e
}
"
)
def
isolate_entry
(
self
,
filtered_data_file_name
:
str
,
index
:
int
):
try
:
with
open
(
filtered_data_file_name
,
"a"
,
encoding
=
self
.
data_encoding
)
as
output_file
:
for
line
in
self
.
my_read_line
():
line_entries
=
line
.
strip
().
split
(
','
)
entry
=
line_entries
[
index
]
output_file
.
write
(
entry
+
"
\n
"
)
except
Exception
as
e
:
print
(
f"Error: Error writing to file:
{
e
}
"
)
def
filter_out_
(
self
,
filtered_data_file_name
:
str
,
str_or_int_entries
):
try
:
with
open
(
filtered_data_file_name
,
"a"
,
encoding
=
self
.
data_encoding
)
as
output_file
:
for
line
in
self
.
my_read_line
():
line_entries
=
line
.
strip
().
split
(
','
)
int_line
=
[]
str_line
=
[]
for
entry
in
line_entries
:
if
'-'
in
entry
:
int_line
.
append
(
entry
)
else
:
try
:
int
(
entry
)
int_line
.
append
(
entry
)
continue
except
ValueError
:
str_line
.
append
(
entry
)
if
isinstance
(
str_or_int_entries
,
str
):
output_file
.
write
(
","
.
join
(
int_line
)
+
"
\n
"
)
else
:
output_file
.
write
(
","
.
join
(
str_line
)
+
"
\n
"
)
except
Exception
as
e
:
print
(
f"Error: Unexpected error occurred:
{
e
}
"
)
Back
|
FazBrowse Home
|
New Git URL