read text file in python

2019-01-21 02:42:46来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

** read text file in python
capability: reading =text= from a text file

1. open the IDLE text editor
    >>> idle3
2. declare a *string* variable that holds *the path to the text file*, =test.txt=
    >>> strPath="/home/kaiming/Documents/Python/text/text.dat"
3. open the file using the =open()= function
    >>> f=open(strPath)
4. Read the contents of the file using the =read()= function
    >>> StrText=f.read()
5. Print out the contents of the file
    >>> print(strText)

 

refer to

https://docs.python.org/2/tutorial/inputoutput.html

 


原文链接:https://www.cnblogs.com/code-saturne/p/10284114.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python 学习总结5

下一篇:Python中threading的join和setDaemon的区别[带例子]