Erlo

read text file in python

2019-01-17 20:01:52 发布   278 浏览  
页面报错/反馈
收藏 点赞

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

 

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认