QQ登录

只需一步,快速开始

登录 | 立即注册 | 找回密码

主题

帖子

荣誉

VIP至尊会员

Rank: 15Rank: 15Rank: 15

积分
275
查看: 177|回复: 1

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

[复制链接]
最佳答案
0 
累计签到:16 天
连续签到:1 天
黄金猫 发表于 2018-3-14 12:22:23 1771 | 显示全部楼层 |阅读模式

马上注册加入鱼C,享用更多服务吧^_^

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

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()
复制代码
楼层
跳转到指定楼层
最佳答案
0 
累计签到:62 天
连续签到:1 天
fengcc 发表于 2018-3-14 12:33:33 | 显示全部楼层

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

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

    移动客户端下载(未启用)
    微信公众号

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

Copyright 2018 鱼C论坛 版权所有 All Rights Reserved.

Powered by Discuz! X3.3 Copyright
© 2001-2018 Comsenz Inc.    All Rights Reserved.

小黑屋|手机版|Archiver|鱼C工作室 ( 粤公网安备 44051102000370号 | 粤ICP备11014136号

GMT+8, 2018-6-20 00:40

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