0

here my function . I have to do lower what ever coming in newfilename..i.e newfilename.lower()

def my_function(start, end):
    sheetname = 'my-sheet'
    filepath = "/myxl.xlsx"

try:
    work_book=xlrd.open_workbook(filepath)
except:
    print 'error'

try:
    worksheet = work_book.sheet_by_name(sheetname)
except:
    print 'error'

rows=worksheet.nrows
cols=worksheet.ncols

success = []
fail = []
for row in xrange(start,end):
    print "row no.       : ",row

    state = '/home/myfolder/'
    if os.path.exists(state):
        print "state folder exits"
    else:
        os.makedirs(state)

    district =  state + worksheet.cell_value(row,0) + '/'    
    if os.path.exists(district):
        print "district folder exits"
    else:
        os.makedirs(district)

    city = district +  worksheet.cell_value(row,2) + '/'
    if os.path.exists(city):
        print "city folder exits"
    else:
        os.makedirs(city)

    newfilename = city + worksheet.cell_value(row,4).replace (" ", "-") + '.png'
    if worksheet.cell_value(row,5) !="":
        oldfilename = worksheet.cell_value(row,5)
    else:
        oldfilename="no-image"

    newfullpath = newfilename
    oldfullpath = '/home/old/folder/' + oldfilename

    try:
        os.rename(oldfullpath,newfullpath)
        success.append(row)
    except Exception as e:
        fail.append(row)
        print "Error",e
    print 'renaming done for row #' ,row , ' file ', oldfilename , ' to ', newfilename

print 'SUCCESS ', success
print 'FAIL ', fail

newfilename.lower() not working

here when I am going to use unicode error coming... UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 72: ordinal not in range(128)

Samiul
  • 124
  • 1
  • 15
  • see: http://stackoverflow.com/a/20907062/3991125 – albert Jul 17 '16 at 19:40
  • I used 'content = content.decode('utf-8')' this but another error coming decoding not supported. Let me know another solution plz. – Samiul Jul 18 '16 at 06:52
  • You need to provide more details about the file you're trying to read. Where does it come from? Do you know which text encoding was used? Can you provide a sample snippet? What do you want to achieve? Maybe there are other ways to do the same but different... – albert Jul 18 '16 at 07:54
  • pllz review my question..i describe properly hope u understood . – Samiul Jul 19 '16 at 04:01

0 Answers0