Skip to content

Commit 195f7fa

Browse files
committed
Adicionando funcao de pegar extencao do arquivo
1 parent f6b75b3 commit 195f7fa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

file-operations/file_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ def remove_accents(string):
55
return unidecode(string)
66

77
def get_file_content(file):
8+
file_extention = get_file_extention(file)
9+
if file_extention != '.txt':
10+
raise NotImplementedError('Only .txt files are available')
811
with open(file, 'r') as f:
912
file_string = f.read()
1013
return file_string
@@ -14,3 +17,11 @@ def store_file_content(content, file='new_file.txt'):
1417
with open(file, 'w') as f:
1518
f.write(content)
1619
return file
20+
21+
def get_file_extention(file: str):
22+
if file.startswith('.'):
23+
dot = file.find('.', 1)
24+
dot = file.find('.')
25+
if dot < 0:
26+
raise ValueError('extention not found')
27+
return file[dot:]

0 commit comments

Comments
 (0)