稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

python3 从文件中搜索包含字符串的行

import codecs
FileName = r'c:\ls\1'
#KeyStr = input("the key string: ")
KeyStr = '<dd class="info"><span>执业证号:'
FoundFlag = False
#用utf-8格式打开文件
FileObj = codecs.open(FileName, 'r', 'utf-8')
LineTemp = FileObj.readline()
while LineTemp:
   # print(LineTemp)
   # print(KeyStr)
   # zc = LineTemp.find(KeyStr)
    
    if LineTemp.find(KeyStr) > 0:
        FoundFlag = True
        print("*************************")         
        print("the line is: " + LineTemp, end='')
        print("*************************")
        LineTemp = FileObj.readline()
 #       break
    else:
        LineTemp = FileObj.readline()
FileObj.close()
if FoundFlag == False:
    print("Not found the string!")

posted on 2018-05-23 15:11 AlanTop 阅读(1374) 评论(0)  编辑 收藏 引用 所属分类: Python


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理