python clipboard 塊移動

來源:互聯網
上載者:User

這一直沒發現在linux下好用的塊移動的編輯器

因為你可能在網上copy下來的代碼是這樣的需要把整個代碼向前移4個字元自己寫了這樣一個程式來實現這個功能

>>> 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

說明

用到xclip這個軟體

ubuntu下可以直接 sudo apt-get install xclip

#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."

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.