This is the 11th day of my participation in Gwen Challenge
Application scenarios
If we are editing a document in Markdown format and need to display a large list, but currently only have each line of text, we need to add an “*” to the front of each line so that the document in Markdown can form an unordered list. Here is a quick way to use CTRL + C, CTRL + V.
Unordered list Markdown syntax
* haha * hahaCopy the code
Effect:
- Ha ha
- Ha ha
For example, zhu Ziqing’s 246 lines of the long poem “Destruction” need to be displayed in the form of an unordered list. If we need to manually add “*” before each line, how tiring it is. We need to automate it
steps
- Select line 246 and right – click copy
- Run this program
- Right click paste where you want to insert it, Bingo
How do we do this when we look at Python’s Pyperclip module
The PyPerClip module is not a built-in module and needs to be installed by itself:
pip3 install pyperclip
Copy the code
- Pyperclip.paste () : Gets the copied content from the computer clipboard
- Pyperclip. copy(text) : Put the content of a text onto the computer clipboard. The pasted data becomes the content of the text
So, let’s automate it by adding a * to each line.
#! /usr/bin/env python3
# coding=utf-8
__author__ = "RidingRoad"
import pyperclip
def main() :
Before running, select the data to form an unordered list and right click copy. After running, right click paste to generate a Mark Down unordered list.
Get the clipboard data
text = pyperclip.paste()
# Split long strings into a list according to "\n"
text_split = text.split('\n')
Add "* "(* and a space) before each line
for i in range(len(text_split)):
text_split[i] = "*" + text_split[i]
# merger
text = "\n".join(text_split)
# Put the processed data back to the clipboard
pyperclip.copy(text)
if __name__ == "__main__":
main()
Copy the code
After running clipboard contents:
* wandering halfway, * dejected, * it's me, it's me! * Five light bar, * ten color bar, * listed in close between: * this good-looking ah! * That sounds good! * smell is thick incense, * taste is greasy taste; What the hand touches, what the body depends on, is slippery and soft! * Decadent! * How can this cheap? -- * being pushed, * being held in arms, * long only in the bending, * ever do a minute and a half son Lord? * in the dream, * in the sick; * All that's missing is waking up! * I am in the clouds, * floating in the sky wind, * I am in the abyss, * The torrent of volts; * only in the green, green soil, * never printed with shallow, indistinct, my footprints! * I emigrate, * I emigrate; * tiptoes tread, * but not on her own land! * Old in the dust, * decayed in the dust, * the last lazy corporeal body, * heaps of black shadows! * The beginning of disillusionment, * I try to think: * "Dear, though he, * my hometown -- my hometown! * go back! Go back!" * Though there is a vast pale moon, * cage of the quiet lake, * mist dewy, * mist dewy; * Imitation Buddha Buddha mountains, * are arranged to sleep. * The fireflies, unable to find their way through the fog, only fluttered about. * Who puts lotus lanterns? "Ha ha ha ha ~ ~ ~" * * "frighten frighten ~ ~ ~" with a low sound, * near the frog also then sounded the. * is rocked, * is led, * said to have fallen asleep in the "sister's arms"; * Really, who can go without floating? * But the moon is really lonely, * the fireflies are not close to me, * laughter is obviously theirs. Only the sound of the flute, which has caused melancholy; The sound of the organ is only the sound of the organ. * Swinging is yours, * teasing is yours, * they go their separate ways, * who cares about you? * do not make friends, * chanchanmianmian some what! * Lonely, * cold, * tasteless, tasteless! * Turn around and go your own way. * go back! Go back! Although the snow-like dress is now fluttering away, it looks like the white paper ashes burned during the Qingming Festival. * That live like a river like flow of eyes, * too much implied meaning, contain more than a few words, * also dried up, * dry like a desert under the sun. * dark hair, * became a shaggy autumn grass; The face that had been blown to pieces was only brown and waxy. State flower general smile is not a trace son, * beads general singing voice is not through a trace son! * Eyes are light, * always only light. * Forget about it. * What else to skim! * go back! Go back! Though we have friends like clouds, * boasting and comforting each other, * talking and laughing, * wasting away hours; * and drink the heroic, * wandering close, * not like luxuriant flowers, the most hot flames! Who can forget him that was so spoken in many mouths and known in many hearts? * But a hand away, * things are different: * turn over is the cloud, * over is the rain, * don't face, * turn around, * can't recognize you! -- * It was just a whim, * who really cares about you? * Then there are some faint names -- * In the wilderness, * you are left alone, * surrounded by air, * surrounded by air! * Feel your way back; There may be brothers and sisters who look forward to you. * go back! Go back! * Though there is a subtle mystery, * like smallpox falling; And in front of my eyes, there's a light vision -- and it takes me down, down, down, up to thirty-three days. I was in a cloud of colors, and the gray world was at my feet -- smaller, smaller, farther away, almost out of my mind. * but lower GangFeng * always thus backspin, * blow people my filar silk muscle! If I were to fall, I would be like a balloon, trampled on by people, with only a sound of sound! Will the contagious contagious disease, like a three-pointed and two-bladed knife, clew into my flesh? * I shall be dismembered in clouds of five colors; * even a burst of smoke, * curl to scattered. * I shivered, * "read the heaven and earth long"... * go back! Go back! * A hungry stomach, * cramped hands, * shaggy hair, * recessed eyes, * soft feet, * especially a weak heart, * all lead me down, * to the bottom of my heart, * teach me to smoke, * teach me to drink, * teach me to look at women. * But I am in fan infatuation love, * although mixed how many moments, * just do not give in is my present, * he does not allow you to ignore him! I finally can not support the infatuation of people, * only feel the body decay, * mind wandering, * then in the middle of infatuation, * also grow secretly! * Really not human kind of me * so gently quick rot it? * don't! No! * While you are not crippled, * still use the only strength you have! * go back! Go back! * though death seemed like a white girl, * in front of me, carrying a lantern * and alex, like black * holding a hammer force behind me - * will come in I worry the prodigal fierce miserably, * and hatred between the year of the same flesh and blood, * (with blood eye each other up and take notice), * in my for two shoulder the burden of life, * when I can't breathe, * when I see my harvest * empty like clouds and smoke in the distance; * When, facing the dark, fluffy and white future, I * do not know what path to take, * but wander about in the disputes of understanding, * Then she and he appear, * like something, * like nothing -- * with such an elusive look, * enough for me to look forward to. * Go, go, * to her, his arms. * Well, she looked at me and waved, * he looked at me and nodded. ... * But, but, * She and he were strangers, * I was a little uneasy; * Their hands are floating in the air, * too thin, * too hard to grasp, * how can I reach them? The land of death is a foreign land. Know what land it is! Only in the origin of life, * I am familiar; * My hometown is in my memory, * blurred, * but its outline is familiar to me -- * Alas! Doesn't my hometown greet me with open arms? * Melons and fruits are ripe and tasty; * Places and friends are familiar; * Little girl, * Lex in black, * I'd rather go home, * I'd rather go home; * go back! Go back! * Return of my struggle, * smoke and see their own land! * There is no image left, no light left; * get rid of entanglement, * reduction of an ordinary me! * from now on I no longer looked up at the sky, * no longer looked down at the white water, * only cautious of my footsteps in both; * I want to step step by step on the soil, * hit deep footprints! * Though these marks are very small, * and will be extinguished, * though this slow step * is not called an endless journey, * But now * I, ordinary and insignificant, * only see a clear step, * I am very happy -- * those far away * can no longer, And I don't want to. * Don't delay, * go! Go! Go!Copy the code
Effect of Markdown
- Wandering about halfway,
- Crestfallen,
- It’s me! It’s me!
- Five more light,
- Ten colors,
- The list is close at hand:
- This beautiful ah!
- That’s nice!
- The smell is thick,
- Taste is greasy taste;
- What my hand touches,
- Where the body is,
- It’s all slippery,
- It’s all fluffy!
……………………