使用言語:python、MySQL
コード
import MySQLdb
データベースとの接続
conn = MySQLdb.connect(
user='root',
passwd='',
host='localhost',
db='gr',
charset='utf8')
cursor=conn.cursor()
ファイルを読み込んで書き込む
with open('D:\J2A206\test\Database2\test.txt',encoding='utf8') as fh:
for line in fh:
line=line.rstrip()
items=line.split(',')
sql="insert into goods(goodsID,goodsname,goodsprice,goodscategory) values('%s','%s','%s',%s)"%(items[0],items[1],items[2],items[3])
cursor.execute(sql)
conn.commit()
conn.close()
前提・実現したいこと
現在こちらのプログラムでファイルを読み込んでデータベースに登録する作業を行っています。
このようなエラーが出てしまい、先に進むことができなくなってしまいました。
私の思いつく限りで調べたのですが、ヒットする解決方法では解決できず困っています。
どなたか解決方法分かる方いらっしゃいましたらご連絡宜しくお願い致します。
発生している問題・エラーメッセージ
Traceback (most recent call last):
File "D:\J2A206\test\Database2\menu.py", line 18, in <module>
with open('D:\J2A206\test\Database2\test.txt',encoding='utf8') as fh:
OSError: [Errno 22] Invalid argument: 'D:\J2A206\test\Database2\test.txt'

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/21 06:31