Multiple .replace() ?? and understanding the "u" which gets added to record from excel file (Python)
Question: I need some help with this code:

    
    
    import pyexcel as pe
    import pyexcel.ext.xls
    import pyexcel.ext.xlsx
    
    def randStrings(excelFile1,excelFile2):
        getNameList = pe.get_sheet(file_name=excelFile1)
        randName = sum([i for i in getNameList],[])
        getCompanyList = pe.get_sheet(file_name=excelFile2)
        randCompany = sum([i for i in getCompanyList],[])
        randStrings.name = random.choice(randName)
        randStrings.combinedString = random.choice(randName) + "@" + random.choice(randCompany).lower().replace(" ","").replace("'","").replace("/","").replace(".","").replace(",","") +".com"
        return randStrings.name, randStrings.combinedString
    
    randStrings("names.xlsx","companys.xlsx")
    data = {'user_name':randStrings.name,'user_email': randStrings.combinedString}
    print data
    

my output is : {'user_name': u'duky', 'user_email': u'geri@belleladi.com'}

Need help or advice for two things :

1.Does anyone have a idea or can explain on why there is 'u' character when
getting a record from the excel sheet?? and how to remove this from the
output?

  2. As you can I've done a extra long .replace() to get rid of any gremlins within the excel . Is there a short or more clean way to do this? like a python reg ex or something. I haven't found any examples dealing with multiple replacements for formating.

Cheers


Answer: The u' in front of your records means that they are encode as unicode.

    
    
    >>> a=u'test'
    >>> a
    u'test'
    >>> type(a)
    <type 'unicode'>
    >>> b="b"
    >>> b
    'b'
    >>> type(b)
    <type 'str'>
    >>> 
    

