上面的写法报了空指针异常
因为str为空,不能调用split()方法。需要在调用split()方法前,先判断str是否为空,例如:
if str:
arr = str.split(',')
或者使用try-except语句处理异常:
try:
arr = str.split(',')
except AttributeError:
arr = []
原文地址: https://www.cveoy.top/t/topic/eNgJ 著作权归作者所有。请勿转载和采集!