Title Description
Items: Adding unordered lists to Wiki tags
When editing a Wikipedia article, you can create an unordered list that takes one row for each item and places an asterisk in front of it. But suppose you have a very large list and want to add the preceding asterisk. You can enter these asterisks at the beginning of each line, one line after the other. Alternatively, you can automate this task with a small Python script.
The bulletpointadder.py script gets the text from the Clipboard, adds an asterisk and a space at the beginning of each line, and then pastes the new text back into the Clipboard. For example, if I copy the following text to the Clipboard (taken from the Wikipedia article "List of Lists of Lists"):
Lists of Animals
Lists of Aquarium life
Lists of biologists by author abbreviation
Lists of cultivars
Then run the bulletpointadder.py program and the Clipboard will contain the following content:
* Lists of animals
* Lists of Aquarium life
* Lists of biologists by author abbreviation
* Lists of cultivars
This text, preceded by an asterisk, can be pasted back into Wikipedia's article as an unordered list.
Run
Command line Run
Copy that four rows list
D:\>cd D:\Code\VimCode\Python_auto\RunD:\Code\VimCode\Python_auto\Run>python bulletPointAdder.py
Script Run
Step Analysis:
1. Clipboard copy and paste, using Text=pyperclip.paste (), this is not difficult, simple to use the Pyperclip library. Paste () and. Copy () on the line
2. Detach the lines in the text and add an asterisk. line = Text.split (' \ n ').
3. Link line after processing. Text= ' \ n '. Join (lines)
Code:
#! python4# bulletPointAdder.py - Adds Wikipedia bullet points to the start# of each line of text on the clipboard.import pypercliptext = pyperclip.paste()# 分离行和添加星号lines = text.split('\n')for i in range(len(lines)): lines[i] = '*' + lines[i]# 连结linestext = '\n'.join(lines)pyperclip.copy(text)
Use the string method to summarize:
Split (str), separating with Str as interval
'. Join (str) to ' Connect str list
Python practice Exercise: Adding unordered lists to Wiki tags