首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取txt将返回有关文件的信息,而不是内容。

读取txt将返回有关文件的信息,而不是内容。
EN

Stack Overflow用户
提问于 2017-08-27 17:37:30
回答 1查看 19关注 0票数 0

这是我的蚂蚁索引程序导入时间的代码。

代码语言:javascript
复制
    import os

    import re

    print ("Welcome to the general purpose")

    print ("library index program in python.")

    print ("This version has been set to find indexed")

    print ("ant species.")

    find_genus_1 = input("please enter Genus")

    find_species_1= input("Please enter species")

    output_base_1 = ('{}{}'.format(find_genus_1, find_species_1))

    output_1 = ('{}{}'.format(output_base_1,'.txt'))

    F = open(output_1,"r")

    print (F)

我运行了它,它返回了下面引用的声明。

<_io.TextIOWrapper名称=‘lasiusniger.txt’模式=‘r’编码=‘cp1252 1252’>

而不是文件中的文本(如下所示)

  • 科学分类
  • 王国:动物
  • 节肢动物门
  • 类别: Insecta
  • 目:膜翅目
  • 科:甲科
  • 亚科: Formicinae
  • 拉西乌斯属
  • 种: L. niger
EN

回答 1

Stack Overflow用户

发布于 2017-08-27 18:20:12

您需要显式地告诉Python读取open()返回的文件对象的内容。使用f.read()f.readlines()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45907620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档