2016-03-04 108 views
-1
def every_second_line(report): 
    """ (Open File for reading) -> list of str 

    Return a list containing every second line (with leading and trailing 
    whitespace removed) in report, starting with the first line. 
    """ 
+4

你试过解决吗? – vaultah

+2

欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在您发布代码并准确描述问题之前,我们无法有效帮助您。 StackOverflow不是一个编码或教程服务。 – Prune

+0

尝试写一些你希望能够发挥作用的东西,然后(如果没有),试着问为什么 – holdenweb

回答

0

如果我没有记错,你会做这样的:

def every_second_line(report_location): 
    """ This code will return every second line with trailing whitespace stripped.""" 
    report = open(report_location, rb+) 
    second_lines = [a.strip() for a in report.readlines()[1::2]] 

    return second_lines 

我不跟我了Python的时刻,但这应该工作。祝你好运!