- 字符轉義
- 讀寫文件cvs
- 字符串拼接,替換
import csv
csv_file_name = 'cardbin.csv'
# insert into `card_bin_code` (name_of, code_of, card_no_prefix, bank_code) values ('中國銀行曼谷分行', '01040764', '621395', '0104');
str = 'insert into `card_bin_code` (name_of, code_of, card_no_prefix, bank_code) values (\''
content = []
csv_file = csv.reader(open(csv_file_name, 'r'))
for stu in csv_file:
stu[1] = stu[1].replace('\n', '-')
line = str + stu[0] + '\', \'' + stu[1] + '\', \'' + stu[2] + '\', \'' + stu[3] + '\');'
# print(line)
content.append(line)
print('==== look the content size: ', len(content))
filename = 'temp_insert.sql'
with open(filename, 'a', encoding='UTF-8') as file_obj:
for line in content:
file_obj.write(line + '\n')
print('write file over.')
pip on python3
sudo apt-get install python3-pip
pip3 --version
pip3 install flask