Python – Convert simple lines to bulleted lines using the Pyperclip module
Last Updated :
06 Feb, 2020
Pyperclip is the cross-platform Python module which is used for copying and pasting the text to the clipboard. Let’s suppose you want to automate the task of copying the text and then convert them to the bulleted points. This can be done using the pyperclip
module. Consider the below examples for better understanding.
Examples:
Clipboard Content :
United we stand, divided we fall.
Where there is a will, there is a way.
Rome was not built in a day.
New clipboard Content :
* United we stand, divided we fall.
* Where there is a will, there is a way.
* Rome was not built in a day.
Approach: First, you need to copy whatever text you want to convert to bulleted text then you need to run the program and after its successful execution when you paste the contents of clipboard you can see that the contents have been already modified. Two methods of this module have been used i.e. paste()
method which is used to paste as well as return the copied string and copy()
which is used to pass the string to the clipboard.
Below is the implementation.
import pyperclip
text = pyperclip.paste()
print ( "Before Modification:" )
print (text)
lines = text.split( "\n" )
for i in range ( len (lines)):
lines[i] = "*" + lines[i]
text = "\n" .join(lines)
pyperclip.copy(text)
print ( "\nAfter Modification:" )
print (pyperclip.paste())
|
Output:
Before Modification:
United we stand, divided we fall.
Where there is a will, there is a way.
Rome was not built in a day.
After Modification:
*United we stand, divided we fall.
*Where there is a will, there is a way.
*Rome was not built in a day.
Share your thoughts in the comments
Please Login to comment...