pythoneclipsetext-manipulation

How do I print text in italics in Python?


I am writing a program that is supposed to take entries and return an APA citation in a specific modified form of APA. I have realized that I will need to print only certain parts of the text in italics. Right now, my program just does an input asking if you have certain information and if you do, it asks for it, formats it, and puts it in one list(fullCitation) that I will eventually do print("".join(fullCitation)) to and that will print the whole citaion. The first part that i need italics for is the publisher name and I will probably need to store it as italic text in the fullCitation list. I could figure out a way to print it out by itself using index ranges and doing only that italics, but all i really need to know is how to print/store italic text in Python. I am using language version 3.0. I use eclipse Juno on windows 10. Here is my code:

welcome="Welcome to the research APA citation machine. If you want specific instructions, type help. If you are ready, type ready."  
print(welcome)
type=input('web page=1, Journal=2. type your citation type number: ')
#asks citation type. only journal is available (work in progress)
fullCitation=[]
#this is the whole citation in a list. Everything gets appended in a certain order with spaces already formatted. 
authorKnown=input("Is the author known? ")
if authorKnown.lower()=='yes':
    authorNum=input('How many authors? ')
    nameList=[]
    for x in range(1,int(authorNum)+1):
        first=input("First name: ")
        firstInitial=first[0].upper()+'.'
        last=input("Last name: ")
        middleKnown=input('Is there a middle name? ')
        if middleKnown.lower()=='yes':
            middle=input("Middle name: ")
            middleInitial=middle[0].upper()+'.'
            fullName= last+', '+firstInitial+middleInitial
            nameList.append(fullName)
        if middleKnown.lower()=='no':
            fullName=last+', '+firstInitial
            nameList.append(fullName)
    if len(nameList)==1:``
        fullCitation.append(nameList[0])
    if len(nameList)==2:
        fullCitation.append(nameList[0]+'and'+nameList[1])
        #just puts an "and" in between the two authors
    if len(nameList)>=3:
        nameListPunc=[]
        for x in nameList[0:len(nameList)-2]:
            nameListPunc.append(x+', ')
        nameListPunc.append(str(nameList[len(nameList)-2])+', and '+str(nameList[len(nameList)-1]))  
        fullCitation.append("".join(nameListPunc))
        #This is for when you need to list items like "a, b, c, and d"
if authorKnown.lower()=='no':
    pass
#asks if author(s) are known and formats name(s)  
pubYearKnown=input('Is the year of publication available? ')
if pubYearKnown.lower()=='no':
    fullCitation.append('(n.d.). ')
if pubYearKnown.lower()=='yes':
    pubYear=input('Publication year: ')
    fullCitation.append('('+pubyear+'). ')
#asks if publication year is known and formats it  
#this is not complete. I still need to code for title, journal name(italics), volume number(italics), and page numbers  

Solution

  • If your program is simply going to print to the command line (the console in Eclipse) you are out of luck if you want it to automatically include formatting. Print() and Sys.stdout.write() don't have the ability to automatically provide formatting.

    However, that doesn't mean it is impossible, it just means you have to work for it. The easiest method is to write the results out to an file in HTML format. You can then open that file in a web browser or MS Word and it will have the correct formatting. The extra work you need to do is to provide all of the wrapper tags around each section that needs to be italicized, underlined, or bolded.