0
0

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 1 year has passed since last update.

Windowsとpython3.11で"delimiter" must be a 1-character stringというエラー

Posted at

次のようなプログラムをwindowsで実行

import csv

raw_data_path = 'hoge.txt'

with open(raw_data_path) as raw_data_file:
    reader = csv.reader(raw_data_file, delimiter='¥t')
    for row in reader:
        print(row[0], row[5],row[6])

その結果タイトルのエラーが発生

    reader = csv.reader(raw_data_file, delimiter='¥t')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: "delimiter" must be a 1-character string

原因はdelimiterの引数が¥tになっていること。delimiter='\t'にすることで解決。

単なるコピペには注意

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?