Python Forum
Using Pyperclip in Python 3 Does Not Paste Data in Desired Format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Pyperclip in Python 3 Does Not Paste Data in Desired Format
#1
I'm using python 3.7 and I want to:
  • Copy IPs from a column in excel
  • Add a comma between each IP separated by a space
  • Return as one line
  • Copy back to clipboard using pyperclip.

Below is the desired pasted results:
10.10.10.10, 10.10.10.11, 10.10.10.12, 10.10.10.13, 10.10.10.14

I have looked at some answers I found here and here but it's not printing the desired results. Below, I have tried the following codes but none seem to do it for me:

#code 1
import pyperclip
text = pyperclip.paste()
lines = text.split('\n')
pyperclip.copy('\n'.join(lines))

#code2
import pyperclip
text = pyperclip.paste()
lines = text.split('\n')
a = '{}'.format(', '.join(lines[:-1]))
pyperclip.copy(''.join(a))

#code3
import pyperclip
text = pyperclip.paste()
lines = text.split('\n')
a = '{}'.format(', '.join(lines[:-1]))
pyperclip.copy(a)
Assistance on providing understanding on what I'm missing and getting the desired results would be appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyperclip stopped working OAP 8 977 Apr-13-2025, 12:54 PM
Last Post: OAP
Question [SOLVED] [datetime.strptime] ValueError: time data 'foo' does not match format 'bar' Winfried 1 1,242 Jan-02-2025, 02:09 AM
Last Post: lyly19
  What script to paste folders thenewcoder 1 1,309 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Export data from PDF as tabular format zinho 5 2,401 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 4,032 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 3,844 Dec-12-2022, 08:22 PM
Last Post: jh67
  Please help me [copy and paste file from src to dst] midomarc 2 1,822 Nov-24-2022, 10:13 PM
Last Post: midomarc
  Json filter is not capturing desired key/element mrapple2020 1 1,966 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 4,985 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Need Help writing data into Excel format ajitnayak87 8 4,059 Feb-04-2022, 03:00 AM
Last Post: Jeff_t

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020