从txt文件读入 [英] Read in from a txt file
本文介绍了从txt文件读入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我希望我的python代码能够读取我在.txt文件中的行,并在调用时将其打印到另一个文件中。
< b>我尝试了什么:
导入os
随机导入
导入时间< br $>
var = open(Test.txt)
print(var)
当我使用它时得到的结果:
< _io.TextIOWrapper name ='Test.txt'mode = 'r'coding ='US-ASCII'>
Basically I want my python code to be able to read the line I have in my .txt file and print it out in another file when called.
What I have tried:
import os
import random
import time
var = open("Test.txt")
print(var)
And what I get when I use that:
<_io.TextIOWrapper name='Test.txt' mode='r' encoding='US-ASCII'>
推荐答案
您只打开文件,但您没有从中读取任何内容。请参见 7。输入和输出 - Python 3.6.3文档 [ ^ ]
You only open the file, you have not read anything from it. See 7. Input and Output — Python 3.6.3 documentation[^]
从这里开始:用Python读取和写入文件 [ ^ ]
这篇关于从txt文件读入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文