2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで、テキストファイルの各行をlistまたはiteratorにする方法

Last updated at Posted at 2017-11-02

テキストファイル

foo
bar
baz
qux
quux

コード

# path_text: text の path
with open(path_text) as f:
    lines = f.read().splitlines()

結果

print(lines)

['foo', 'bar', 'baz', ...]

もっと良い書き方ありましたら教えてください。

2
6
2

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
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?