In this video, Kathryn shows you how to format your text with Python's text wrap module. Learn how to dedent and indent your text, set how much space the text will occupy, and how to add a placeholder such as an ellipsis if the text is too long.
- [Instructor] Let's figure out how to format text…with the Text Wrap Module, and in order to use…this module we need to import it,…and so we're going to go import textwrap,…and we'll go ahead and print the text…without any dedenting, and we'll…learn what that means in a minute.…So we'll go print(textwrap.fill(websiteText)),…and so printing this out you'll see that…when we printed it, it kept this beginning space…that we had up here but it didn't keep…our enters, meaning it broke our text at different places.…
So it kind of edited it on its own…and filled a certain particular space…but still kept this beginning tab here.…This is one way that you could display your text.…Another way is to have dedenting,…and what this is going to do is it's going to take…away our beginning and later spaces…and it's going to keep the enters that…we had here, it's not going to reformat them.…And so in order to create dedent text…we'll go dedent_text = textwrap.dedent(websiteText).strip,…and then we'll go ahead and print out…this dedented text, dedent_text,…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
Learning the Standard PHP Librarywith David Powers3h 24m Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.