python实现剪切功能

作者:huangyingleo 时间:2023-02-27 17:52:01 

本文实例为大家分享了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实现剪切功能

来源:https://blog.csdn.net/huangyingleo/article/details/54176507

标签:python,剪切
0
投稿

猜你喜欢

  • python中csv文件的若干读写方法小结

    2021-04-07 11:46:03
  • layui radio单选限制下一个radio单选的实例

    2024-06-09 15:52:07
  • python的re模块使用方法详解

    2022-08-10 16:18:20
  • 老生常谈Python之装饰器、迭代器和生成器

    2023-04-08 08:28:19
  • 基于Python socket实现简易网络聊天室

    2021-10-19 09:10:30
  • Python 数据类型--集合set

    2021-11-23 21:17:54
  • Python正则表达式和元字符详解

    2021-02-26 02:54:19
  • 使用python进行文本预处理和提取特征的实例

    2022-07-13 21:25:47
  • 使用Python实现大学座位预约功能

    2022-03-14 16:26:53
  • go语言数组及结构体继承和初始化示例解析

    2024-05-08 10:22:35
  • W3C优质网页小贴士(二)

    2008-04-07 12:14:00
  • Go语言break跳转语句怎么使用

    2024-05-28 15:37:12
  • ASP.NET页面间的传值的几种方法

    2024-05-11 09:26:52
  • SQL Server远程定时备份数据库脚本分享

    2024-01-24 12:20:31
  • WebStorm 遇到的问题总结

    2023-08-31 23:30:00
  • C#使用ADO.Net连接数据库与DbProviderFactory实现多数据库访问

    2024-01-24 08:56:29
  • MySQL 管理

    2024-01-13 14:42:43
  • MySQL数据库安装和Navicat for MySQL配合使用教程

    2024-01-24 16:50:58
  • ASP.NET 2.0防止同一用户同时登录

    2007-10-03 14:30:00
  • TensorFlow实现简单的CNN的方法

    2023-09-14 14:08:50
  • asp之家 网络编程 m.aspxhome.com