鱼C论坛

 找回密码
 立即注册
查看: 245|回复: 1

[学习笔记] 零基础入门学Python 29课 课堂练习 MAC版本

[复制链接]
最佳答案
0 
发表于 2018-3-14 12:22:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
  1. f = open('/Users/yufan/Desktop/record.txt',encoding = 'GBK')

  2. boy1 = str()
  3. boy2 = str()
  4. boy3 = str()
  5. girl1 = str()
  6. girl2 = str()
  7. girl3 = str()

  8. dh = list()
  9. line_num = -1

  10. for each_line in f:
  11.     line_num += 1
  12.     if '==' in each_line:
  13.         dh.append(line_num)

  14. f.seek(0)

  15. line_num = -1

  16. for each_line in f:
  17.    
  18.    
  19.    
  20.     line_num += 1
  21.     if '小甲鱼:' in each_line and line_num < dh[0]:
  22.         each_line = each_line[4:]
  23.         boy1 = boy1 + each_line
  24.         
  25.     elif '小甲鱼:' in each_line and line_num > dh[0] and line_num < dh[1]:
  26.         each_line = each_line[4:]
  27.         boy2 = boy2 + each_line
  28.         
  29.     elif '小甲鱼:' in each_line and line_num > dh[1]:
  30.         each_line = each_line[4:]
  31.         boy3 = boy3 + each_line

  32.     if '小客服:' in each_line and line_num < dh[0]:
  33.         each_line = each_line[4:]
  34.         girl1 = girl1 + each_line
  35.         
  36.     elif '小客服:' in each_line and line_num > dh[0] and line_num < dh[1]:
  37.         each_line = each_line[4:]
  38.         girl2 = girl2 + each_line
  39.         
  40.     elif '小客服:' in each_line and line_num > dh[1]:
  41.         each_line = each_line[4:]
  42.         girl3 = girl3 + each_line

  43. fb1 = open('/Users/yufan/Desktop/boy1.txt','w',encoding = 'GBK')
  44. fb1.write(boy1)

  45. fb2 = open('/Users/yufan/Desktop/boy2.txt','w',encoding = 'GBK')
  46. fb2.write(boy2)

  47. fb3 = open('/Users/yufan/Desktop/boy3.txt','w',encoding = 'GBK')
  48. fb3.write(boy3)

  49. fg1 = open('/Users/yufan/Desktop/girl1.txt','w',encoding = 'GBK')
  50. fg1.write(girl1)

  51. fg2 = open('/Users/yufan/Desktop/girl2.txt','w',encoding = 'GBK')
  52. fg2.write(girl2)

  53. fg3 = open('/Users/yufan/Desktop/girl3.txt','w',encoding = 'GBK')
  54. fg3.write(girl3)


  55. ##print('boy1:','\n',boy1)
  56. ##
  57. ##print('boy2:','\n',boy2)
  58. ##
  59. ##print('boy3:','\n',boy3)
  60. ##
  61. ##print('girl1:','\n',girl1)
  62. ##
  63. ##print('girl2:','\n',girl2)
  64. ##
  65. ##print('girl3:','\n',girl3)

  66. f.close()

  67. fb1.close()
  68. fb2.close()
  69. fb3.close()

  70. fg1.close()
  71. fg2.close()
  72. fg3.close()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
最佳答案
0 
发表于 2018-3-14 12:33:33 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

小甲鱼强烈推荐上一条 /1 下一条

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号

GMT+8, 2018-9-23 01:57

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表