Get the App
SLTechnology News&Howtos  ›  Servers  › 

Python reads file scripts line by line and removes blank lines

Shulou Source: shulou.com Published: 2022-06-03 03:35:27 10月03日 Update

There are many ways to read line by line, and here is a very simple one:

#! / usr/bin/python#-*-coding: utf-8-*-for line in open ("awip.conf"): print line

This line-by-line reading has a drawback, there are blank lines, and there will be no blank lines in the following code

#! / usr/bin/python#-*-coding: utf-8-*-def update_all_aw (): for line in open ("upmips.cfg"): a=line.strip () print (a) update_all_aw ()

For others, you can refer to the tutorial:

Three methods of reading file contents line by line by python

Python-- file reading

Tags: Methods files utf-8 code content drawbacks tutorials faceted references blank lines scripts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Redmi OPPO Reno NVidia