search
LoginSignup
0
Help us understand the problem. What are the problem?

posted at

python3 gzipファイルを読み込みforで回してListに格納する

  • 読み込むファイル
    gzip -dc sample.txt.gz
    111
    222
    333
sample.py
import gzip

listaddress = []
with gzip.open("sample.txt.gz", "rt") as f:
    for line in f:
      listaddress.append(line.replace("\n", ""))
print(listaddress)
['111', '222', '333'] #結果

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0
Help us understand the problem. What are the problem?