求解释下这段Python代码,尤其是lineList = line.split()这句infile = open("message.txt","r")outfile = open("newMsg.txt","w")count = 0stringList = infile.readlines()for line in stringList:lineList = line.split()for word in lineList:count = co

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 13:47:07
求解释下这段Python代码,尤其是lineList = line.split()这句infile = open(
xTMSP+)ʖA;}j C`wh"ӊ@e_A{ +B{/@ . {}w.<7nL[\^y)ھzHrA)ᐨz3QZC y\EY\|]W^SG}˻$IyVQ#jaLJ*! :*G  K-s"3}4 f ܠ_S, 僼h`9?= My𿥧a(z!/H$#Q(QqŦ9l^MY ɊM̈́Y韐ve۸\BSߐs4”%^pR !Gn!-Mh,n4[8 gOzhpc iFj~©.o3+F%sV:@'p0 , {nº0Y3$ͽ2j7dz%(u<\׌a[CNu@yP)!tyvMp0/[H}f43~ԍ}5mA[JxT,[k0\4YMᘤi k]CcKc===aI?Q2a<2VB.bXg"*jm wN4 Q҈7 È,з|hf2 vp fMZby0g$Άң,GXBdA驇֪4:nS?I2p:aF93JxQ'kL

求解释下这段Python代码,尤其是lineList = line.split()这句infile = open("message.txt","r")outfile = open("newMsg.txt","w")count = 0stringList = infile.readlines()for line in stringList:lineList = line.split()for word in lineList:count = co
求解释下这段Python代码,尤其是lineList = line.split()这句
infile = open("message.txt","r")
outfile = open("newMsg.txt","w")
count = 0
stringList = infile.readlines()
for line in stringList:
lineList = line.split()
for word in lineList:
count = count + 1
word = word[::-1]
print(word,end = ' ')
outfile.write(word + ' ')
if count == 10:
print('')
outfile.write('\n')
count = 0
infile.close()
outfile.close()

求解释下这段Python代码,尤其是lineList = line.split()这句infile = open("message.txt","r")outfile = open("newMsg.txt","w")count = 0stringList = infile.readlines()for line in stringList:lineList = line.split()for word in lineList:count = co
infile = open("message.txt","r") #只读模式打开message.txt
outfile = open("newMsg.txt","w") #写模式打开newMsg.txt
count = 0 #创建变量count ,值为整数0
stringList = infile.readlines() #一次性读取message.txt中的所有行,返回字符串列表,
一 行文本就是列表的一项
for line in stringList:#迭代该列表
lineList = line.split() #用split讲该行的单词分割成列表,每个单词就时一个列表
项目,split的默认参数是空格,所以不传递任何参数时
分割空格,在英文中也就等同于分割单词
for word in lineList:#迭代该行的每个单词
count = count + 1 #每迭代一次count+1
word = word[::-1] #利用切片,反转该单词
print(word,end = ' ') #
outfile.write(word + ' ') #将单词写入到newMsg.txt文件中
if count == 10:#当单词数量读取到10个时
print('') #打印一个空白行
outfile.write('\n') #在newMsg.txt中写入一个换行符(这应该是linux,
在windows下应该是\r\n)
count = 0 #计数变量count 恢复成0
infile.close() #关闭message.txt文件拘柄
outfile.close() #关闭newMsg.txt文件拘柄