First time here? Check out the FAQ!

Ask Your Question
2

How to copy huge output in another code?

asked 2 years ago

sgmth gravatar image

updated 2 years ago

tmonteil gravatar image

My code gives an output containing lakhs of matrices. I want to use that output in another code. By "print(sage_input())" command I get the output in the form, which I can manually copy and use it in another code. But the problem is , it is taking a lot of time to manually select the output as the output is huge. Is there any simpler way to do so?

Preview: (hide)

Comments

What is the problem with saving your "huge output" in a variable ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2 years ago )

1 Answer

Sort by » oldest newest most voted
3

answered 2 years ago

tmonteil gravatar image

updated 2 years ago

Your question is not very clear on where to copy the code.

If you want to save the output in a text file named /tmp/file.py, you can do:

sage: m = random_matrix(ZZ,100,100)
sage: with open('/tmp/file.py','w') as f:
....:     f.write(str(sage_input(m)))

If you want to append to an existing file, just replace 'w' with 'a'.

If you want to copy the output in the clipboard so that you can paste it from the mouse to some window with CTRL+V, you can install clipboard Python module within Sage virtual environment from a shell:

$ sage -pip install clipboard

an then do (in the Sage session):

sage: import clipboard
sage: clipboard.copy(str(sage_input(m)))
Preview: (hide)
link

Comments

Yes, the "clipboard" one I wanted. Thanks a lot. My problem is solved.

sgmth gravatar imagesgmth ( 2 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 384 times

Last updated: Aug 12 '22