我正在编写一个程序,该程序应该以特定的APA修改形式获取条目并返回APA引文。我意识到我只需要用斜体打印文本的某些部分。现在,我的程序只是输入询问你是否有某些信息,如果你这样做,它要求它,格式化它,并把它放在一个列表(fullCitation)中,我最终会打印(“”。join(fullCitation) ))那将打印整个citaion。我需要斜体的第一部分是发布者名称,我可能需要将其作为斜体文本存储在fullCitation列表中。我可以找出一种方法来使用索引范围自己打印出来并只做斜体,但我真正需要知道的是如何在Python中打印/存储斜体文本。我使用的是语言版本3.0。我在Windows 10上使用eclipse Juno。这是我的代码:
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
答案 0 :(得分:1)
使用 python 模块! 它可以使用pip安装 https://pypi.org/project/quo
用法::
from quo import echo
echo(f"Hello world", italic=True)
答案 1 :(得分:0)
如果您的程序只是打印到命令行(Eclipse中的控制台),那么如果您希望它自动包含格式化,则运气不好。 Print()和Sys.stdout.write()无法自动提供格式。
然而,这并不意味着它是不可能的,它只是意味着你必须为之努力。最简单的方法是将结果写入HTML格式的文件中。然后,您可以在Web浏览器或MS Word中打开该文件,它将具有正确的格式。您需要做的额外工作是在每个需要斜体,下划线或粗体的部分周围提供所有包装标签。