Python clipboard Block Movement

Source: Internet
Author: User

This has never been found in the Linux block mobile editor.

Because the code you may copy on the internet is like this, you need to move the entire code four characters forward and write such a program to implement this function.

>>> from sqlalchemy import Column, Integer, String>>> class User(Base):...     __tablename__ = 'users'......     id = Column(Integer, primary_key=True)...     name = Column(String)...     fullname = Column(String)...     password = Column(String)

Step

1. Copy Clipboard data to file

2. read data from File

3. Block move

4. Save File

5. copy file data to clipboard

Description

Xclip is used.

Sudo apt-Get install xclip in Ubuntu

# Copy Clipboard data to from.txt
Xclip-o> from.txt

# Copy data to clipboard
Cmd = 'cat to.txt | xclip-selection clipboard'
OS. popen (CMD)

Block_move.py

#!/usr/bin/env pythonimport sysimport osdel_num = 3if len(sys.argv)>1:    del_num = int(sys.argv[1])#copy clipboard data to from.txtcmd = 'xclip -o > from.txt'os.popen(cmd).read()to_data = []print "from.txt:"with open('from.txt') as fp:      for line in fp:          print line,        to_line = line[del_num:]        to_data.append(to_line)to_file = open('to.txt', 'w')data = ''.join(to_data)to_file.write(data)to_file.close()#copy data to clipboardcmd = 'cat to.txt | xclip -selection clipboard'os.popen(cmd)print ""print "to.txt:"print dataprint "del_num:", del_num print "ok."

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.