zoukankan      html  css  js  c++  java
  • for i in xrange(0,5)使用过程中遇到的问题

    文件中共有4行内容。

    fd = open("C:UserswilliamDesktopdup_file - Copy (2).txt")
    for i in xrange(0,5):
    print type(fd.readline())
    print fd.readline()
    print "-----"

    <type 'str'>
    ccf30309-2a02-4d09-8ea8-70c3da8de09d

    -----
    <type 'str'>
    9cee8472-dfc1-49ac-90c3-572f68373934

    -----
    <type 'str'>

    -----
    <type 'str'>

    -----
    <type 'str'>

    -----

    执行第1个print,返回了第1行的type,然后第2个print,返回了第2行的value,并print后面有换行符

    后面循环,返回了第3行的type, 然后是第4行的value。

    所以这里要注意的是,每次循环,最好注意调用readline的次数。

    fd = open("C:UserswilliamDesktopdup_file - Copy (2).txt")
    for i in xrange(0,5):
    print i
    print fd.readline()
    print "-----"

    0
    8957d983-05e2-4a54-a7b3-f1532421c7a7

    -----
    1
    ccf30309-2a02-4d09-8ea8-70c3da8de09d

    -----
    2
    492ddb07-e0c5-4dda-ae91-8b3700d05a79

    -----
    3
    9cee8472-dfc1-49ac-90c3-572f68373934

    -----
    4

    -----

    fd = open("C:UserswilliamDesktopdup_file - Copy (2).txt")
    for i in xrange(0,5):
    print i
    print fd.readline(),

    0
    8957d983-05e2-4a54-a7b3-f1532421c7a7
    1
    ccf30309-2a02-4d09-8ea8-70c3da8de09d
    2
    492ddb07-e0c5-4dda-ae91-8b3700d05a79
    3
    9cee8472-dfc1-49ac-90c3-572f68373934
    4

    这里主要是复习一下print不换行的方法,后面加逗号","

  • 相关阅读:
    Python参考资料汇总
    Redis发布/订阅
    Redis读书笔记之API的理解和使用
    三、Dubbo源码学习笔记(一)之 Spring容器启动
    利用VMware在虚拟机上安装Zookeeper集群
    二、Dubbo相关文献链接
    一、Dubbo初体验
    @Retention小记
    EasyUI知识点杂记
    ---Mybatis3学习笔记(2)补充
  • 原文地址:https://www.cnblogs.com/guohuino2/p/6042839.html
Copyright © 2011-2022 走看看