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 can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
0
Help us understand the problem. What are the problem?