I am moving to the second part of my project: extracting the values I need from the file!
To do that i am checking inside the newly created string with
I made an example of what i am doing, but i am sure there is a better way to handle this and that my coding style is not very pythonic
meanwhile i am learning about the
To do that i am checking inside the newly created string with
str.find()
then i try to understand where my data start and endI made an example of what i am doing, but i am sure there is a better way to handle this and that my coding style is not very pythonic
meanwhile i am learning about the
re
library!import re #https://docs.python.org/3/library/re.html #r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline #check special characters and put a "\" before them! text = "Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." #print (text) debug = True #re.sub(pattern_to_find, replace_with, text_input, count=0, flags=0) text = re.sub('(\. |, )', '.\n', text) print (text) #data that i need to find name = "incidunt" surname = "consectetur" birth = "veniam" #index of them ix_name = text.find(name)+len(name) ix_surname = text.find(surname)+len(surname) ix_birth = text.find(birth)+len(birth) if debug: print("start of data:") print("name position:", str(ix_name)) #my data data_name = text[ix_name:ix_name+20] data_surname = text[ix_surname:ix_surname+20] if debug: print(data_name)as always any suggestion to better approach, libraries, examples is very welcomed :D