Pythonic way to ignore for loop control variable

前端 未结 9 1421
时光取名叫无心
时光取名叫无心 2020-12-03 11:22

A Python program I\'m writing is to read a set number of lines from the top of a file, and the program needs to preserve this header for future use. Currently, I\'m doing s

9条回答
  •  臣服心动
    2020-12-03 11:58

    I'm not sure what the Pylint rules are, but you could use the '_' throwaway variable name.

    header = ''
    header_len = 4
    for _ in range(1, header_len):
        header += file_handle.readline()
    

提交回复
热议问题