1

我已经很好地浏览了网站和网络,但找不到如何做到这一点,因为它相当具体,我已经尝试了一切!

我有一个执行搜索的函数,我正在尝试打印位于列表中特定位置的纯文本和字符串。

这是我的代码:

def search_authors( the_author, authors ):

    position = 0

    foundAuthor = False

    for i in authors:
        if the_author in i:
                print((the_author)  + ". (" + str(years[position]) + "). " + str(titles[position]) + ". " + str(journals[position]) + ". "  )
                foundAuthor == True

        #
        #       for some reason this is prnting a dot on the next line, not just after the last entry
        #

        elif position == len(authors) and foundAuthor == False:
                print("not here")
        position += 1

这是打印时的输出:

Anonymous. (1993). Technical correspondance - Random Number Generators. Communications       of the ACM
. 
Anonymous. (1992). Research Directions in Virtual Environments (NSF Invitational Workshop). Computer Graphics
. 
Anonymous. (1998). "Exploring sequential data: Commentary on Bowers, Jentsch, Salas, and Braun (1998)". Human Factors
. 

我不知道如何停止每个搜索结果的最后一个句号进入下一行,任何帮助将不胜感激。

4

1 回答 1

1

期刊列表的每个元素中可能都有一个换行符。尝试替换:

str(journals[position]).rstrip()

为了

str(journals[position])
于 2013-04-27T21:27:55.513 回答