简体   繁体   中英

split function (list index out of range)

textData = "SENDER|%|SUB|%|HTML|%|username{*|*}password{*|*}mail{*|*}data1|*|username{*|*}password{*|*}mail{*|*}data1"
genelData = textData.split("|%|")
userData = genelData[3].split("|*|")
for userDataTable in userData:
    usersData = userDataTable.split("{*|*}")
    self.response.out.write("<br>" + usersData[2])

in this code i try to parse some string data.But when i try to print "usersData" variable everything looks fine.But when i tried to use like "usersData[2]" im getting list index out of range problem.

You should re-evaluate some of your identifiers...having 'userData' and 'usersData' in the same scope is a recipe for trouble.

Having said that, are you sure you aren't inadvertantly trying to print userData[2] instead of usersData[2] ? I replaced your call to response.out.write with a simple print statement, userData[2] produced an index error while usersData[2] worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM