1
0

More than 3 years have passed since last update.

Python手遊び(CSVファイルから列名を取得)

Posted at

この記事、何?

表題の通り。10分で書いたような記事。
CSVファイルの1行目をとってsplit(',')して返す。それだけ。

伏線・・・かも?

コード



def get_lines_from_textfile(filepath):
    with open(filepath, 'r', encoding='utf-8') as f:
        lines = f.readlines()
    return lines


def get_columns_list(csvpath):
    line_1st = get_lines_from_textfile(csvpath)[0]
    return line_1st.split(',')


def main():
    csvpath = 'solubility.test.csv'
    columns = get_columns_list(csvpath)
    for column in columns:
        print(column)


if __name__ == '__main__':
    main()

感想

特になし。

1
0
0

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
1
0