python实现剪切功能


Posted in Python onJanuary 23, 2019

本文实例为大家分享了python实现剪切功能的具体代码,供大家参考,具体内容如下

#!/usr/bin/env python
#coding: utf8

import sys

mystr = []

def inputstr():
 item = raw_input('Please input your string:')
 mystr[:] = [] #清空列表
 mystr.extend(item) #将输入的字符串拆开为一个一个字符填入列表

def printstr():
 lenth = len(mystr) - 1
 index = 0
 print "Your result is :"
 print "*****" + ''.join(mystr) + "*****"
 #.join()与之前的extend对应,将字符合并为一个元素,用''里面的内容分割。''里面为空,则字符之间没有间隙
 print "----------------分割符----------------"

def leftstrip(): #左剪切
 while True:
 if mystr[0] == ' ':
  mystr.pop(0)
 else:
  break
 printstr()

def rightstrip():#右剪切
 while True:
 if mystr[-1] == ' ':
  mystr.pop()
 else:
  break
 printstr()

def bothsidestrip():
 while True:
 if mystr[-1] == ' ':
  mystr.pop()
 elif mystr[0] == ' ':
  mystr.pop(0)
 else:
  break
 printstr()
#使用字典的方式,实现case的语法功能
CMDs = {'l':leftstrip,'r':rightstrip,'b':bothsidestrip}

def showmenu():
 prompt = """(L)eftstrip
(R)ightstrip
(B)othsidestrip
(Q)uit
Please select a choice:"""
 while True:
 choice = raw_input(prompt).lower()
 if choice not in 'lrbq':
  continue
 if choice == 'q':
  break
 inputstr()
 CMDs[choice]()

if __name__=='__main__':
 showmenu()

效果图:

python实现剪切功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python dict remove数组删除(del,pop)
Mar 24 Python
Python实现给qq邮箱发送邮件的方法
May 28 Python
python实现汉诺塔方法汇总
Jul 25 Python
python 将对象设置为可迭代的两种实现方法
Jan 21 Python
python 环境搭建 及python-3.4.4的下载和安装过程
Jul 20 Python
在django中实现页面倒数几秒后自动跳转的例子
Aug 16 Python
python将print输出的信息保留到日志文件中
Sep 27 Python
python模拟实现斗地主发牌
Jan 07 Python
pycharm内无法import已安装的模块问题解决
Feb 12 Python
Python中pyecharts安装及安装失败的解决方法
Feb 18 Python
Pycharm github配置实现过程图解
Oct 13 Python
Keras在mnist上的CNN实践,并且自定义loss函数曲线图操作
May 25 Python
对python实现合并两个排序链表的方法详解
Jan 23 #Python
Python基于Logistic回归建模计算某银行在降低贷款拖欠率的数据示例
Jan 23 #Python
python实现石头剪刀布程序
Jan 20 #Python
python random从集合中随机选择元素的方法
Jan 23 #Python
python3+selenium实现qq邮箱登陆并发送邮件功能
Jan 23 #Python
python3+selenium实现126邮箱登陆并发送邮件功能
Jan 23 #Python
python+selenium实现QQ邮箱自动发送功能
Jan 23 #Python
You might like
php输出1000以内质数(素数)示例
2014/02/16 PHP
PHP基于MySQLI函数封装的数据库连接工具类【定义与用法】
2017/08/11 PHP
IE6下JS动态设置图片src地址问题
2010/01/08 Javascript
JS中prototype关键字的功能介绍及使用示例
2013/07/21 Javascript
JQuery对class属性的操作实现按钮开关效果
2013/10/11 Javascript
Extjs4实现两个GridPanel之间数据拖拽功能具体方法
2013/11/21 Javascript
js插件YprogressBar实现漂亮的进度条效果
2015/04/20 Javascript
JavaScript判断数组是否包含指定元素的方法
2015/07/01 Javascript
JS高仿抛物线加入购物车特效实现代码
2017/02/20 Javascript
ES6基础之展开语法(Spread syntax)
2019/02/21 Javascript
JavaScript实现公告栏上下滚动效果
2020/03/13 Javascript
《javascript设计模式》学习笔记一:Javascript面向对象程序设计对象成员的定义分析
2020/04/07 Javascript
jquery实现简单拖拽效果
2020/07/20 jQuery
vue组件中节流函数的失效的原因和解决方法
2020/12/02 Vue.js
[00:50]2014DOTA2国际邀请赛 NEWBEE战队回顾
2014/08/01 DOTA
netbeans7安装python插件的方法图解
2013/12/24 Python
python通过urllib2爬网页上种子下载示例
2014/02/24 Python
Python字符串拼接的几种方法整理
2017/08/02 Python
使用Python微信库itchat获得好友和群组已撤回的消息
2018/06/24 Python
Python编程中flask的简介与简单使用
2018/12/28 Python
对python使用telnet实现弱密码登录的方法详解
2019/01/26 Python
python 获取等间隔的数组实例
2019/07/04 Python
python爬虫-模拟微博登录功能
2019/09/12 Python
django 取消csrf限制的实例
2020/03/13 Python
python3 re返回形式总结
2020/11/20 Python
英国No.1体育用品零售商:SportsDirect.com
2019/10/16 全球购物
科级干部考察材料
2014/02/15 职场文书
优秀广告词大全
2014/03/19 职场文书
企业安全生产标语
2014/06/06 职场文书
四风对照检查材料范文
2014/09/27 职场文书
检讨书模板
2015/01/29 职场文书
2015年党风建设工作总结
2015/04/29 职场文书
比较node.js和Deno
2021/04/27 Javascript
Python基础之元类详解
2021/04/29 Python
Python虚拟环境virtualenv是如何使用的
2021/06/20 Python
Java详细解析==和equals的区别
2022/04/07 Java/Android