摘要: 任务:有一个多行文本的字符串 需要创建该字符串的一个拷贝,并在每行行首添加或删除一些空格,以保证每行缩进都是指定数目的空格数利用字符串对象提供的 strip() s.splitlines()可以很快的实现#!/usr/bin/python# -*- coding: utf-8 -*-#改变多行文本的缩进def reindent(s,numSpaces): leading_space = numSpaces * ' ' lines = [leading_space + line.strip() for line in s.splitlines()] return '\n& 阅读全文
posted @ 2012-07-23 11:17 cacique 阅读(1149) 评论(0) 推荐(0) 编辑
Copyright ©2011 Goodspeed Cheng