python按行读取文件,如何去掉换行符"\n"

for line in file.readlines():
line=line.strip('\n')

python没有substr,但可以用slice

s = line[11:22]

遍历文件夹。os.walk()返回一个三元素的tuple:当前路径、子文件夹名称、文件列表。

import os
def fun( path ):
for root, dirs, files in os.walk( path ):
for fn in files:
print root, fn

  

  

Python Snippet的更多相关文章

  1. A look at WeChat security

    原文地址:http://blog.emaze.net/2013/09/a-look-at-wechat-security.html TL;DR: Any (unprivileged) applicat ...

  2. How to Use Postman to Manage and Execute Your APIs

    How to Use Postman to Manage and Execute Your APIs Postman is convenient for executing APIs because ...

  3. vim中自动补全插件snipmate使用

    vim中自动补全插件snipmate使用 1.下载snipMatezip:https://github.com/msanders/snipmate.vim/archive/master.zip 2.解 ...

  4.  Go is more about software engineering than programming language research.

    https://talks.golang.org/2012/splash.article Go at Google: Language Design in the Service of Softwar ...

  5. Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

    https://geert.vanderkelen.org/2014/results-after-procedure-call/ Problem Using MySQL Connector/Pytho ...

  6. Coroutines declared with async/await syntax is the preferred way of writing asyncio applications. For example, the following snippet of code (requires Python 3.7+) prints “hello”, waits 1 second, and

    小结: 1.异步io  协程 Coroutines and Tasks — Python 3.7.3 documentation https://docs.python.org/3/library/a ...

  7. sublime text添加snippet

    下面的${1:this}格式的会在tab键下一次切换选中 <snippet> <content><![CDATA[Hello, ${1:this} is a ${2:sn ...

  8. 手把手教你写Sublime中的Snippet

    手把手教你写Sublime中的Snippet Sublime Text号称最性感的编辑器, 并且越来越多人使用, 美观, 高效 关于如何使用Sublime text可以参考我的另一篇文章, 相信你会喜 ...

  9. 转帖:Python应用性能分析指南

    原文:A guide to analyzing Python performance While it’s not always the case that every Python program ...

随机推荐

  1. Git命令收集【不断更新中】

    git stash 可以用来保存暂时不想提交但又被修改过的文件. git stash pop 用来取出被保存在stash栈中的修改过的所有文件. git stash show 查询哪些文件被存放在了s ...

  2. Cookie 的运行机制以及常用规则

    一   setCookie        bool setcookie ( string name [, string value [, int expire [, string path [, st ...

  3. IOS 控件的生命周期

    ViewController的生命周期包括: Initialize ViewDidLoad ViewWillAppear ViewDidAppear ViewWillDisappear ViewDid ...

  4. 【学习总结】iOS 数据保存几种方式总结

    在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好.下面介绍一下数据保存的方式: NSKeyedAr ...

  5. Careercup - Facebook面试题 - 5998719358992384

    2014-05-02 00:22 题目链接 原题: Given a matrix consisting of 's. 题目:给定一个01矩阵,找出由1构成的连通分量中最大的一个. 解法:四邻接还是八邻 ...

  6. android 中设置HttpURLConnection 超时并判断是否超时

    设置超时: URL url1 = new URL(url); HttpURLConnection conn = (HttpURLConnection) url1.openConnection(); c ...

  7. php 安全处理方案

    Safe::mysqlSafe(); sql注入,升级5.3.6以上版本php 方案一:将所有请求中所有数据(get/post/cookie)实现mysql_escape_string进行安全处理. ...

  8. uoj 67 新年的毒瘤 割点

    题目链接: 题目 #67. 新年的毒瘤 问题描述 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树. 这个长着毒瘤的树可以用 nn 个结点 mm 条无向边的无向图表示.这个图中有 ...

  9. 'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件的解决办法

    前言: 本文的解决方法来自http://www.cnblogs.com/xionghui/archive/2012/04/11/2442404.html --感谢! 问题描述:新电脑装mysql后在c ...

  10. Asp.Net原理Version3.0_页面声明周期

    Asp.Net原理Version1.0 Asp.Net原理Version2.0                   相关源码 页面的Process方法 // System.Web.UI.Page pr ...