Python3 split()方法
描述
split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串
语法
split()方法语法:
str.split(str="", num=string.count(str)).
参数
- str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
- num -- 分割次数。
返回值
返回分割后的字符串列表。
file_out = open("HM_result.txt", 'w+')
file_out.write("sku,asin\n")
with open("HM.txt") as file:
for line in file:
newl= line.split("\t", 2)
file_out.write(newl[0] + "," + newl[1] + "\n")
print(newl)
file_out.close()