Change Name from a csv list with python

0

Before I introduce myself since I'm new here and I'm just starting with this. What I want to solve is the following, I have different folders with images labeled as follows First name Paternal Mother's last name and date of birth example: Luis Pedro de la Rosa sources 14.02.1986 I have managed to make a scrip that brings me the names of the files and save them in a csv, now I would like to know if I can separate the name from the date to put them in a different column, and so have the name and date of birth separately, to then read the csv and connect to the database search by name and date of birth and I return the employee number generating or generating the csv with the fields name, date and number and then go to the database to the table photos look for the employee number and upload your photo, take the id of the photo and write it in another table that makes reference, I hope you can support me or guide me with your comments

thanks Greetings!

    
asked by Bernardino Hernández Hernández 29.08.2017 в 20:03
source

1 answer

1

I can think of two ways to recover date and name, obviously it works if in all cases we have a format similar to this <nombre y apellido> <dd>.<mm>.<aaaa>

First of all we can establish that the date is the last 10 characters, so obtaining both fields could be resolved with a "slice", in the following way:

text = "luís Pedro de la rosa fuentes 14.02.1986"

nombre = text[:-10]
fecha = text[-10:]

print("nombre: {}".format(nombre))
print("fecha : {}".format(fecha))

> nombre: luís Pedro de la rosa fuentes 
> fecha : 14.02.1986

The other way is a bit more complex but more flexible and is using regular expressions:

import re

m=re.search(r'^(.*?)(\d{2}.\d{2}.\d{4})', text)
print("nombre: {}".format(m.group(1)))
print("fecha : {}".format(m.group(2)))

> nombre: luís Pedro de la rosa fuentes 
> fecha : 14.02.1986
    
answered by 29.08.2017 / 20:51
source