Python practice Exercise: Adding unordered lists to Wiki tags

Source: Internet
Author: User
Tags python script

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.