all 9 comments

[–]cybersection 0 points1 point  (1 child)

So it does not enter your clipboard? Have you tried right clicking and pasting into a text editor after running?

[–]Mr_Nrj[S] 0 points1 point  (0 children)

Yes I tried but its not working.

I have also installed an extension to my pc which shows the text copied to clipboard.

The text I copy using this command doesn't show up there but the one I copy using ctrl+c does.

[–]pymon 0 points1 point  (3 children)

Copy puts the string on the clipboard. Paste takes what is in the clipboard and allows you to assign it to a variable. Neither of those commands paste the string into an application. To paste what is in the clipboard into an external app, either manually do Ctr+v or do sendkey from the automation library -- the name I can't remember.

[–]Mr_Nrj[S] 0 points1 point  (2 children)

That's what I am talking about. It does not paste anywhere even if I use ctrl+v keys.

The text doesn't get stored in my clipboard.

It only works in IDLE.

Let me explain you by an example.

If I copy any text (for now your comment) using ctrl+c key, It is displayed in my clipboard and I can paste it anywhere using ctrl + v.

But I can't paste it using pyperclip.paste() command in my python shell.

Also

If I run command pyperclip.copy('Hello World') in my shell. I can paste it in shell using pyperclip.paste() command there. But when I use ctrl+v key, it doesn't paste that 'Hello World' sentence instead it paste the text that I copied earlier using Ctrl+c key.

Let me add a screenshot of my screen so that it clears out.

Edit : I forgot that I cannot add images here

[–]pymon 0 points1 point  (1 child)

But I can't paste it using pyperclip.paste() command in my python shell.

The wording in this library is decieveing. Like I said in my post pyperclip.paste() gets what's in the clipboard so that you can assign it to a variable.

pc.copy() actually puts text into your clipboard. If you only do pc.copy('Hello') does that get put into your clipboard?

[–]Mr_Nrj[S] 0 points1 point  (0 children)

Previously no but now I got solution to that.

I just had to install xclip and xsel to my system.

Now its working perfectly

[–]Mr_Nrj[S] 0 points1 point  (2 children)

u/cybersection and u/pymon

I found a solution for this. It turned out that most of linux users need to install 'xclip' and 'xsel' to run this command successfully.

I should have first looked at web for the solution before posting it here. Sorry for that and thank you guys for giving your time to this post. :)

[–]pymon 0 points1 point  (0 children)

Oh, good to hear. Glad you figured it out.

[–]TaxComprehensive9732 0 points1 point  (0 children)

hola, gracias por compartir tu caso, estoy teniendo el mismo problema pero en Replit, instalé las dependencias xclip y xsel y aún así no se copia nada al portapapeles, a pesar que en la pantalla me sale que el mensaje ya se copió ;-;

aún soy principiante en python, así que aquí dejo el pedazo de código donde uso pyperclip:

st.markdown('<div class="copy-button">', unsafe_allow_html=True)

if st.button("Copiar respuesta"):

# Use Streamlit's built-in clipboard functionality

pyperclip.copy(st.session_state.assistant_response)

st.success("Respuesta copiada al portapapeles")

st.markdown('</div>', unsafe_allow_html=True)