Python Forum
Italics - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Italics (/thread-27264.html)



Italics - Dasiey12 - May-31-2020

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)



RE: Italics - menator01 - May-31-2020

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


RE: Italics - Dasiey12 - Jun-01-2020

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,


RE: Italics - menator01 - Jun-01-2020

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')