• python 中文件打开后只能调用一次??


    001、

    (base) root@PC1:/home/test2# cat outcome.ped      ## 测试文件
    1 G G C C G G
    2 G G G C G G
    3 G G C C G G
    4 G G C C G G
    5 G G C C G G
    6 G G C C G G
    7 G G C C G G
    8 G G C C G G
    9 G G G C G G
    10 G G C C G G
    (base) root@PC1:/home/test2# cat x.py            ## 测试脚本
    #!/usr/bin/python
    
    in_file = open("outcome.ped", "r")
    
    ##first                                         ## 第一次调用
    for i in in_file:
        print(i.strip())
        print("first")
    
    
    ##second
    for j in in_file:                              ## 第二次调用
        print(j.strip())
        print("second")
    (base) root@PC1:/home/test2# python x.py       ## 执行程序,仅执行了第一次调用
    1 G G C C G G
    first
    2 G G G C G G
    first
    3 G G C C G G
    first
    4 G G C C G G
    first
    5 G G C C G G
    first
    6 G G C C G G
    first
    7 G G C C G G
    first
    8 G G C C G G
    first
    9 G G G C G G
    first
    10 G G C C G G
    first
  • 相关阅读:
    awk使用
    SQL VIEW(视图)
    crontab使用
    SecureCRT
    Python异常
    Python字符串
    Python字典,列表,元组
    Python路径
    vim插件
    Python类
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/16566094.html
Copyright © 2020-2023  润新知