[Tutor] help with re.split use

Michel Bélanger michel.belanger at seidel.ca
Thu Jan 29 09:45:30 EST 2004


Hi,

I  use the re.split function to parse Fisrt and Last name from a contact 
field.  I use the following command:    

# -*- coding: cp1252 -*-
import csv
import re
row = "Genevieve Camiré"
contact = re.split(' ',row)
print row, contact, len(contact)

This generate the following results:
Genevieve Camiré ['Genevieve', 'Camir\xe9'] 2


question1:  When I first ran the code, I had and I/O warning message 
which  ended up with the addition of the first line of code  # -*- 
coding: cp1252 -*-  What is it for?

question2:  Why the word 'Camiré' got changed to 'Camir\xe9'

question3: Some of the row from my contacts list contain only one word 
which result with contact been a list of length 1.  Is it possible to 
add an argument to the split function so that it generates an empty 
string for the second item in contact list: i.e.

row = "Belanger"
after split function is applied to row
contact = ['Belanger','']

Thanks





More information about the Tutor mailing list