欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

read text file in python

程序员文章站 2022-10-19 17:19:52
** read text file in pythoncapability: reading =text= from a text file 1. open the IDLE text editor >>> idle32. declare a *string* variable that holds ......

** 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