Cut and paste to X clipboard?

Sam Holden sholden at flexal.cs.usyd.edu.au
Tue Jun 29 02:44:03 EDT 2004


On Tue, 29 Jun 2004 00:39:54 -0500,
	Stephen Boulet <stephen.no at spam.theboulets.net.please> wrote:
> Stephen Boulet wrote:
> 
>> Does anyone have a code sample for cutting and pasting to the X-clipboard
>> in python?
> 
> I found a solution for this thanks to the 'xsel' program:
> 
> Copy from the clipboard:
> 
> import os
> s = popen('xsel').read()
> 
> Paste to the clipboard (ok this is a pia):
> 
> import os
> filename = os.path.join(os.path.expanduser('~'),'.tempclipboard')
> f = file(filename,'wb')
> f.write(s)
> f.close()
> command = 'xsel < %s' % filename
> os.popen(command).read()
> os.remove(filename)

What's wrong with:

import os
os.popen('xsel', 'wb').write(s)

?


-- 
Sam Holden



More information about the Python-list mailing list