【问题标题】:Reading the txt is returning the information about the file and not the contents读取 txt 是返回有关文件的信息而不是内容
【发布时间】:2018-02-05 01:14:30
【问题描述】:

这是我的代码 用于蚂蚁物种索引程序 进口时间

    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 name="Lasiusniger.txt" mode="r" encoding="cp1252">

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

  • 科学分类
  • 王国:动物界
  • 门:节肢动物门
  • 类别:昆虫纲
  • 目:膜翅目
  • 科:蚁科
  • 亚科:蚁科
  • 属:Lasius
  • 物种:尼日尔乳杆菌

【问题讨论】:

    标签: python-3.x io


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 2011-03-14
      • 2020-08-18
      • 1970-01-01
      相关资源
      最近更新 更多