Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Italics
#1
I am pretty new to coding. I have had some luck with VBA. So python why not! I am reading Eric Matthews, Python Crash Course 2nd edition. I am working with string data type. I'd like to further one of his exercises. I want to be able to store the names of authors and their quotes. I'd like to italics the quote. I was able to use, python -m pip install docx. I did install it. I do not own Microsoft Word. I can't use the package. I was wondering about using Google Docs, but it is an API. I am working pretty hard to use python packages. Is there another free word processing program I could use to run my code and have the quote be italics?
Here is my code just to store the name of the author and the quote.

first_name = "Eric"
last_name = "Carl"
quote = "[i]My oh my, how the days have flown by since we have met[/i]."   
name_quote = (f"{first_name.title()} {last_name.title()} \n\t {quote}")
print(name_quote)
Reply
#2
Don't know if your wanting this in shell or if this works on all os.
# Italic text
txt = '\x1B[3mThis is italic text\x1B[23m'

# Add rgb color too this case red
print(f'\1xB[38;2;255;0;0m{txt}\033[39m')
Will print in italic in shell/terminal
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
my-python
Reply
#3
Hi thanks for the reply. I tried to run the code.

txt = '\x1B[3m This is italic text \x1B[23m'
print(txt)
I am using Sublime a text editor. I saved the file as .py. When I run the code and it prints in Sublime the text editor output says,
Output:
<0x1b>3m This is italic text <0x1b> [23
I also tried to open the .py file in the Python 3.8.3 shell and the output wasn't italic text.
Output:
This is italic text 
One last question about dealing with string data type. When I make a variable and assign the text to the variable the text has to be in quotation marks. The book I am reading appears to recommend double quotes. Do you think that is right? Why are you using a single quote?

thanks,
Reply
#4
If you are using windows the encoding is a little different.
You can read about it here.
The single quotes just my preference. The lessons I watched said it did not matter, they are treated the same. Just my opinion, the only advantage I could see is if you needed a single quote in the string eg:myval = "Isn't this a string" as apposed to myval = 'Isn\'t this a string'

This is for terminal. Will not work in IDE's

Not always supported you can try this
print(f'\033[3mThis is italic text\033[0m')
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
my-python
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020