Ask Your Question
2

How to copy huge output in another code?

asked 2022-08-12 07:00:19 +0100

sgmth gravatar image

updated 2022-08-28 19:27:41 +0100

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?

edit retag flag offensive close merge delete

Comments

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-08-12 07:41:03 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-08-12 12:04:06 +0100

tmonteil gravatar image

updated 2022-08-12 12:16:42 +0100

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)))
edit flag offensive delete link more

Comments

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

sgmth gravatar imagesgmth ( 2022-08-15 07:54:55 +0100 )edit

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: 2022-08-12 07:00:19 +0100

Seen: 333 times

Last updated: Aug 12 '22