•        Python : 3.7.0
  •          OS : Ubuntu 18.04.1 LTS
  •         IDE : PyCharm 2018.2.4
  •       Conda : 4.5.11
  •    typesetting : Markdown

txt(utf-8)

《道德经》原文 "我有三宝持而保之∶一曰慈,二曰俭,三曰不敢为天下先。"
一曰慈,
二曰俭,
三曰不敢为天下先。

code

"""
@Author : 行初心
@Date : 18-10-2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
""" def main():
# file 文件类型的对象
with open(r'1.txt', encoding="utf-8") as file:
print(type(file))
print(file) # 以列表的形式输出文本
lines = list(file)
print(lines) # 输出文本的每一行
for eachLine in lines:
print(eachLine) # 这样做的效率低 if __name__ == '__main__':
main()

result

/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/base/demo.py
<class '_io.TextIOWrapper'>
<_io.TextIOWrapper name='1.txt' mode='r' encoding='utf-8'>
['《道德经》原文 "我有三宝持而保之∶一曰慈,二曰俭,三曰不敢为天下先。"\n', '一曰慈,\n', '二曰俭,\n', '三曰不敢为天下先。']
《道德经》原文 "我有三宝持而保之∶一曰慈,二曰俭,三曰不敢为天下先。" 一曰慈, 二曰俭, 三曰不敢为天下先。 Process finished with exit code 0

resource

  • [文档] docs.python.org/3
  • [规范] www.python.org/dev/peps/pep-0008
  • [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [源码] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [平台] www.cnblogs.com
  • [平台] gitee.com


Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

Python3基础 file for+list 读取txt文本 并 一行一行的输出(低效率)的更多相关文章

  1. 别再用"while (!feof(file))"来逐行读取txt文件了!

    起因 执行一个C/C++程序出现segment fault.它逐行读取文本文件,每一行是一个图片名字,然后读图.处理图像,etc. 发现最后一次读取的文件名不存在(空的). 正确的逐行读取txt文件 ...

  2. C++ 读取txt文本内容,并将结果保存到新文本

    循序渐进学习读文件 // readFile.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <iostream> # ...

  3. ajax读取txt文本时乱码的解决方案

    前言:第一次学习使用 ajax 就是用来读取文本 先给出现乱码的代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ ...

  4. C# 读取txt文本内容写入到excel

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. matlab读取txt文本

    textread函数 原文:http://blog.sina.com.cn/s/blog_618af1950100k926.html 文档:https://ww2.mathworks.cn/help/ ...

  6. Python3基础 file for+文件指针 读取txt文本并 一行一行的输出(高效率)

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. Python3基础 file read 读取txt文件的前几个字符

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 file open 打开txt文件并打印出全文

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 file open+write 对不存在的txt进行创建与写入

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. FW 构建OpenStack的高可用性(HA,High Availability)

    原文地址:http://blog.csdn.net/hilyoo/article/details/7704280 1.CAP理论 1) CAP 理论给出了3个基本要素: 一致性 ( Consisten ...

  2. ZB api

    本文介绍ZB api Rest API (已开启) ZB为用户提供了一个简单的而又强大的API,旨在帮助用户快速高效的将ZB交易功能整合到自己应用当中. 如果在使用过程中有任何问题,请加群764113 ...

  3. Linux上Oracle 11g安装步骤图解

    Oracle 11g下载地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html 选 ...

  4. zookeeper源码导入

    1 搭建步骤 1.1 到github中下载该项目 项目地址 https://github.com/apache/zookeeper.下载.zip包到本地解压. 解压后文件目录: 1.2 使用ant对源 ...

  5. 你可能用得到的9段CSS代码

    一.opacity兼容 .transparent {    filter: alpha(opacity=50);/* internet explorer */    -khtml-opacity: 0 ...

  6. PythonWeb 开发记录(一)

    安装Django Sudo apt-get install python-django 验证安装Django成功 创建Django应用程式的方式 创建的是解决方案 ,然后创建的是Hi 模块 运行项目: ...

  7. RGB颜色参考

    实色效果 英文名称 R.G.B 16色 实色效果 英文名称 R.G.B 16色   Snow 255 250 250 #FFFAFA   PaleTurquoise1 187 255 255 #BBF ...

  8. ubuntu 磁盘分区

    1:查看分区情况:df -h admin@iZwz92c0zpe8t65qe996ckZ:/$ df -h Filesystem Size Used Avail Use% Mounted on ude ...

  9. 前m大的数(哈希入门)&&sort

    http://acm.hdu.edu.cn/showproblem.php?pid=1280 普通方法(625ms) #include <stdio.h> #include <str ...

  10. Linux实验楼学习之一

    查看当前所在目录 pwd 创建文件:1-1.txt touch 1-1.txt 进入统计目录下的etc目录 cd /etc 强行终止当前程序 Ctrl + c 常用快捷键 按键 作用 Ctrl+d 键 ...